Using Handbrake to Convert Audio

Handbrake is the best conversion utility around. It’s just good at what it does. Yes, it has many advanced features, but if you want to convert video really just pick a preset and you’re on your way.

It’s also superb at converting audio. It can take DTS or AC-3 and turn it into AC-3, MP3, AAC, or OGG. And it can do that while letting you choose a downmix, meaning you can take a nice sounding AC-3 or DTS and output 3 tracks if you wish: AC-3 at 5.1, AAC at 5.1, and a stereo (2-channel) AAC with, say, a Dolby Pro Logic II mix down. You’ll have near-perfect compatibility, depending on your needs.

The problem with handbrake is that they refuse to add video passthrough, despite it being a number 1 requested feature. All the developers do is yell at you when you ask about it. They have AC-3 and DTS passthrough, but no kind of video copying. I’ve used Mencoder and FFMPEG for audio conversion and passthroughs, but I never get an output file I’m happy with. Either the generated MP4/M4V is incompatible with something or the audio quality sucks.

Solution with an MKV (you can adapt this for another input file with, say, MP4Box with an mp4 or similar and can also try Mencoder or FFMPEG to extract)

1. Extract the audio with, say,
mkvextract tracks yourVideoFile.mkv 1:video.h264 2:audio.ac3

2. Mux the extracted audio into a video file (MP4 or MKV preferably) along with a dummy video file:
MP4Box -brand mp42 -add empty.h264 -add audio.ac3 tempOutput.mp4 

3. Convert with Handbrake:
HandBrakeCLI -i tempOutput.mp4 -E aac -6 dpl2 -o tempOutput2.mp4
(This converts an AC-3 to a Pro Logic II stereo AAC within an MP4) 

4. Output is a video file with the audio you want and a dummy video file. You can use the attached ’empty’ video files (separate AAC and h.264 streams and a muxed .mov container).

Hopefully this helps someone out there. I purposely made the steps vague, you should apply the general method to your situation.


