FFmpeg 2.8.22
Since* 1.1
#

Select frames to pass in output.

This filter accepts the following options:

expr, e

Set expression, which is evaluated for each input frame.

If the expression is evaluated to zero, the frame is discarded.

If the evaluation result is negative or NaN, the frame is sent to the first output; otherwise it is sent to the output with index ceil(val)-1, assuming that the input index starts from 0.

For example a value of 1.2 corresponds to the output with index ceil(1.2)-1 = 2-1 = 1, that is the second output.

outputs, n

Set the number of outputs. The output to which to send the selected frame is based on the result of the evaluation. Default value is 1.

The expression can contain the following constants:

n

The (sequential) number of the filtered frame, starting from 0.

selected_n

The (sequential) number of the selected frame, starting from 0.

prev_selected_n

The sequential number of the last selected frame. It’s NAN if undefined.

TB

The timebase of the input timestamps.

pts

The PTS (Presentation TimeStamp) of the filtered video frame, expressed in TB units. It’s NAN if undefined.

t

The PTS of the filtered video frame, expressed in seconds. It’s NAN if undefined.

prev_pts

The PTS of the previously filtered video frame. It’s NAN if undefined.

prev_selected_pts

The PTS of the last previously filtered video frame. It’s NAN if undefined.

prev_selected_t

The PTS of the last previously selected video frame. It’s NAN if undefined.

start_pts

The PTS of the first video frame in the video. It’s NAN if undefined.

start_t

The time of the first video frame in the video. It’s NAN if undefined.

pict_type (video only)

The type of the filtered frame. It can assume one of the following values:

  • I
  • P
  • B
  • S
  • SI
  • SP
  • BI
interlace_type (video only)

The frame interlace type. It can assume one of the following values:

PROGRESSIVE

The frame is progressive (not interlaced).

TOPFIRST

The frame is top-field-first.

BOTTOMFIRST

The frame is bottom-field-first.

consumed_sample_n (audio only)

the number of selected samples before the current frame

samples_n (audio only)

the number of samples in the current frame

sample_rate (audio only)

the input sample rate

key

This is 1 if the filtered frame is a key-frame, 0 otherwise.

pos

the position in the file of the filtered frame, -1 if the information is not available (e.g. for synthetic video)

scene (video only)

value between 0 and 1 to indicate a new scene; a low value reflects a low probability for the current frame to introduce a new scene, while a higher value means the current frame is more likely to be one (see the example below)

The default value of the select expression is "1".

#

Examples

  • Select all frames in input:

    select
    

    The example above is the same as:

    select=1
  • Skip all frames:

    select=0
  • Select only I-frames:

    select='eq(pict_type\,I)'
  • Select one frame every 100:

    select='not(mod(n\,100))'
  • Select only frames contained in the 10-20 time interval:

    select=between(t\,10\,20)
  • Select only I frames contained in the 10-20 time interval:

    select=between(t\,10\,20)*eq(pict_type\,I)
  • Select frames with a minimum distance of 10 seconds:

    select='isnan(prev_selected_t)+gte(t-prev_selected_t\,10)'
  • Use aselect to select only audio frames with samples number > 100:

    aselect='gt(samples_n\,100)'
  • Create a mosaic of the first scenes:

    ffmpeg -i video.avi -vf select='gt(scene\,0.4)',scale=160:120,tile -frames:v 1 preview.png

    Comparing scene against a value between 0.3 and 0.5 is generally a sane choice.

  • Send even and odd frames to separate outputs, and compose them:

    select=n=2:e='mod(n, 2)+1' [odd][even]; [odd] pad=h=2*ih [tmp]; [tmp][even] overlay=y=h