简体   繁体   English

使用 FFMPEG 将帧插入视频

[英]Insert frames into video using FFMPEG

The camera I am recording video with occasionally drops frames, so I need to reinsert frames into the video to keep the timing precise.我正在录制视频的相机偶尔会掉帧,所以我需要将帧重新插入视频中以保持时间精确。

I already have a script to identify exactly when those frames were dropped, so I have an index of every frame that needs to be inserted and where.我已经有一个脚本来准确识别这些帧何时被丢弃,所以我有一个需要插入的每一帧的索引和位置。

For example, in a 100 s video at 100 FPS, I should have 10,000 frames.例如,在 100 FPS 的 100 秒视频中,我应该有 10,000 帧。 However, 4 frames were dropped at frame 399, 1205, 4299, and 7891. So, I want to either insert a black frame at the same resolution at those spots, or hold the previous frame for exactly one frame (eg hold frame 398 for an extra frame, or 0.01 s).但是,在第 399、1205、4299 和 7891 帧丢失了 4 帧。因此,我想在这些位置插入一个具有相同分辨率的黑色帧,或者将前一帧保持一帧(例如,保持帧 398一个额外的帧,或 0.01 秒)。

Is there a way to do this iteratively in FFMPEG?有没有办法在 FFMPEG 中迭代地做到这一点? I am currently writing the video into its constituent frames, adding in my blank images, then re-concatenating the video from the frames, which is a very inefficient process.我目前正在将视频写入其组成帧,添加我的空白图像,然后从帧中重新连接视频,这是一个非常低效的过程。

Let's take a video having frame rate value FR and your missing frames having index 399, 1205, 4299, and 7891. First frame has index 0.让我们以帧速率值为 FR 的视频和索引为 399、1205、4299 和 7891 的丢失帧为例。第一帧的索引为 0。

ffmpeg -i in.avi -vf setpts='PTS+(1/FR/TB)*(gte(N,399)+gte(N,1205)+gte(N,4299)+gte(N,7891))' -vsync cfr -q:v 1 out.avi

The setpts filter can adjust timestamps and what the setpts expression does is offset all frames after the given indices forward. setpts 过滤器可以调整时间戳,并且 setpts 表达式的作用是向前偏移给定索引之后的所有帧。 The amount offset is evaluated based on how many earlier frames are missing.偏移量是根据丢失的早期帧的数量来评估的。 This will create empty timestamp slots.这将创建空的时间戳槽。 The -vsync cfr option will then fill in these slots with a clone of the previous available frame.然后-vsync cfr选项将使用前一个可用帧的克隆填充这些插槽。

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

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