18 Responses to Using Handbrake to Convert Audio

  1. This is very very very unnecessary. Just use Avidemux. It has audio/video passthrough and lets you reencode anything you want.

    2.6 for windows
    2.6 nightly

  2. This little bit of improvisation finally gave me a great solution after hours of fuitless searching. Thank you!

  3. So i have successfully used this guide to convert to dolby digital.. however what would be the mp4box command to mux the 5.1 ac3 and 2ch dolby into the final mp4 container with the origianal source video, similar to how handbrake does when ripping from dvd?

    I used a straight add, but now both audio streams are playing at the same time, i want them to be selctable from the apple TV.

    • From the mp4box documentation:

      -add inputFile#trackID=ID or -add inputFile#ID: adds the specified track. For IsoMedia files, ID is the track ID. For other media files, ID is the value indicated by MP4Box -info inputFile.

      There you go 🙂

  4. Another option is to set the video average quality rate to 1. The result is a great audio track with an horrible gray video. 🙂

    I’m using HandbrakeCLI to create this m4v “without” video, with converted audio tracks and then recombine the audio on Subler, ignoring the ugly gray video. The best part it to have a multitrack audio file converted at once. Works like a charm.

  5. I tried your instructions, which worked beautifully in converting from 5.1 to stereo so I could stream to xbox360, however the video quality is terrible. It feels like I am watching in 8-bit color and the framerate is just slow enough to be noticeable. My 410MB mkv file was converted into a 47MB mp4. Is there a way to fix this problem? I’m running it on ubuntu 12.04 server edition with the current version of the programs from their respective PPAs.

    • Is there a reason you’re converting the video along with the audio? I think you just need to add the original video into the mp4 and you should be good to go.

      • I figured out my mistake. After using handbrake on the audio with the empty video file, I went full-on retard and combined tempoutput2.mp4 and video.h264 using the same handbrake command. After screwing with it for an hour or 2 trying to figure out why it was failing, I gave up for a few days. When I pulled up the bash history, I kicked myself for being an idiot.

        Many thanks for the walkthrough!

  6. Just another random wanting to thank you for a quick workaround to this stupid problem.

  7. Hi there,

    Thanks for this little trick.
    I use your empty video files successfully in order to use handbrake for audio conversion.

    I have one question though: How did you succeed in building an empty video empty.h264 that can be muxed into mkv such that Handbrake recognizes the resulting file as a video file?

    I tried the following:

    convert -size 100×100 xc:black black.png
    x264 –input-res 100×100 -o empty.mkv black.png
    mkvextract tracks empty.mkv 0:empty.h264

    However, the resulting files can not be used.
    Mediainfo (to my untrained eyes) looks fine, but here is what happens if I try to mux the empty.h264 into a new mkv container:

    mkvmerge -o dfdf.mkv empty.h264
    mkvmerge v6.5.0 (‘Isn’t she lovely’) built on Nov 17 2013 21:28:26
    Error: The file ’empty.h264′ has unknown type. Please have a look at the supported file types (‘mkvmerge –list-types’) and contact the author Moritz Bunkus if your file type is supported but not recognized properly.

    I did succeed to build an mkv with audio using the empty.mkv produced by the x264 line:

    mkvmerge -o df_audio_with_empty_video.mkv empty.mkv df.dts

    mediainfo sees both the video and the audio track.

    However, when running Handbrake on this thing:

    HandBrakeCLI -i df_audio_with_empty_video.mkv -a 1 -A “ha” -E copy -o df_audio_with_empty_video.mp4

    does not work:

    [01:26:45] hb_init: starting libhb thread
    HandBrake 0.9.9 (2013051800) – Darwin x86_64 –
    4 CPUs detected
    Opening df_audio_with_empty_video.mkv…
    [01:26:45] hb_scan: path=df_audio_with_empty_video.mkv, title_index=1
    libbluray/bdnav/index_parse.c:162: indx_parse(): error opening df_audio_with_empty_video.mkv/BDMV/index.bdmv
    libbluray/bdnav/index_parse.c:162: indx_parse(): error opening df_audio_with_empty_video.mkv/BDMV/BACKUP/index.bdmv
    libbluray/bluray.c:1725: nav_get_title_list(df_audio_with_empty_video.mkv) failed (0x103002600)
    [01:26:45] bd: not a bd – trying as a stream/file instead
    libdvdnav: Using dvdnav version 4.1.3
    libdvdread: Using libdvdcss version 1.2.13 for DVD access
    libdvdnav:DVDOpenFileUDF:UDFFindFile /VIDEO_TS/VIDEO_TS.IFO failed
    libdvdnav:DVDOpenFileUDF:UDFFindFile /VIDEO_TS/VIDEO_TS.BUP failed
    libdvdread: Can’t open file VIDEO_TS.IFO.
    libdvdnav: vm: failed to read VIDEO_TS.IFO
    [01:26:45] dvd: not a dvd – trying as a stream/file instead
    [h264 @ 0x102016400] no frame!
    Input #0, matroska,webm, from ‘df_audio_with_empty_video.mkv’:
    Duration: 01:59:36.84, start: 0.000000, bitrate: N/A
    Stream #0.0(eng): Video: h264, 100×100, PAR 1:1 DAR 1:1, 25 fps, 25 tbr, 1k tbn (default)
    Stream #0.1: Audio: dca (DTS), 48000 Hz, 5.1, fltp, 1536 kb/s (default)
    [01:26:45] ffmpeg_title_scan: Unsupported color space
    [01:26:45] scan: decoding previews for title 1
    [01:26:45] scan: audio 0x1: dca, rate=48000Hz, bitrate=1536000 Unknown (DTS) (5.1 ch)
    [01:26:45] scan: could not get a decoded picture
    [01:26:45] scan: could not get a decoded picture
    [01:26:45] scan: could not get a decoded picture
    [01:26:45] scan: could not get a decoded picture
    [01:26:45] scan: could not get a decoded picture
    [01:26:45] scan: could not get a decoded picture
    [01:26:45] scan: could not get a decoded picture
    [01:26:45] scan: could not get a decoded picture
    [01:26:45] scan: could not get a decoded picture
    [01:26:45] scan: could not get a decoded picture
    [01:26:45] libhb: scan thread found 0 valid title(s)
    No title found.

    HandBrake has exited.

    So, it appears that somehow you were smarter in producing your empty video. What is your trick?

  8. You can actually use handbrake to make this ‘dummy’ video file and simply rename the extension from .mp4 to .m4a and it works fine.

  9. Thank you for posting this information and the dummy files. The method worked great to fool Handbrake.

  10. That’s the technique I thought of myself when dealing with MKV-DTS-files, but I somehow can’t manage to add the Handbrake-generated AC3 5.2 und 2.0 files to the unchanged Video from the original file before remuxing it to mp4.

    Not with subler, at least.

    What kind of program did you use, if I may ask?

  11. This is perfect!

    I’m using mkvmerge instead, though, as I already have mkvtoolnix installed. Just as easy;
    mkvmerge -o muxed.mkv audio1.dts audio2.ac3 empty.h264

    One thing though, the CLI version of mkvmerge doesn’t allow you to add FLAC for some reason. The GUI does, so you can just use that afterwards 🙂

    Thanks again!

  12. I used handbrake to convert DTS to AC3 for my movies. Because handbrake does not have video pass through every movie took more than 3 hours. After having read Unnessary I switched to Avidemux. Now every conversion takes about 15 minutes like it used to take with popcorn audio converter on my former windows system. Thank you Unnessary!

  13. Benjamin Ruppel

    This was a top google search for this topic, so I would like to add a comment.

    The open source program “StaxRip” seems to provide the capability we are looking for with a reasonable ease-of-use. It has a github page and is in active development now in early 2016.

    After loading the file, I was able to set the output type to “just mux” and it seems to automatically extract the audio and let you add it to your container (-> edit the container, add the track, edit the track properties) and pass the video through.

    Only hiccup was that it didn’t take .m4v as an input, but it was fine after I renamed the source “.mp4”.

Leave a Reply

Your email address will not be published. Required fields are marked *