Log in

View Full Version : H.264 + AC3 in MPEG2 TS


MrWizard
3rd May 2006, 23:58
I have a H.264 720p 59.94 FPS 5-minute sample and the AC3 audio to go with it. I want to multiplex into a transport stream, and what I'm trying isn't working 100%. I tried ffmpeg, as bond suggested in a different thread, but with varying results. If I simply mux the video in on its own as follows, it will play in Mplayer but not VideoLan. Here is the command line (identical to what bond posted):
ffmpeg -f h264 -i "720p-5min-60fps-OFR.h264" -vcodec copy -f mpegts output.ts

However, if I try to multiplex in the audio as well, it seems like the audio and video is not synced and the video plays very choppy in MPlayer:
ffmpeg -f h264 -i "720p-5min-60fps-OFR.h264" -f ac3 -i "5min.ac3" -vcodec copy -acodec copy -f mpegts output.ts

I get a lot of Error while decoding frame! messages and a few Too many audio packets in the buffer: (4096 in 750080 bytes) near the end, right before MPlayer crashes. Is this a problem with MPlayer, the way ffmpeg multiplexes, something stupid I'm doing, or all of the above?

I have another issue that may be related (?). The clip above was encoded from a MPEG2 TS I got from an OTA HDTV channel (FOX I think). I encoded with DGDecode+AviSynth+MeGUI+x264.

I also tried to cut the framerate in half (SelectEven) and encode from that, so I'd have a 5-minute 30 FPS H.264 sample as well. However, when I mux to MP4, then extract the raw H.264 stream (mp4box), then multiplex into a TS as I did for the 60 FPS sample above (no audio), I have problems. When MPlayer opens, it doesn't detect the 29.97 frame rate, and assumes 59.94. The message reads: FPS seems to be: 59.940060. I'm not sure why it is doing that. Even when I include "-r 29.97" and in the ffmpeg command line, I have the same problem.

Any suggestions or hints would be very much appreciated!

Edit: P.S. I might add that the purpose of all this is to test the H.264 decoding capabilities of a STB that just arrived.

Guest
4th May 2006, 00:03
I've used Elecard Muxer for this. The downside is that you can't choose your PIDs.

MrWizard
4th May 2006, 00:11
I tried the Elecard XMuxer first, actually. But I didn't get any video in any of the players I tried. Only audio... Is there a way to fix the TSes generated by this muxer?

Edit: Tried this time by muxing the audio to a TS with ffmpeg. Then mux the .h264 and the .ts audio with XMuxer. The output is playable with MPlayer, but has the same problem as the ffmpeg solution. MPlayer goes for a bit, complaining about decoding errors, then the audio packet errors, then a crash.

unixfs
6th May 2006, 20:07
too many remuxing processes!
First, make sure you are using mencoder from cvs, not a "release"
(recently I fixed a bug in the framerate detection of H264 video), then:

mencoder "720p-5min-60fps-OFR.h264" -audiofile "5min.ac3" -rawaudio format=0x2000:bitrate=BITRATE:rate=48000:channels=6 -audio-demuxer rawaudio -o output.ts -of lavf -lavfopts format=mpegts -ovc copy -oac copy

Yet, don't expect anything to be in perfect sync, since the original timings are completely lost!

MrWizard
7th May 2006, 00:00
Okay thanks, I'll try that. I was wondering, is it possible to mux directly from the MP4 container outputted by x264? That way, the timings wouldn't be lost...

robU*4
7th May 2006, 08:21
You could try VLC which is probably the best to do that.

unixfs
7th May 2006, 09:14
If you have the original mp4 your output TS file will be much better.

The best choice is:
$ vlc --sout '#std{mux=ts,access=file,url=output.ts}' file.mp4

or

$ ffmpeg -i file.mp4 -acodec copy -vcodec copy -f mpegts -o output.mpegts

or

$ mencoder -of lavf -lavfopts format=mpegts -o output.ts -vcodec copy -acodec copy file.mp4