简体   繁体   English

批量写入样本时,Mediamuxer产生损坏的视频

[英]Mediamuxer produces corrupted video when samples are written in batch

I'm trying to use Android's MediaMuxer and MediaCodec to produce MP4 videos. 我正在尝试使用Android的MediaMuxer和MediaCodec来制作MP4视频。

If I drain frames from the codec directly to the muxer by calling writeSampleData(), everything works fine and the correct video is produced. 如果我通过调用writeSampleData()将帧从编解码器直接消耗到复用器,则一切正常,并生成正确的视频。

But if I try to first store these frames on an array and decide later to send them to the muxer, I'm unable to produce a working video, even if the presentation timestamps are correct. 但是,如果我尝试先将这些帧存储在数组中,然后再决定将其发送到多路复用器,则即使演示时间戳正确,我也无法制作有效的视频。

For some reason, it seem that the mediamuxer output depends not only on the presentation timestamps, but also on the actual time "writeSampleData" is called, although it's my understanding that having the correct timestamps should be enough. 出于某种原因,尽管我认为只要具有正确的时间戳就足够了,但看来,mediamuxer的输出不仅取决于表示时间戳,而且还取决于调用“ writeSampleData”的实际时间。

Can anyone shed some light on this issue? 谁能阐明这个问题?

Thanks mstorsjo and fadden . 感谢mstorsjofadden I had actually a combination of errors which didn't allow me to understand what was really going on. 实际上,我遇到了很多错误,这些错误使我无法理解实际发生的情况。 Both your questions led me to the correct code and the conviction that using writeSampleData() was not time sensitive. 您的两个问题都使我找到了正确的代码,并确信使用writeSampleData() 并不对时间敏感。

Yes, I was getting the wrong buffers at the first time. 是的,我第一次遇到错误的缓冲区。 The problem was not initially noticeable because the muxer was writing the frames before the buffers got rewritten. 这个问题最初并不明显,因为复用器在重写缓冲区之前正在写帧。 When I introduced the delays and decided to duplicate the buffers contents, I hit another issue (basically a race condition) and concluded it was not the case. 当我引入延迟并决定复制缓冲区内容时,我遇到了另一个问题(基本上是竞争条件),并得出结论并非如此。

What this code does (for the SmartPolicing project) is capture video and audio to create a MP4 file. 该代码的作用(对于SmartPolicing项目)是捕获视频和音频以创建MP4文件。 I could use MediaRecorder (this was the initial solution), but we also wanted to intercep the frames and stream the video via web, so we dropped the MediaRecorder and created a custom solution. 我可以使用MediaRecorder(这是最初的解决方案),但我们也想截取帧并通过网络流式传输视频,因此我们放弃了MediaRecorder并创建了一个自定义解决方案。

Now it is running smoothly. 现在它运行平稳。 Thanks a lot, guys. 谢谢你们

您确定确实存储了要写入帧的完整数据,而不仅仅是缓冲区索引吗?

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

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