合并MP4文件的MDAT原子(Merge MDAT atoms of MP4 files)

编程入门 行业动态 更新时间:2024-10-10 03:28:20
合并MP4文件的MDAT原子(Merge MDAT atoms of MP4 files)

我有一系列MP4文件(H.264视频,AAC音频,16KHz)。 我需要以编程方式将它们合并在一起(Objective-C,iOS),但最终文件太大而无法容纳在内存中,所以我无法使用AVFramework为我做这个。

我已经编写了代码,它将进行合并并基于仅连接相应MDATS的内容来处理所有MP4原子(STBL,STSZ,STCO等)。 我遇到的问题是,当播放结果文件时,音频逐渐与视频不同步。 似乎正在发生的事情是每个文件中的音频和视频长度之间存在差异,我连接的文件越多越差。

我已经使用MP4Box从命令行生成一个文件,它与我的输出“相似但不同”。 一个值得注意的不同之处在于MDAT的长度已经改变,并且块偏移也发生了变化(尽管样本大小保持一致)。

我最近读到AAC编码在流的开头和结尾引入了填充,所以想知道这是否是我需要处理的事情。

问:给定两个包含H264编码数据和AAC音频的MDAT原子,我的基本方法是声音还是我需要以某种方式内省MDAT数据。

I have a series of MP4 files (H.264 video, AAC audio, 16KHz). I need to merge them together programmatically (Objective-C, iOS) but the final file will be too large to hold in memory so I can't use the AVFramework to do this for me.

I have written code which will do the merge and takes care of all of the MP4 atoms (STBL, STSZ, STCO etc.) based on just concatenating the contents of the respective MDATS. The problem I have is that while the resultant file plays, the audio gradually gets out of sync with the video. What seems to be happening is that there is a disparity between the audio and video length in each file which gets worse the more files I concatenate.

I've used MP4Box to generate a file from command line and it is 'similar but different' to my output. A notable different is that the length of the MDAT has changed and the chunk offsets have also changed (though sample sizes remain consistent).

I've recently read that AAC encoding introduces padding at the beginning and end of a stream so wonder if this is something I need to handle.

Q: Given two MDAT atoms containing H264 encoded data and AAC audio, is my basic method sound or do I need to introspect the MDAT data in some way.

最满意答案

感谢指针Niels

因此,似乎该方法是完全合理的,但是由于采样频率之间的差异,每个单独的MP4文件在音频长度和视频长度之间具有边际差异。 MP4包括EDTS.ELST组合,可以纠正该文件的此问题。 合并文件时我没有考虑EDTS。 合并EDTS解决了这个问题。

Thanks for pointer Niels

So it seems that the approach is perfectly reasonable however each individual MP4 file has marginal differences between the audio length and video length due to differences between the sampling frequency. The MP4s include an EDTS.ELST combination which correct this issue for that file. I was failing to consider the EDTS when I merged files. Merging EDTS has fixed the issue.

更多推荐

本文发布于:2023-08-07 16:38:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1465294.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:原子   文件   MDAT   atoms   Merge

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!