ffmpeg: Select frames at % position of video

前端 未结 1 1690
Happy的楠姐
Happy的楠姐 2021-01-11 12:20

I\'m trying to create a 2x2 tile thumbnail of a video, that contains frames from 20%, 40%, 60%, and 80% through a video. I see that I need to use a video filter, with select

1条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-11 12:58

    • Method 1: Frame intervals

      This may take some time depending on the input or return N/A for certain types of inputs (see the duration based method in this case).

      Get the total number of video frames:

      ffprobe  -select_streams v -show_entries stream=nb_frames -of default=nk=1:nw=1 -v quiet
      

      The command will output an integer value, for example:

      18034
      

      For the example above the frame interval is nb_frames / 5 = 18034 / 5 = 3607

      Finally the ffmpeg command is:

      ffmpeg -i  -filter:v "select=(gte(n\,3607))*not(mod(n\,3607)),tile=2x2" -frames:v 1 -vsync vfr -y tile.png
      
    • Method 2: Duration intervals

      Same idea as above but use a duration in seconds. This can also take a while and the reported duration may be invalid (eg: if the file is truncated).

      ffprobe  -select_streams v -show_entries stream=duration -of default=nk=1:nw=1 -v quiet
      

      It returns a real value like:

      601.133333
      

      Your interval is 601 / 5 ~= 120 seconds:

      ffmpeg -i  -filter:v "select=(gte(t\,120))*(isnan(prev_selected_t)+gte(t-prev_selected_t\,120)),tile=2x2" -frames:v 1 -y tile.png
      
    • Method 3: Seek & extract

      Seek to a specific time with -ss -i, extract a single frame and use imagemagick's montage to create the tile.

      Example output for a 10 minute countdown timer:

    0 讨论(0)
提交回复
热议问题