How to Start FFplay at a Specific Frame

While FFplay does not include a native command-line option to jump directly to a frame number, you can achieve frame-accurate playback by utilizing FFmpeg's video filtering engine or by calculating time-based seeking offsets. This guide explains how to start playback at an exact frame using the select video filter, as well as the alternative method of converting frame counts to timestamps for faster seeking.

Method 1: Exact Frame Selection Using Video Filters

The most accurate method to start playback at a precise frame is using the select video filter. This instructs FFplay to evaluate every frame index and drop all frames occurring before your target number.

Run the following command in your terminal:

ffplay -vf "select='gte(n\,TARGET_FRAME)',setpts=PTS-STARTPTS" input.mp4

Replace TARGET_FRAME with your desired frame number (indexing starts at 0).

  • select='gte(n\,TARGET_FRAME)': The variable n represents the current frame number. The gte (greater than or equal to) function ensures FFplay only renders frames from that index forward.
  • setpts=PTS-STARTPTS: Resets the Presentation Timestamps of the remaining frames to start at zero. Without this, FFplay may pause or freeze until the player reaches the real-time timestamp of the selected frame.

If your media file contains audio, the video filter alone will not drop the corresponding audio stream. To sync or mute the audio, you can either disable audio output entirely using -an:

ffplay -vf "select='gte(n\,TARGET_FRAME)',setpts=PTS-STARTPTS" -an input.mp4

Or apply a corresponding audio filter:

ffplay -vf "select='gte(n\,TARGET_FRAME)',setpts=PTS-STARTPTS" -af "aselect='gte(n\,TARGET_FRAME)',asetpts=PTS-STARTPTS" input.mp4

Method 2: Calculated Timestamp Seeking (-ss)

For very large files where decoding every frame from the beginning is too slow, you can calculate the timestamp of the target frame and use the -ss flag.

First, determine the frame rate (FPS) of the video using ffprobe:

ffprobe -v error -select_streams v:0 -show_entries stream=r_frame_rate -of default=noprint_wrappers=1:nokey=1 input.mp4

Next, calculate the time offset using the formula:

\[\text{Time in Seconds} = \frac{\text{Target Frame Number}}{\text{Frame Rate}}\]

For example, if your target frame is 300 and the frame rate is 30 FPS, the timestamp is 10 seconds:

ffplay -ss 10 input.mp4

You can specify the -ss argument in seconds (e.g., 10.5) or in standard time format (HOURS:MM:SS.MICROSECONDS). Note that while this method starts playback immediately, it may snap to the nearest preceding keyframe (I-frame) rather than the exact target frame depending on the file's container and codec. Combine -ss with Method 1 if you require both fast navigation and exact frame precision.