简体   繁体   English

使用ffmpeg提取特定帧的列表

[英]Extract list of specific frames using ffmpeg

I'm trying to use ffmpeg on a video to extract a list of specific frames, denoted by their frame numbers. 我正在尝试在视频上使用ffmpeg来提取特定帧的列表,用帧号表示。 So lets say I want to extract just one frame from 'test_video.mp4', frame number 150 to be exact. 所以我想说我想从'test_video.mp4'中提取一帧,确切地说帧号为150。 I can use the following command 我可以使用以下命令

ffmpeg -i test_video.mp4 -vf "select=gte(n\\, 150)" -vframes 1 ~/test_image.jpg

But what if I want to exact a list of frames, such as [100, 110, 127, 270, 300] ? 但是,如果我想确定一个帧列表,如[100, 110, 127, 270, 300]怎么办? I have been looking at this page ( https://ffmpeg.org/ffmpeg-filters.html#select_002c-aselect ) and can see that there are ways to extract multiple frames based on parity of frame number, timestamps, etc, but I can't find the syntax for doing what I need to do. 我一直在看这个页面( https://ffmpeg.org/ffmpeg-filters.html#select_002c-aselect ),可以看到有很多方法可以根据帧号,时间戳等的奇偶校验提取多个帧,但是我找不到我需要做的事情的语法。

Ideally I would extract the list of given frames under the naming convention out_image%03d.jpg where the %03d is replaced by the given frame number, although a timestamp would also work. 理想我想提取的命名规则下给出帧列表out_image%03d.jpg其中%03d由给定的帧编号替代,尽管时间戳也将工作。

Is there a way to do this? 有没有办法做到这一点?

Use 使用

ffmpeg -i in.mp4 -vf select='eq(n\,100)+eq(n\,184)+eq(n\,213)' -vsync 0 frames%d.jpg

FFmpeg is primarily a processor of timed video ie media with a cycle rate such as framerate or sample rate. FFmpeg主要是定时视频的处理器,即具有诸如帧速率或采样率的循环速率的媒体。 It assumes that the output should be at the same rate as the source. 它假定输出应与源相同。 If inadequate frames are supplied, it duplicates unless told not to. 如果提供的框架不合适,除非被告知不重复,否则它会重复。 -vsync 0 is added which, in this case, tells it to suppress duplication. -vsync 0被添加,在这种情况下,它告诉它抑制重复。

A very naive answer... 一个非常天真的答案......

#! /bin/sh -e
# framegrab v0.1

frames="$1"
filename="$2"
printf '%s' "$frames" |
sed 's:\[\|\]::g; s:[, ]\+:\n:g' |
xargs printf '%03d\n' |
xargs -IFRAME ffmpeg -i "$filename" -vf "select=eq(n\,FRAME)" -vframes 1 out_imageFRAME.jpg

Call it with your argument list: 用你的参数列表调用它:

 framegrab '[100, 110, 127, 270, 300]' test_video.mp4

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

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