Create multiple thumbnails from a video at equal times / intervals

岁酱吖の 提交于 2020-11-29 23:39:21

问题


I need to create multiple thumbnails (ex. 12) from a video at equal times using ffmpeg. So for example if the video is 60 seconds - I need to extract a screenshot every 5 seconds.

Im using the following command to get the frame in the 5ths second.

ffmpeg -ss 5 -i video.webm -frames:v 1 -s 120x90 thumbnail.jpeg

Is there a way to get multiple thumbnails with one command?


回答1:


Get duration (optional)

Get duration using ffprobe. This is an optional step but is helpful if you will be scripting or automating the next commands.

ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 input.mp4

Example result:

60.000000

Output one frame every 5 seconds

Using the select filter:

ffmpeg -i input.mp4 -vf "select='not(mod(t,5))',setpts=N/FRAME_RATE/TB" output_%04d.jpg

or

ffmpeg -i input.mp4 -vf "select='not(mod(t,5))'" -vsync vfr output_%04d.jpg
  • Files will be named output_0001.jpg, output_0002.jpg, output_0003.jpg, etc. See image muxer documentation for more info and options.

  • To adjust JPEG quality see How can I extract a good quality JPEG image from a video with ffmpeg?

Output specific number of equally spaced frames

This will output 12 frames from a 60 second duration input:

ffmpeg -i input.mp4 -vf "select='not(mod(t,60/12))'" -vsync vfr output_%04d.jpg

You must manually enter the duration of the input (shown as 60 in the example above). See an automatic method immediately below.

Using ffprobe to automatically provide duration value

Bash example:

input=input.mp4; ffmpeg -i "$input" -vf "select='not(mod(t,$(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 $input)/12))'" -vsync vfr output_%04d.jpg

With scale filter

Example using the scale filter:

ffmpeg -i input.mp4 -vf "select='not(mod(t,60/12))',scale=120:-1" -vsync vfr output_%04d.jpg


来源:https://stackoverflow.com/questions/61893366/create-multiple-thumbnails-from-a-video-at-equal-times-intervals

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!