合并MP4文件的MDAT原子 [英] Merge MDAT atoms of MP4 files

查看:120
本文介绍了合并MP4文件的MDAT原子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一系列MP4文件(H.264视频,AAC音频,16KHz).我需要以编程方式将它们合并在一起(Objective-C,iOS),但最终文件太大而无法保存在内存中,因此我无法使用AVFramework来为我完成此工作.

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.

我已经编写了代码,可以进行合并,并且仅根据各个MDATS的内容来处理所有MP4原子(STBL,STSZ,STCO等).我的问题是,在播放结果文件时,音频逐渐与视频不同步.似乎正在发生的是,每个文件中音频和视频长度之间存在差异,而我连接的文件越多,情况就越糟.

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.

我使用MP4Box从命令行生成文件,它与我的输出相似但有所不同".一个显着的不同是MDAT的长度已更改,并且块偏移也已更改(尽管样本大小保持一致).

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).

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

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.

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

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已解决了该问题.

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.

这篇关于合并MP4文件的MDAT原子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