简体   繁体   English

如何在不重写整个视频文件的情况下仅替换流中的一个数据帧? (FFmpeg)

[英]How can I replace only one data frame from stream without rewriting whole video file ? (FFmpeg)

I created two streams: for input video file and for output. 我创建了两个流:用于输入视频文件和用于输出。 But even if I want to change only one (first) video frame I have to use av_read_frame and write_frame for each frame in loop just to place them from one file to another. 但是,即使我只想更改一个(第一个)视频帧,我也必须为循环中的每个帧使用av_read_framewrite_frame ,以便将它们从一个文件放置到另一个文件。

How can I change only one frame and then flush somehow other frames to the output without loop av_read_frame , write_frame ? 如何仅更改一帧,然后以其他方式将其他帧刷新到输出,而无需循环av_read_framewrite_frame

What you ask seems a logical question, if you think of the frames in a video as a sort of linked list or array - you simply want to replace one element in the array or list without having to change everything else, I think? 如果您将视频中的帧视为一种链接的列表或数组,那么您提出的问题似乎是一个逻辑问题-我想您只是想替换阵列或列表中的一个元素而不必更改其他所有内容,我想呢?

The problem is that video streams are typically not as simply arranged as this. 问题在于视频流通常不像这样简单地安排。

For instance, the encoding often uses previous and even following frames as a reference for the current frame. 例如,编码经常使用先前和甚至随后的帧作为当前帧的参考。 As an example, every 10th frame might be encoded fully and the frames in between be simply encoded as deltas to these reference frames. 例如,每第10帧可能被完全编码,而其间的帧则被简单地编码为这些参考帧的增量。

Also, the video containers, eg mp4, often use offsets to point to the various elements within them. 同样,视频容器(例如mp4)经常使用偏移量来指向其中的各个元素。 Hence, if you dive inside and change the size of a particular frame by replacing it with another one, then the offsets will not be correct anymore. 因此,如果您潜入内部并通过用另一框架替换特定框架来更改其大小,则偏移将不再正确。

If you are doing this for a single frame in a large video file, and you know roughly where the frame is, then you may find it more effective to split the video file, into a long section before the bit you want to change, a short section containing the frame you want to change, and a long section afterwards. 如果您对大型视频文件中的单个帧执行此操作,并且大致了解了帧的位置,那么您可能会发现,将视频文件分割成一个长段,然后再更改您想要的位,这样会更有效。包含要更改的框架的短部分,然后是长部分。 You can apply your change just on the short section and then concatenate the videos at the end. 您可以仅在短部分中应用更改,然后在末尾连接视频。

If you do something like this, you have to use a proper utility to split and concatenate the video, for the same reasons as above - ie to make sure the split videos have the right header info, offsets etc. 如果您这样做,则必须使用适当的实用工具拆分和连接视频,原因与上述相同-即确保拆分的视频具有正确的标题信息,偏移量等。

ffmpeg supports these type of functions - for example you can see the concatenation documentation here: ffmpeg支持这些类型的功能-例如,您可以在此处查看串联文档:

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

相关问题 如何处理来自 WASAPI 流的声音数据块而不将它们写入文件? - How can I process chunks of sound data from a WASAPI stream without writing them to a file? 如何使用带有C的ffmpeg截取编码的视频数据? - How can I intercept encoded video data using ffmpeg with C? 删除文件的开头而不重写整个文件 - Remove beginning of file without rewriting the whole file 如何使用 FFmpeg 和 C/C++ 将数据流添加到 MXF(使用 mpeg2video)文件中 - How add Data Stream into MXF(using mpeg2video) file with FFmpeg and C/C++ 如何设置从 RTSP stream 和 FFMPEG 保存的视频的开始时间 - How to set start time of video saved from RTSP stream with FFMPEG 如何在ffmpeg C ++ API中将关键帧(Iframe)插入到h.264视频流中? - How to insert a key frame(Iframe) to a h.264 video stream in ffmpeg C++ api? 从streambuf派生而不重写相应的流 - Deriving from streambuf without rewriting a corresponding stream 如何将视频从应用程序流传输到网络? - How can I stream video from my application to the web? 如何使用FFMPEG打开文件\\实时流使用openCV编辑每个帧并保存为使用FFMPEGfile \\ live stream编码? - How to open file\live stream with FFMPEG edit each frame with openCV and save that as encoded with FFMPEGfile\live stream? 使用FFMpeg iOS解码相机流视频帧时出错 - Error while decoding camera stream video frame using FFMpeg iOS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM