简体   繁体   English

ffmpeg到底是怎么分帧的

[英]How does ffmpeg divide into frames EXACTLY

I'm using this piece of code in python to split a video into frames.我正在使用 python 中的这段代码将视频分割成帧。

    def ffmpeg(self, video_file, fps, start_number, **trim_kwargs):
        ffmpeg.input(video_file) \
            .filter('fps', fps=fps) \
            .trim(**trim_kwargs) \
            .output(os.path.join(self._output_dir, f"%0{NAME_PADDING}d.JPG"),
                    **{'qscale:v': 1, 'vsync': 'drop', 'start_number': start_number}) \
            .run()

I sometimes use also trimming options more or less like this:我有时也会像这样或多或少地使用修剪选项:

ffmpeg(video_file, fps, 0, start=XXX,end=YYY)

Additionally, I have a list with timestamps (starting from point zero) with some additional metadata at certain points.此外,我有一个时间戳列表(从零点开始),在某些点有一些额外的元数据。 I'm trying to figure out what are the mechanics of ffmpeg of using fps for dividing into frames (for example fps = 1), because when I try to jump through my timestamped log manually with the same "fps", I often get less entries than ffmpeg by 1. It's like ffmpeg always took first and last frame or something.我试图弄清楚 ffmpeg 使用 fps 划分帧(例如 fps = 1)的机制是什么,因为当我尝试使用相同的“fps”手动跳过带时间戳的日志时,我经常得到更少条目比 ffmpeg 多 1。就像 ffmpeg 总是占据第一帧和最后一帧之类的。 Can someone explain to me how it's done exactly, so I could match metadata with generate frames in the best manner?有人可以向我解释它是如何完成的,这样我就可以以最好的方式将元数据与生成的帧相匹配吗?

An MPEG file is always recorded at a specific frame rate(*), usually 24 or 30 or 60. Because an MPEG frame depends on the frames before and after it, the decoder always has to decode ALL the frames in the file. MPEG 文件总是以特定的帧率 (*) 记录,通常是 24 或 30 或 60。因为 MPEG 帧取决于它之前和之后的帧,解码器总是必须解码文件中的所有帧。 If you ask for fps=1 , it's just going to throw out the frames between the recorded frame rate and the frame rate you ask for.如果您要求fps=1 ,它只会丢弃记录的帧速率和您要求的帧速率之间的帧。

(*) -- Technically, a single MPEG file can include multiple frame rates, but that's less commonly used. (*) -- 从技术上讲,单个 MPEG 文件可以包含多个帧速率,但这种情况不太常用。

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

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