Current state of ac3+aac mp4 creation

Discussion in 'Apple TV and Home Theater' started by ajv, Feb 22, 2008.

  1. ajv macrumors newbie

    Feb 22, 2008
    So after searching and browsing several posts, am I correct that we're still waiting for/working on a solution for adding an ac3 track to an mp4 file? VisualHub does not currently do this, and although HandBrake does, it only works with VIDEO_TS directories, not other formats.

    I have mp4box 0.4.4, and when I run:

    mp4box -add -add -add -fps 23.976 foo.mp4

    I get:

    AVC-H264 import - frame size 1280 x 544 at 23.976 FPS
    Import results: 787 samples - Slices: 24 I 723 P 40 B - 1 SEI - 22 IDR
    Stream uses B-slice references - max frame delay 2
    IsoMedia import - track ID 1 - Audio (SR 48000 - 2 channels)
    Unknown input file type
    Unknown input file type
    Saving to foo.mp4: 0.500 secs Interleaving

    The resulting file does not include the ac3 track
  2. smilinmonki666 macrumors regular

    Jan 20, 2008
    To include, you need either Visual Hub 3.31 (I think?) or Hand Brake 0.9.2 to include the AC3 passthrough. With HB, you can add AC3 passthrough & AAC 2ch encoding in the same file.
  3. Avatar74 macrumors 65816


    Feb 5, 2007

    Unless I misread you, you seem to be asking why you can't encode AC-3 from formats other than DVD.

    I'm not sure I understand your goal here. What source are you transcoding from, and what file is your AC-3 source coming from?
  4. Jestered macrumors 6502

    Oct 13, 2005
    Austin, Texas
    I have the same question. It does not really matter where the file "came from", I just want to know if it is possible and how?

    I have some .mkv files that have the 5.1 audio but it is aac format. HandBrake won't do anything with a .mkv file so that is out. VisualHub will encode the video perfectly, but it won't do the audio.

    Any ideas?
  5. Avatar74 macrumors 65816


    Feb 5, 2007
    Well, yes it does matter. AC-3 Pass-through only works if the source file is itself AC-3. Handbrake 0.9.2 is the best tool for producing AppleTV compatible files with the AC-3 track encapsulated in the MPEG-4 container.

    Unless you have a Dolby Digital encoder, you're most likely out of luck. Most receivers don't know what to do with an AAC file, and most transcoding tools do not have a Dolby Digital encoder that will actually take multichannel audio and produce an AC-3 bitstream from it.
  6. spice weasel macrumors 65816

    Jul 25, 2003
    I suppose you could just paste an AC-3 track into an mp4 in QT and save as a .mov. You'd likely have sync problems though. But, as has been asked, where would you get the AC-3 track from? A DVD. In that case, why not just use Handbrake?
  7. Avatar74 macrumors 65816


    Feb 5, 2007
  8. sJv macrumors regular

    Jul 11, 2007
    Sierra Foothills, CA
    If your source .mkv file does not have the AC3 bit stream in it, you will likely not find an easy way to transcode this into an AppleTV format with AC3. Most tools merely pass on the existing AC3 stream and do not do encoding. Many .mkv files do have the AC3 stream. In this case Visual Hub is your best bet.

    Just be sure your illegally downloaded .mkv movies have the AC3 stream in them and you should be set! :)

  9. secondcup macrumors member


    Feb 12, 2008
    The latest version of Visual Hub now supports AC3. There's a new setting "optimize for AppleTV 5.1"

    Check out the link:
  10. Avatar74 macrumors 65816


    Feb 5, 2007
    However, since AC-3 streams are often short a few frames (even at the time of compiling the master DVD) there arises the question of whether stripping AC-3 from an MKV is even worthwhile.

    For example, if the MKV encoder drops any AC-3 frames at the beginning or end to compensate for any format idiosyncrasies with MKV, the same AC-3 file might not actually sync up to an H.264 video stream encapsulated in an MPEG-4 container.

    The best, simplest solution is to transcode from the original DVD using handbrake. However, as you so astutely point out, the only reason one would insist on going to more elaborate lengths than that is because they don't have the DVD source... i.e. illegal download. :D
  11. ajv thread starter macrumors newbie

    Feb 22, 2008
    I have a library of 720p .mkv files with ac3 audio. I want to convert them to an apple tv compatible format that will do ac3 passthrough for receivers that support it and stereo for those that don't. I plan on getting an appletv for each tv in the house, but only the living room setup will have surround sound. I would also like to be able to manage the resulting files with MetaX.

    I've spent some time learning about x264 encoding and how to get the best quality in the least amount of encoding time. The latest build of the x264 command line tool can do a two pass encode with higher quality settings in about the same time it takes visualhub to do a "go nuts" ffmpeg single pass.

    Here's the script I'm using. Unfortunately the ac3 track gets left out of the result. The script requires mplayer, x264, mkvtoolnix, qt_tools, and mp4box. You can generate using the qt_export --dodialog and --savesettings options.

    rm -f stream.yuv stream.y4m
    mkfifo stream.yuv
    ln -s stream.yuv stream.y4m
    mplayer -vo yuv4mpeg -ao null -nosound "$1" > /dev/null &
    x264 --progress --bframes 3 --b-pyramid --no-cabac --bitrate 4500 \
    --vbv-maxrate 11500 --threads auto --level 31 --ref 1 --subme 1 --pass 1 \
    --stats "$" -o /dev/null stream.y4m
    mplayer -vo yuv4mpeg -ao null -nosound "$1" > /dev/null &
    x264 --progress --bframes 3 --b-pyramid --no-cabac --bitrate 4500 \
    --vbv-maxrate 11500 --threads auto --level 31 --ref 3 --subme 6 --pass 2 \
    --stats "$" -o "$" stream.y4m
    mkvextract tracks "$1" "2:$"
    qt_export \
    "$" "$"
    mp4box -add "$" -add "$" -add "$" \
    -fps 23.976 "$1.mp4" && \
    rm "$" "$" "$" "$"
  12. Blazer5913 macrumors 6502

    Jan 20, 2004
    I think this is a great queestion that everybody with 720p HD .mkv encodes has on their mind right now. When is VisualHub going to give us what we need? Handbrake did it exactly right, and the darn thing is free. Yet, I fork over 25 bucks for VisualHub, and granted they do give an update, but they change the format to .mov, something they know MetaX can't handle (at least stability wise now). VisualHub needs to get their act together, I have hudnreds of gb worth of .mkv just waiting to be thrown into VisualHub! I want my HD with 5.1 on AppleTV!
  13. stuff4me macrumors newbie

    Feb 11, 2008
    I am slowly re-encoding all my DVDs again because I want that AC-3 stream now. So I have to spend time again to re-rip and encode my DVDs. Am I upset no. I should have waited.

    As for the few that are complaining in this post the HandBrake only supports a VIDEO_TS folder and VisualHub does not have support yet for the mp4 container and AC-3 stream need to chill out a bit. I can see your frustration, but come on, give the developers of these fine pieces software a break.

    I think VisualHub is worth the $23.32 I paid for it and I think there is only one developer working on all aspects of it (could be wrong).

    HandBrake, one day the developers might change from being free to charging for updates.

    AppleTV 2 has only been out for 2 weeks now, so be patient as the developers catch up with the new technology of the AppleTV 2.

    It seems like now-a-days, everyone needs "it" right away and if it is not done right, they draw quick blame to the developer/provider, when the developer/provider is trying their best to keep up with the new standards. I think both VisualHub and HandBrake teams are doing wonderful work and in most cases they are not doing this development as their primary job.

    Just my $.02
  14. ajv thread starter macrumors newbie

    Feb 22, 2008
    VisualHub uses standard open source command line utilities under the hood, so until mp4box can do this, VisualHub will have to wait also. Both mp4box and ffmpeg (what VisualHub uses) use the GPAC library for mp4 encapsulation. I assumed that Handbrake did as well since it is open source. I guess I'll have to dig around the source and figure out how it's doing it.

    What's all this talk of DVD ripping being somehow less illegal than downloading? The only legal ways to get movies on your appletv under US law are to shoot them yourself, or buy/rent them from itunes. In fact even *discussing* how to rip a CSS encrypted DVD that you own to appletv format is a criminal offense. People have actually been arrested for it.

    Why do you think iTunes rips CDs but not DVDs? Why does HandBrake not include de-css? We're all outlaws here (those of us living in the US anyway), so don't get too smug.

    edit: It looks like Handbrake is using something called mpeg4ip which had a patch submitted about a week ago to allow it to include ac3 tracks in mp4 files. I'll see if there's an easy way to use it. If not then the option is to write my own command line program to use it, or see about getting the functionality added into GPAC.
  15. spice weasel macrumors 65816

    Jul 25, 2003
    I don't want to thread-jack here, but there is a qualitative and moral difference between ripping/encoding from a source you own and downloading one that you do not. I understand that ripping your own DVDs is illegal under DCMA law, but as far as I'm concerned it is not nearly as illegal as downloading something you don't even own. In that case, you are not only an accomplice in breaking DCMA, but also guilty of trafficking in stolen goods.

    I'm not trying to get sanctimonious here by any means. But the two are not (im)morally equivalent in my book.
  16. ajv thread starter macrumors newbie

    Feb 22, 2008
    Since it's my thread, is it okay for me to hijack it? :) I think it's a really interesting topic.

    Okay, so what you're saying is that it's okay to ignore the law as long as what you're doing is moral. I happen to agree with that. In fact I would go one further and say it's our civic *duty* in a free society to disobey laws against perfectly moral acts (Rosa Parks). Now the question is only about what's moral regardless of the law. What if I only download movies that were released before 1994, the original 14 year copyright term? Copyright is a contract between content producers and the public. The public gives up their right to do what they like with their stuff in exchange for increasing the incentive for content producers to create more stuff to begin with. Unfortunately the content producers have been able to lobby the legislature to continually extend this copyright term... retroactively. Now explain that one to me. When the work was created the producer knew he would only have exclusive control of the work for a fixed time. How does retroactively extending the term for stuff he's already completed encourage him to create more? Wouldn't it actually do the opposite, encouraging him to rely on the income from the stuff he's already created? I think the public got the raw end of that deal, and that's not even considering all sorts of other things like the fact that the public is forced to pay for the enforcement of copyright.

    BTW, mpeg4ip includes a command line utility called mp4creator. I'll see if it's been patched to deal with ac3.
  17. roland.g macrumors 603


    Apr 11, 2005
    One mile up and soaring
    Yes it is very interesting that music is legal to rip. Put it your CD and compress it to your computer. You should be able to do the same thing with a DVD. People will argue that music is cheaper. Really $10-20 for a CD. DVDs are that cheap. But you can rent - blockbuster/netflix - DVDs and not really music. So I guess the argument goes that with DVDs people would rent them and add them to their personal library. And that just screws those of us who own the content and want to back it up (i.e. prevent kids from destroying discs) as well as use an Apple TV to have a dedicated media server and put all those discs in a box somewhere. Is the ability to rip a movie slowing down my movie purchase rate. NO. Personally I would like to see the HD movies come to iTunes for purchase. Between renting $2.99-$4.99 I would prefer to buy at $10-20 for download. Saves me ripping. But I would also prefer to buy HD content or at least higher definition than the 'almost DVD' quality of current iTunes purchase movies at 640x.
  18. ajv thread starter macrumors newbie

    Feb 22, 2008
    I found this thread over on the handbrake dev forum:

    It looks like edgyg is the only guy outside of apple to figure out how to get mp4 ac3+aac working so far. I'll shoot him an email and see if he has any interest in getting his patch working with the mp4creator command line tool that's part of the mpeg4ip library he's using.
  19. theBB macrumors 68020


    Jan 3, 2006
    I think you are mixing up patents with copyrights. AFAIK, copyrights covered decades after the death of the original author for a long time. They just keep on increasing the number of decades after that death. The patents were extended beyond the original limit to be compatible with European systems, but the two does not have much to do with each other.

    A lot of companies get affected by patents in a negative way, so they lobby to balance the rights of the public versus the incentive to innovate. In copyrights, very few members of the public actually lobbies for the public and there are no rich companies that make money through works whose original copyright have expired, so copyright holding media companies usually get what they want from Congress.
  20. ajv thread starter macrumors newbie

    Feb 22, 2008
    From the US Copyright office website:
    May 31, 1790 - First copyright law enacted under the new U.S. Constitution. Term of 14 years. Books, maps, and charts protected. Copyright registration made in the U.S. District Court where the author or proprietor resided.

    Rufus Pollock of Cambridge wrote and excellent paper recently where he attempts to calculate the optimal copyright term for producing the greatest social benefit. He comes to the conclusion that 14 years is the optimal length:

    Patents are 7 years, with the exception of drug patents which are for 14.
  21. spice weasel macrumors 65816

    Jul 25, 2003
    I think it's silly to cite 1790 copyright law and try to apply it to today. Laws change all the time as legislatures attempt to keep up with advances in technology, societal change, etc. I'm hardly an expert, but my understanding is that motion picture copyright originally lasted 28 years, but has now been extended for up to 95 years. I do agree that this is entirely too long. But that doesn't give me the right to infringe on someone's copyright.

    I never said that breaking DCMA was morally right, only that there is a fundamental difference between breaking DCMA to copy something you already own for your own use and freely downloading a copyrighted motion picture of which you don't own a copy.

    I must also HIGHLY disagree with your attempt to equate the civil disobedience of people such as Rosa Parks with stealing copyrighted material. Civil rights movement leaders did not get hosed, beaten, and attacked by police dogs so that you could feel better about downloading illegally copied motion pictures. Your indignity over DCMA and copyright does not even begin to approach the travesty that was Jim Crow.

    Stealing movies does not make you Patrick Henry, Rosa Parks, or even Henry David Thoreau, regardless of how unfair you think current copyright law may be.
  22. ajv thread starter macrumors newbie

    Feb 22, 2008
    I never said overly long copyright terms were comparable to jim crow laws. The only thing they have in common is that I happen to think both are unjust. Clearly the level of unjustness isn't comparable either. I do compare myself to figures like Thoreau, but I wouldn't cite violating copyright as a reason why. The DMCA is a much more oppressive law that directly contradicts the first amendment, but again this still doesn't rise to the level of jim crow laws, or taxation in Thoreau's case.

    I do think that it's our civic duty to defy unjust laws, large or small. I will encourage others to be aware of and think about the justness of restrictions placed on them and decide for themselves what's just and what isn't.

    In the case of copyright I maintain that exclusive control of a work for a period of several years is reasonable as a standard contract between a content producer and the public, but when this contract is extended continually retroactively through corruption of the legislature, we as citizens should fight back.

    Making a copy or derivative work of something that someone else created is absolutely not theft. It's not always right, but comparing it to theft is a pretty twisted corruption of that term. If I steal your bicycle, you are deprived of a bicycle. A more apt analogy would be if I made a copy of your bicycle.

    Copyright can be a great benefit to everyone. Just as traffic laws place minor restrictions on me, but give me the freedom to travel around, so copyright can also place a restriction on me while creating an incentive for producers to make a lot of things for me to enjoy. The term of copyright should be chosen to provide the greatest overall freedom to everyone involved. So far the best estimation of what that term should be that I've come across is about 14 years, which also just happens to be what the founding fathers decided on. Their ideas and judgements have served us well in the past. I think we'd all be a lot better off if we didn't discard their judgement so readily in all sorts of areas. This is a pretty small one by comparison to some others.
  23. secondcup macrumors member


    Feb 12, 2008
    #23 about thread jacking!
  24. Alphy macrumors member

    Apr 12, 2007
    I've been trying to find a solution for this problem all damn night.

    I guess the gist of it, as mentioned above, is the follow;

    How to take my .mkv's and put them into a format that is compatible with Apple TV (maintaining 5.1 sound), in as little as time and effort as possible?

    Basically from what I understand now, we're at the cusp of a solution. I've been going over Doom9 threads:

    and I'm still not quite there yet. Anyways, I forgot why I originally posted all of this but I'm going to try and post on Doom9 and see if I can get an answer that doesn't involve me having to go commandline. /faint
  25. Alphy macrumors member

    Apr 12, 2007

    Managed to get AutoMKV (google it) to give me a nice .aac track that I can throw into yamb and then remux with my h.264 to give me an .mp4. REMEMBER, you need to manually set the fps in yamb to 23.967.

    But, I'm still not quite there yet. I need to the "Level" to 3.1 to have Apple TV play it back. It's getting late though...More tomorrow.

    Thread at Doom9 asking about this:

Share This Page