ffmpeg:在视频的%位置选择帧 [英] ffmpeg: Select frames at % position of video
问题描述
我正在尝试创建视频的2x2拼贴缩略图,该缩略图包含视频中20%,40%,60%和80%的帧.我看到我需要使用带有select的视频过滤器,但无法确定哪些选项可以执行此操作.我想做这样的事情:
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, but can't work out what options will do this. I want to do something like this:
ffmpeg -i video.avi -frames 1 -vf "select=not(mod(pos\,0.2)),tile=2x2" tile.png
位置是视频中从0.0到1.0的位置.我该怎么做,或者我有什么选择?
Where position would be the position in the video from 0.0 to 1.0. How do I do this, or what are my options?
推荐答案
-
方法1:帧间隔
这可能需要一些时间,具体取决于输入,或者对于某些类型的输入,返回
N/A
(在这种情况下,请参见基于持续时间的方法).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).获取
video
帧的总数:ffprobe <input> -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
对于上面的示例,帧间隔为
nb_frames / 5 = 18034 / 5 = 3607
For the example above the frame interval is
nb_frames / 5 = 18034 / 5 = 3607
最后,
ffmpeg
命令是:ffmpeg -i <input> -filter:v "select=(gte(n\,3607))*not(mod(n\,3607)),tile=2x2" -frames:v 1 -vsync vfr -y tile.png
-
方法2:持续时间间隔
与上述相同,但是使用持续时间(以秒为单位).这也可能需要一段时间,并且报告的持续时间可能无效(例如:文件被截断).
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 <input> -select_streams v -show_entries stream=duration -of default=nk=1:nw=1 -v quiet
它返回一个真实值,例如:
It returns a real value like:
601.133333
您的间隔为
601 / 5 ~= 120
秒:ffmpeg -i <input> -filter:v "select=(gte(t\,120))*(isnan(prev_selected_t)+gte(t-prev_selected_t\,120)),tile=2x2" -frames:v 1 -y tile.png
-
方法3:搜索&提取
使用
-ss -i
搜索特定时间,提取单个帧,然后使用imagemagick的montage
创建图块.Seek to a specific time with
-ss -i
, extract a single frame and use imagemagick'smontage
to create the tile.10分钟倒数计时器的示例输出:
Example output for a 10 minute countdown timer:
这篇关于ffmpeg:在视频的%位置选择帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!