简体   繁体   English

ffmpeg:在视频的%位置选择帧

[英]ffmpeg: Select frames at % position of video

I'm trying to create a 2x2 tile thumbnail of a video, that contains frames from 20%, 40%, 60%, and 80% through a video. 我正在尝试创建视频的2x2平铺缩略图,其中包含通过视频的20%,40%,60%和80%的帧。 I see that I need to use a video filter, with select, but can't work out what options will do this. 我看到我需要使用带有select的视频过滤器,但无法确定哪些选项可以执行此操作。 I want to do something like this: 我想做这样的事情:

ffmpeg -i video.avi -frames 1 -vf "select=not(mod(pos\,0.2)),tile=2x2" tile.png

Where position would be the position in the video from 0.0 to 1.0. 位置将是视频中从0.0到1.0的位置。 How do I do this, or what are my options? 我该怎么做,或者我有什么选择?

  • Method 1: Frame intervals 方法1:帧间隔

    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). 这可能需要一些时间,具体取决于某些类型输入的输入或返回N/A (在这种情况下参见基于持续时间的方法)。

    Get the total number of video frames: 获取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 

    For the example above the frame interval is nb_frames / 5 = 18034 / 5 = 3607 对于上面的示例,帧间隔是nb_frames / 5 = 18034 / 5 = 3607

    Finally the ffmpeg command is: 最后, ffmpeg命令是:

     ffmpeg -i <input> -filter:v "select=(gte(n\\,3607))*not(mod(n\\,3607)),tile=2x2" -frames:v 1 -vsync vfr -y tile.png 
  • Method 2: Duration intervals 方法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 

    Your interval is 601 / 5 ~= 120 seconds: 你的间隔是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 
  • Method 3: Seek & extract 方法3:寻求和提取

    Seek to a specific time with -ss -i , extract a single frame and use imagemagick's montage to create the tile. 使用-ss -i寻找特定时间,提取单个帧并使用imagemagick的montage来创建切片。

    Example output for a 10 minute countdown timer: 10分钟倒计时器的示例输出:

    在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM