View Full Version : x264 to *.264 and x264 to *.mp4 to *.264 (mp4box) result in different filesizes.why?
poyupay
1st June 2006, 10:53
Hi there!
I just did a few tests. I encoded a small file to *.264 and to *.mp4 with the x264 codec, build 530 from sharktoth.
The filesizes are *.mp4 : 2.509.609 Bytes, and *.264 : 2.503.108 bytes. But now, if i extract the *mp4 file to raw stream with "mp4box -raw 1 File.mp4" i get a *.264 file which's file size is 2.502.849 bytes!
(mp4box 0.4.1-dev)
This is a difference of 259 bytes compared to the *.264-file i got from the x264 encoder. I thought that *.264 files are raw stream and therefore do not contain any flags like "Date of creation" or something like that. Could anybody make it clear to me why the two files have different sizes?
...btw: i'm pretty new to encoding and so i'm new to doom9 as well... ahh, you guys rock! :-)
akupenguin
1st June 2006, 13:17
x264 writing to h264es duplicates the global headers before each keyframe. mp4 does not allow that, and stores headers only once at the beginning of the file. The h264es extracted from the mp4 still has only one copy of the headers.
poyupay
1st June 2006, 15:53
..i guess x264 is not doing the duplicated headers just for the fun of it, but as mp4-container does not take advantage of those dublicated headers (does not allow it!), there must be some other container which does, am i right? and if so, in which way?
duplicated headers dont really make sense (except for error resilience maybe), because why store the same info multiple times if its enough for playback when they are stored once?
either way, mp4 is also able to store different (and therefore also duplicated) headers throughout a stream (eg when appending different streams with different settings used). its just that noone really uses such streams (and i am also not sure if decoders handle those)
foxyshadis
1st June 2006, 21:07
Can mp4 actually handle different headers switched in a single stream? I thought both mp4 and mkv required max one header per stream, but allow multiple video streams. (Anytime I make an mp4 by trying to concatenate streams with different headers I always end up with multiple video streams, through mp4box.)
mp4 handles it, i am not sure about mp4box (i think it does). in any case the different headers need to have different ids iirc, which you can set in x264
never tried it
edit: and of course also the parsers and decoders need to explicitely support such streams (so i would try to avoid them)
poyupay
1st June 2006, 22:58
duplicated headers dont really make sense (except for error resilience maybe), because why store the same info multiple times if its enough for playback when they are stored once?
...And therefore i think it doesn't really make sense that x264 does duplicate the headers. But, now that i know, it doesn't really bother me.
I just did another test with filesizes (yeah, that really turns me on):
I encoded with x264 to mp4 and got a filesize of 831.586.535 Bytes. If i extract the h264 stream with mp4box and then put the h264 again to mp4 with mp4box i get a filesize of 831.409.539 Bytes. The resulting filesize is, as you can see, a bit smaller as the filesize of the mp4-file originally created by x264. So what kind of Information is so important that x264 decides to store it within the mp4-file? (And why does mp4box not?) I mean, the difference is 176kB!
Thanks for your advice!
foxyshadis
1st June 2006, 23:18
mp4box, having the entire stream available, is able to add seek points and optimize the size, probably folding some information together. Perhaps it tosses some extraneous information out as well, but it'll happen as soon as you mux in audio anyway so I doubt it matters.
Also, outputting headers at each keyframe makes sense if the stream was going to be muxed into .ts, where that's required although the muxer should handle it, or even used directly as a poor man's .ts. (Is that even possible?)
poyupay
1st June 2006, 23:51
mp4box, having the entire stream available, is able to add seek points and optimize the size, probably folding some information together. Perhaps it tosses some extraneous information out as well, but it'll happen as soon as you mux in audio anyway so I doubt it matters.
You're probably right if one uses mp4 as container for both, video and audio. But for matroska i can tell you, it matters... size of mkv will be bigger of almost the difference of the two mp4-filesizes (for some reasons i would like to know, it's not the same difference in filesizes as the two mp4-files have!)
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.