简体   繁体   English

如果文件未正确完成,您如何使用 libav 编写可播放的 .mov 文件

[英]How can you write a .mov file with libav which is playable if the file isn't properly completed

I'm developing a video recording application in c++ with the libav c library which records and encodes h265 from a camera feed into a .mov container.我正在使用 libav c 库在 c++ 中开发一个视频录制应用程序,该库将 h265 从相机输入记录并编码到 .mov 容器中。

I can successfully play back the .mov file on all standard video players, but only if the recording is terminated properly - ie calling av_write_trailer and properly closing the file.我可以在所有标准视频播放器上成功播放 .mov 文件,但av_write_trailer是录制正确终止 - 即调用av_write_trailer并正确关闭文件。

One important requirements of the software, however, is a playable .mov file even in the event that the recording is terminated inappropriately - ie power loss or target disk becomes full.然而,该软件的一个重要要求是一个可播放的 .mov 文件,即使在不恰当地终止录制的情况下 - 即断电或目标磁盘已满。

I'm assuming this is possible as most video recording devices create valid .mov files even when they run out of battery or fill their target media.我假设这是可能的,因为大多数视频录制设备即使在电池耗尽或填充目标媒体时也会创建有效的 .mov 文件。

I have tried specifying the following AVDictionary option which is suppose to move relevant stream information to the start of the file:我尝试指定以下AVDictionary选项,该选项假设将相关流信息移动到文件的开头:

av_dict_set(&options, "movflags", "faststart", 0);

However, this does not make incomplete files playable.但是,这不会使不完整的文件可播放。

I believe this is the options you're looking for:我相信这是您正在寻找的选项:

av_dict_set(&options, "movflags", "+frag_keyframe+empty_moov+faststart", 0);

This is what is used for streaming mp4 , so the stream is both playable and interruptible at any time.这是用于流式传输 mp4 的内容,因此该流可以随时播放和中断。

As a downside, such video file won't be seekable.不利的一面是,此类视频文件将无法查找。 But you can probably post-process such incomplete files and fix headers once the power is restored.但是,您可能可以对此类不完整的文件进行后处理,并在电源恢复后修复标题。

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

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