简体   繁体   English

FFmpeg:如何使用 C++ 代码更改视频文件的帧速率?

[英]FFmpeg: how to use C++ code to change the frame rate of a video file?

I know it would be easier to use FFmpeg commands to change the frame rate of a video file.我知道使用 FFmpeg 命令更改视频文件的帧速率会更容易。 But anyway, if I want to do it in C++ code, and use FFmpeg libraries, how could I do it?但无论如何,如果我想用 C++ 代码来做,并使用 FFmpeg 库,我该怎么做?

I think I should've be able to find out the clue in the source code.我想我应该能够在源代码中找到线索。 Just before proceeding, I hope there would be some good introductions or examples.在继续之前,我希望会有一些好的介绍或示例。

This is fairly easy, all you need is to modify the time_base of the video stream.这相当简单,您只需要修改视频流的 time_base 即可。 For simple container formats such as AVI you only need to do it in the header.对于简单的容器格式(例如 AVI),您只需在标题中执行此操作。 If you insist to do it via ffmpeg API, you'd need to loop through all the frames in the input stream, and copy them to the output stream.如果您坚持通过 ffmpeg API 执行此操作,则需要遍历输入流中的所有帧,并将它们复制到输出流。

The above assumes you only want to change the FPS (ie slow down or speed up the video) without dropping frames.以上假设您只想在不丢帧的情况下更改 FPS(即减慢或加快视频速度)。 However if you want to keep the video playback at the original speed while changing the FPS, you'd need to recode the video, ie decode and encode each frame, while inserting extra frames or removing some frames.但是,如果您想在更改 FPS 的同时保持视频播放的原始速度,则需要重新编码视频,即对每一帧进行解码和编码,同时插入额外的帧或删除一些帧。 You cannot simply remove the frames from the video - for example when converting from 30FPS to 15FPS you cannot simply remove every 2nd frame, since it may be a keyframe and it will break all frames after it until the next keyframe is encountered.您不能简单地从视频中删除帧 - 例如,当从 30FPS 转换为 15FPS 时,您不能简单地删除每第二帧,因为它可能是一个关键帧,它会破坏之后的所有帧,直到遇到下一个关键帧。 Same way, you cannot simply duplicate a frame when upping the FPS, as P frames apply only to the frame before it, so duplicating it would break your video.同样,您不能在提高 FPS 时简单地复制帧,因为 P 帧仅适用于它之前的帧,因此复制它会破坏您的视频。 For this which I'd suggest to look at my Karaoke Lyric Editor source code, notably video decoding and video encoding .为此,我建议查看我的卡拉 OK 歌词编辑器源代码,尤其是视频解码视频编码

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

相关问题 在C ++中以可变帧速率使用FFmpeg库(不是libav fork)以编程方式捕获视频 - Programmatically capturing video with the FFmpeg libaries (not the libav fork) with variable frame rate in c++ 如何使用 FFmpeg、无损并保持相同的总帧数来更改视频帧速率? - How can I change a video frame rate with FFmpeg, lossless and keeping the same total number of frames? Directshow:如何更改视频的大小和帧速率? - Directshow : How to change Size and frame rate of video? ffmpeg / c ++使用ffmpeg编码视频帧的其他信息 - ffmpeg/c++ Encode additional information of video frame with ffmpeg 使用ffmpeg提取每一帧以形成可变帧率视频 - Extract every frame form a variable-frame-rate video with ffmpeg FFMPEG:视频比特率的动态变化 - FFMPEG: Dynamic change of bit_rate for Video 如何更改在C ++中通过FFMPEG库提取的帧的配色方案? - How to change color scheme of frame extracted via FFMPEG library on C++? 更改视频聊天帧率tokbox - change video chat frame rate tokbox 通用Windows平台中视频文件的帧频 - Frame rate of video file in universal windows platform 读取固定帧率的视频文件 - Read video file with fixed frame rate
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM