View Full Version : Muxing a raw h264 stream into an AVI container
Cyber Akuma
6th October 2007, 12:09
I know normally you use h264 video with the MP4 container but I have encoded video in h264/vbr mp3 using the AVI container multiple times before and just about any system or device that support playing the h264 codec and supports .avi files had no problems with them.
Anyway, I have been trying to demux another non-standard container and basically wound up with a RAW h264 video stream and raw AT3 audio stream.
Details about that here for those that are interested:
http://www.psp-hacks.com/forums/viewtopic.php?id=73945&p=1
http://forum.doom9.org/showthread.php?t=130589
Now, the problem is most people seem to recommend using applications to encode this into an uncompressed AVI. Doing this would mean I then need to re-encode this AVI into one using a compression codec. Since this is basically converting a compressed source to an uncompressed source than back to a comrpessed source all this would do is result in quality loss.
The quality of the resulting raw h264 stream is perfect, I would much rather just put this stream into a container directly instead of re-encoding it, if such a thing is possible. The problem is, all programs I have tried fail to read/import the file because it has no header or container, they assume it is either corrupted or junk data.
Is there any way I can put this raw h264 stream into a container without re-encoding it? Preferably AVI so it won't be a hassle to import it into vdub.
Thanks.
nm
6th October 2007, 12:42
You can try AVC2AVI (http://mirror05.x264.nl/Sharktooth/x264/utils/avc2avi_r594.7z), although I wouldn't recommend putting the stream into an AVI container. There are alternatives, like muxing to MP4 and using Avidemux for editing instead of Vdub.
Cyber Akuma
6th October 2007, 14:48
Thanks, AVC2AVI seems to work perfectly.
And I know normally you use MP4 for h264 video but the only editing tool I have is vdub, and I just personally prefer AVI. I am only using vdub to mux the video, I am not doing any actual editing.
However, I do have another problem now. Since the source is raw, I have no way of knowing the actual FPS. AVC2AVI by default recommends 25 and the person that wrote the guide that helmped me extract the audio/video data from the original file recommended 29.97 but that is clearly off too.
I admit I don't know much about determining video framerates, so I tried looking at how many frames the video has, and how long the audio is, and tried to estmate the framerate based on assuming the audio end at the same time. Does this sound like a valid estimate or is it just a stupid way of doing it?
file 1:
video = 3731 frames
audio = 2:07.756 = 127.756 seconds
3731/127.756 = 29.204107830551989730423620025674
file 2:
video = 3205 frames
audio = 1:50.155 = 110.155 seconds
3205/110.155 = 29.095365621170169306885751895057
So I tried a framerate of 29.204 for video 1 and 29.095 for video 2.
Although other than the corruption issue (explained in my other post), while the second video seemed to sync the video and audio up ok (I don't know of any decent method I can use to check other than to just eyeball it), the first one seems off, and I can't seem to determine what framerate to use. Any ideas on a good way to try to determine the framerate?
Also, it played on in Media Player Classic but in mplayer it stuttered a little and each time it stuttered I saw a bunch of these:
[h264 @ 00B2DC90]concealing 0 DC, 0 AC, 0 MV errors
What does that mean? Is there corrupt data in the vidoestream? How can I clean it?
Thanks.
LoRd_MuldeR
6th October 2007, 16:12
And I know normally you use MP4 for h264 video but the only editing tool I have is vdub
Try Avidemux (http://forum.doom9.org/showthread.php?t=126164) asap :p
Cyber Akuma
6th October 2007, 22:18
Avidemux looks like VdubMod on steroids, thanks, i'll try it. Though suprisingly so far, using something as unstandard as h264 video and VBR mp3 audio in an AVI container has enabled more devices for me to play the file instead of .mp4 container video.
Although right now, my main conscern is finding out a good way to get the audio and video to sync other than just guessing the framerate (Well, and fixing the corruption in file 2 but thats in my other topic). Any ideas?
nm
7th October 2007, 00:22
The video framerate is most likely 29.970 and you are just missing some frames compared to audio, maybe only from the beginning. The problem could also be caused by AVI or the tools used. Is the sync constantly off by the same amount or does the difference grow over time? If the sync difference is constant, it can be compensated when muxing the streams.
Personally, I would just mux the raw H.264 and AC3 streams to Matroska and see if the problem persists.
Cyber Akuma
7th October 2007, 01:43
The video framerate is most likely 29.970 and you are just missing some frames compared to audio, maybe only from the beginning. The problem could also be caused by AVI or the tools used. Is the sync constantly off by the same amount or does the difference grow over time? If the sync difference is constant, it can be compensated when muxing the streams.
Hmm, as I said, the only way I have to check is to kinda eyeball/listen to what parts of the audio happen in what parts of the video from actually playing the video from the game in my PSP then loading the soundless AVI and a .wav version of the audio together in Media Player Classic and trying to see/listen if they sync up well.
This compsensation, will it still work if in the final product I want to use a vbr mp3? Vdub seems to have problems with avi files that have a VBR MP3 audio track.
Personally, I would just mux the raw H.264 and AC3 streams to Matroska and see if the problem persists.
So, mux the raw 264 and ac3 stream into an MKV? How would I go about doing that? Most applications don't seem to handle raw streams, especially for audio, and I don't know what application to use for encoding into an MKV container, nor do I know of any good AC3 decoders that would work with MKV or in MPC.
nm
7th October 2007, 15:09
This compsensation, will it still work if in the final product I want to use a vbr mp3? Vdub seems to have problems with avi files that have a VBR MP3 audio track.
I don't know about those tools, but at least it is technically possible by for example adding or removing audio from the start of the sound track. And I know that changing the sync is quite simple with mkvmerge.
So, mux the raw 264 and ac3 stream into an MKV? How would I go about doing that? Most applications don't seem to handle raw streams, especially for audio, and I don't know what application to use for encoding into an MKV container, nor do I know of any good AC3 decoders that would work with MKV or in MPC.
With mkvmerge (http://www.bunkus.org/videotools/mkvtoolnix/doc/mkvmerge-gui.html#whatismkvmerge) (or mkvmerge GUI) -- no need to look further than the default tools. Use VLC for easy playback.
Trahald
7th October 2007, 18:32
to see a raw stream's frame rate, you can use something like h264info or h264_parse(from mpeg4iptools) both free tools
Cyber Akuma
8th October 2007, 00:36
Ok, I tried h264info version alpha 11, but it didnt seem to do anything. I didnt see the framerate listed anywhere, and the output file it created was completely corrupted.
As for h264_parse, is this a Linux-only tool? I could only find a tarball of it released as sourcecode, I coudlent find any binaries.
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.