MP4的Atom解析 - 在配置时间...? [英] MP4 Atom Parsing - where to configure time...?

查看:1088
本文介绍了MP4的Atom解析 - 在配置时间...?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经写了一个MP4解析器可以在MP4就好读原子,它们拼接到一起 - 结果是一个技术上有效的MP4文件的QuickTime可以打开等,但它不能播放任何音频作为我相信时间/采样信息全部关闭。我也许应该提及我只对音频感兴趣。

I've written an MP4 parser that can read atoms in an MP4 just fine, and stitch them back together - the result is a technically valid MP4 file that Quicktime can open and such, but it can't play any audio as I believe the timing/sampling information is all off. I should probably mention I'm only interested in audio.

我在做什么是试图采取MOOV原子/等从现有的MP4,然后只拿MDAT原子的一个子集在文件中创建一个新的,更小的MP4。在此过程中,我改变了<$ c中的持续时间 mvhd 原子,以及持续时间$ C> mdia 头。有此文件中有没有修改 tkhd 原子,所以我相信我不需要改变持续存在 - 我缺少什么

What I'm doing is trying to take the moov atoms/etc from an existing MP4, and then take only a subset of the mdat atom in the file to create a new, smaller MP4. In doing so I've altered the duration in the mvhd atom, as well as the duration in the mdia header. There are no tkhd atoms in this file that have edits, so I believe I don't need to alter the durations there - what am I missing?

在创建新的MP4我正确的切片 MDAT 具有广泛箱,并保持MDAT页眉/在他们的正确的地方大小的块 - 我做一定要与新的内容更新的大小。

In creating the new MP4 I'm properly sectioning the mdat block with a wide box, and keeping the 'mdat' header/size in their right places - I make sure to update the size with the new content.

现在它是完全110%的可能我想的东西左右格式是至关重要的,但如果这是可能,我很想得到的最后一块。任何人有任何输入/想法?

Now it's entirely 110% possible I'm missing something crucial about the format, but if this is possible I'd love to get the final piece. Anybody got any input/ideas?

code可以在下面的链接中找到:

Code can be found at the following link:

https://gist.github.com/ryanmcgrath/958c602cff133bd7fa0b

推荐答案

我要采取刺伤在黑暗中在这里,说你不更新你的 STBL 适当抵消。至少我没有(乍)看到你的Python这样做的任何地方。

I'm going to take a stab in the dark here and say that you're not updating your stbl offsets properly. At least I didn't (at first glance) see your python doing that anywhere.

让我们开始用数据的位置。分组被写入到该文件中的块的方面,所述头告诉解codeR其中每个块中的块的存在。在科技小组委员会表说每块许多物品是如何存在的。在第一块表示,新块的开始。这是一个有点混乱,但是看看我的例子。这是说,你有100个样本每chunkk,到8块。在第8块有98样本。

Lets start with the location of data. Packets are written into the file in terms of chunks, and the header tells the decoder where each "block" of these chunks exists. The stsc table says how many items per chunk exist. The first chunk says where that new chunk starts. It's a little confusing, but look at my example. This is saying that you have 100 samples per chunkk, up to the 8th chunk. At the 8th chunk there are 98 samples.

这是说,你也有可能跟踪这些块的偏移量。这就是 STCO 表的工作。因此,在该文件中块的偏移量1,或组块偏移2等

That said, you also have to track where the offsets of these chunks are. That's the job of the stco table. So, where in the file is chunk offset 1, or chunk offset 2, etc.

如果您修改 MDAT 的任何数据,你必须维护这些表。你不能只砍 MDAT 数据输出,并期望去codeR知道该怎么做。

If you modify any data in mdat you have to maintain these tables. You can't just chop mdat data out, and expect the decoder to know what to do.

好象这还不够,现在你也必须保持样品时间表( STTS )的样本量表( STSZ ),如果这是视频,同步示例表( STSS )。

As if this wasn't enough, now you have to also maintain the sample time table (stts) the sample size table (stsz) and if this was video, the sync sample table (stss).

STTS 说多久样本应在时间刻度单位玩。如果你正在做音频的时间表大概是44100或48000(千赫)。

stts says how long a sample should play for in units of the timescale. If you're doing audio the timescale is probably 44100 or 48000 (kHz).

如果你已经砍掉了一些数据,现在一切都可能是不同步的。如果这里的所有值都具有相同的时间,虽然你会好起来的。

If you've lopped off some data, now everything could potentially be out of sync. If all the values here have the exact same duration though you'd be OK.

STSZ 表示,每个样本单位是字节什么尺寸。对于德codeR能够在一大块入手,然后再通过它的大小每个样品这是非常重要的。

stsz says what size each sample is in bytes. This is important for the decoder to be able to start at a chunk, and then go through each sample by its size.

此外,如果所有的样本量是完全一样的,你会很确定。音频往往是pretty大致相同,但视频的东西变化了很多(使用关键帧和诸如此类的东西)

Again, if all the sample sizes are exactly the same you'd be OK. Audio tends to be pretty much the same, but video stuff varies a lot (with keyframes and whatnot)

和最后但并非最不重要,我们有 STSS 表,说的帧的是关键帧。我只有有经验的AAC,但每一个音频帧被认为是一个关键帧。在这种情况下,你可以有一个描述所有的数据包一个条目。

And last but not least we have the stss table which says which frame's are keyframes. I only have experience with AAC, but every audio frame is considered a keyframe. In that case you can have one entry that describes all the packets.

关于你原来的问题,时间显示并不总是在尊重每个玩家以同样的方式。最准确的方法是总结所有帧的持续时间中的报头,并使用该作为总时间。其他玩家使用元数据在轨道头。我发现它最好还是把所有的值相同,然后玩家都开心。

In relation to your original question, the time display isn't always honored the same way in each player. The most accurate way is to sum up the durations of all the frames in the header and use that as the total time. Other players use the metadata in the track headers. I've found it best to just keep all the values the same and then players are happy.

如果你正在做的一切,我错过了脚本,那么你可以张贴样本MP4和一个独立的应用程序,我可以尽力帮助你。

If you're doing all that and I missed it in the script then can you post a sample mp4 and a standalone app and I can try to help you out.

这篇关于MP4的Atom解析 - 在配置时间...?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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