playback.md

July 14, 2026 · View on GitHub

Playback

TFFVideoPlayer

VCL control with two modes.

Engine mode

Minimal setup – set FileName only:

Player.FileName := 'clip.mp4';
Player.HardwareDevice := ffhdAuto;  // optional; set before Play
Player.Play;

Internally TFFPlaybackEngine creates its own TFFReader / TFFDecoder in worker threads.

Linked mode

Component graph on the form:

Reader.FileName := 'clip.mp4';
Reader.Open;

VideoDecoder.Reader := Reader;
VideoDecoder.StreamIndex := VideoIdx;
VideoDecoder.HardwareDevice := ffhdD3D11VA;

AudioDecoder.Reader := Reader;
AudioDecoder.StreamIndex := AudioIdx;

Player.VideoDecoder := VideoDecoder;
Player.AudioDecoder := AudioDecoder;
Player.Play;

Play / Pause / Stop / SeekTo control TFFLinkedPlayback. Position, Duration, State come from the linked core.

Hardware decode

TFFHardwareDevice (uFFHardwareDecode):

ValueDescription
ffhdNoneSoftware (default)
ffhdAutoD3D11VA on Windows, VAAPI on Linux
ffhdD3D11VA, ffhdDXVA2, ffhdCUDA, ffhdQSV, …Explicit backend
ModeWhere to set
LinkedTFFDecoder.HardwareDevice
EngineTFFVideoPlayer.HardwareDevice or TFFPlaybackEngine.HardwareDevice

Change HardwareDevice only while psStopped. On HW init failure – software fallback (TrySetup).

HW frames are transferred to system memory via av_hwframe_transfer_data before libswscale.

A/V sync

TFFPlaybackClock:

  • with audio – master time from audio PTS (SetAudioTimeMs);
  • before the first audio frame – wall clock (avoids startup deadlock);
  • WaitUntil / IsLate – delay or drop late video frames.

Windows audio: WaveOut (uFFAudioOutputWin), 8-slot ring buffer, Flush on Stop.

Player events

EventPurpose
OnStateChangepsStopped / psPlaying / psPaused
OnFrameHookIntercept TFFFrame before conversion
OnVideoHookIntercept BGRA buffer
OnAudioHookIntercept PCM before output

TFFPlayerControl

Composite VCL control: TFFVideoPlayer + trackbar + play/pause/stop. FileName, VideoDecoder, SubtitleDecoder forward to the inner player.

FMX

TFFFMXVideoPlayer – FMX equivalent based on TFFPlaybackEngine / linked mode. Requires FMX dependencies at build time.