Author Topic: H.264 in MP4 and ac3 sound track  (Read 5700 times)

TCmullet

  • Full Member
  • ***
  • Posts: 140
H.264 in MP4 and ac3 sound track
« on: October 05, 2016, 10:06:27 PM »
I acquire MP4 files with AAC sound track and H.264/AVC video.  But I want to remux it without recoding video and WITH recoding audio to AC3.   I want an MP4 container but with AC3 audio.  But Avidemux lets me pick and set up the AC3 and bitrate but then bombs when I go to save saying, "Unspported" and "Only AAC and mpegaudio supported".  Why is this happening??  I thought the content was independent of what container I use.  I need AC3 audio in these MP4s.

eumagga0x2a

  • Moderator
  • Hero Member
  • *****
  • Posts: 3405
Re: H.264 in MP4 and ac3 sound track
« Reply #1 on: October 06, 2016, 09:26:31 PM »
I thought the content was independent of what container I use.

MP4 specs don't allow AC3 audio. Use MKV then. MKV specs put almost no restrictions on codecs for video and audio.

dosdan

  • Full Member
  • ***
  • Posts: 157
Re: H.264 in MP4 and ac3 sound track
« Reply #2 on: October 07, 2016, 02:39:41 AM »
I thought the content was independent of what container I use.

MP4 specs don't allow AC3 audio.


I don't think that's the case. MP4 allows the inclusion of an AC3 stream, but its usage isn't common. A hardware media player that claims to play "MP4" files may not be able to handle it. But I can't see any reason why TCmullet can not use it in an MP4 for his own use.

https://web.archive.org/web/20160615194616/http://www.mp4ra.org/codecs.html

You can do this with FFMPEG:

ffmpeg -i testfile.avi -c:v copy  -c:a ac3 -ac 2 -ar 48000 -ab 192k "H264 with AC3.MP4"

Tested with the following input files:

TESTFILE.AVI [v:H.264, a:PCM]

TESTFILE.MP4 [v:H.264, a:AAC]

The converted versions of these files played back OK in MPC-BE and appeared to be in sync.

However, there is an additional loss in audio quality from trans-coding from AAC to AC-3. So unless there is some other playback benefit, it's not worthwhile.

If you don't want to create a batchfile to do this with FFMPEG, there are commercial packages that offer this:

http://www.bigasoft.com/articles/how-to-convert-video-to-mp4-ac3-5.1.html

Dan.
« Last Edit: October 07, 2016, 03:19:48 AM by dosdan »

dosdan

  • Full Member
  • ***
  • Posts: 157
Re: H.264 in MP4 and ac3 sound track
« Reply #3 on: October 07, 2016, 04:17:48 AM »
I thought the reason you might want to change from AAC to AC3 was because of surround sound. I don't have a video media file with 5.1ch AAC, but I can switch my camcorder to output in AVCHD format (.MTS) which includes 5.1 384kb/s AC-3, and pretend that it's a 5.1 AAC source.

AVCHD [v:H.264, a:AC3 5.1]  -> MP4 [v.H264, a:AC3 5.1]

ffmpeg -i testfile.mts -c:v copy  -c:a ac3 -ac 6 -ar 48000 -ab 384k  "MP4 with multi-channel AC3.MP4"

In this example I'm faking converting from multi-channel AAC. However since it's really AC3 in the source file I should have just done a straight unpack/repack using:

ffmpeg -i testfile.mts -c:v copy  -c:a copy "MP4 with multi-channel AC3.MP4"

Dan.
« Last Edit: October 07, 2016, 04:24:48 AM by dosdan »

mean

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 10974
Re: H.264 in MP4 and ac3 sound track
« Reply #4 on: October 07, 2016, 05:03:07 AM »
one of mp4 or mp4v2 muxer supports this and not the other


eumagga0x2a

  • Moderator
  • Hero Member
  • *****
  • Posts: 3405
Re: H.264 in MP4 and ac3 sound track
« Reply #5 on: October 07, 2016, 05:29:08 AM »
Oh, I see, the MP4v2 muxer in Avidemux supports AC3 audio. Sorry about wrong info on my part.

TCmullet

  • Full Member
  • ***
  • Posts: 140
Re: H.264 in MP4 and ac3 sound track
« Reply #6 on: November 02, 2016, 12:49:31 AM »
I suppose I should reveal what was driving me to do this.

I use the DGIndexNV/DGDecodeNV package.  When I'm feeding my M2TS transport stream file to it (which perhaps might NOT be a real M2TS, but might be a TS with M2TS extension, according to another thread here), DGIndexNV detects the audio stream and demuxes it.  In my Avisynth script I open the resultant .dgi file (with DGSource), which supplies the video stream to the script.

If the audio is .aac, then I have to convert that to .wav and import it with wavsource(), as I know of no import tool for .aac files.  If the audio was .ac3, then I can directly use nicAc3source() nicely.  For other reasons, I choose .aac for my M2TS files.  However, I deal with a lot of H.264 in .MP4 files.  Lately I've had many Mpeg2 files and I use Replay Converter to reencode to .MP4 (H.264) so I can use DGDecodeNV with them, as well as free up tons of space from bulky Mpeg2.  (The Replay Converter encodes really well with almost no quality loss.)

I chose to set up Replay Converter to ouput AC3 simply so I could avoid having to convert it to .wav to Avisynth import.  I'm also creating other H.264/MP4 files with Replay Video Capture 8.  With great effort (and discussion with customer support), I was able to change it's output to be AC3 vs AAC, again for reason stated above.

I did not anticipate I would need to gop-edit the MP4/ac3 files with AviDemux, but an occasion arose today requiring that.  But got hit by the "does not support AC3 in MP4" bomb.  As I really needed to do this edit, I did "copy/convert" instead of "copy/copy" and made the output AAC (Faac).  So later on, I will have to convert to .wav still.

But in the many cases of my MP4 with AC3 where I DON'T have to edit them, I AM able to import via nicac3source(), saving a conversion step.

From what I understand of MP4 muxer vs MP4v2 muxer, I think I should stay with MP4 muxer.  Even given the caveat that someone kindly posted, that some players will not like MP4 with AC3, I still wish Avidemux could be allowed to output audio in any format I pick.  Perhaps a compromise could be a warning/prompt that "your output file might not play on some platforms", if I output AC3 to MP4.

HEY, if someone knows of a tool to import AAC files into Avisynth, that would partially solve things!  (But I did research it last year and found nothing.)