Problems with 5.1 Audio Encodes

It has come to our attention that many of our trailers with 5.1 audio were improperly encoded where it only included the left, right, and center channels, omitting the rear-left, rear-right, and subwoofer channels. I’ve already reported the issue to the creator of mp4tools (the utility which I’ve been using to re-encode the raw files).

Here’s what the 6 channels look like if you open the mp4tools encoded file in Audacity:

bad encode

In the mean time, I’ve been learning and playing with ffmpeg and I’ve come across a set of options that seem to do the trick. I’ve created a bash alias that does the following:

ffmpeg -i "$1" -y -vcodec libx264 -crf 18.0 -preset veryslow -vf "scale=852:trunc(ow/a/2)*2" -acodec libfaac -ab 384k -ac 6 -f mp4 "${1%.*}-480p-HDTN.mp4"
ffmpeg -i "$1" -y -vcodec libx264 -crf 18.0 -preset veryslow -vf "scale=1280:trunc(ow/a/2)*2" -acodec libfaac -ab 384k -ac 6 -f mp4 "${1%.*}-720p-HDTN.mp4"
ffmpeg -i "$1" -y -vcodec libx264 -crf 18.0 -preset veryslow -vf "scale=1920:trunc(ow/a/2)*2" -acodec libfaac -ab 384k -ac 6 -f mp4 "${1%.*}-1080p-HDTN.mp4"

Here’s the explanation of the options:

  • -i "$1" means the 1st argument passed in is the input file
  • -y means always answer ‘yes’ to questions (e.g. overwriting files)
  • -vcodec libx264 means to re-encode the video using the x264 codec
  • -crf 18.0 refers to a quality of the encode (18 is visually lossless according to the FFmpeg and x264 Encoding Guide)
  • -preset veryslow means to use a slowest preset which will provide the best compression
  • -vf "scale=852:trunc(ow/a/2)*2" means to scale the video to have a width of 852px and a variable height that maintains the aspect ratio. By default, -1 is used for variable heights/widths, but because x264 requires height and width to be divisible by 2, trunc(ow/a/2)*2 is required (see bug #309)
  • -acodec libfaac means to re-encode the audio using faac
  • -ab 384k means to use a 384k audio bitrate
  • -ac 6 means there’s 6 audio channels
  • -f mp4 means that the file format should be mp4
  • "${1%.*}-480p-HDTN.mp4" means that the output file name should use the original filename, but drop the extension while appending -480p-HDTN.mp4

Here’s what the audio channels look like in Audacity when encoded properly:

good encode

I’ll try and find some time to fix the existing bad encodes. No guarantees on when they’ll all be fixed.

Update 1: Emmgunn from mp4tools has gotten back to me and apparently the culprit is the version of ffmpeg that comes with mp4tools and its inability to handle dtshdma audio streams.

Update 2: @willydearborn has brought to my attention that my new encodes are using a newer H.264 profile which won’t stream on the PS3. After looking into this, I’ve discovered that by using the the veryslow preset, it was using [email protected] for 480p encodes, [email protected] for 720p encodes, and [email protected] for 1080p encodes.

By using the default preset, it will use [email protected] for 480p encodes, [email protected] for 720p encodes, and [email protected] for 1080p encodes. The file size is a bit bigger, but change in quality is unnoticeable. Therefore I’ll be switching back to using the default preset.

If you ever want to manually set the profile and level, the options to pass in is: -profile:v PROFILE -level:v LEVEL (More details at FFmpeg and x264 Encoding Guide)

Update 3: As a rule of thumb, I usually encode 1080p @ 10Mbps, 720p @ 5Mbps, and 480p @ 2.5Mbps. But after reading up on libx264 and how the CRF value works, I’ve learnt there’s no reason to do a 2-pass encode anymore. 2-pass encodes were useful if you wanted to hit a certain bitrate or filesize, but all I really cared about was quality and I can certainly see why certain trailers would have a higher or lower bitrate.

I’ve gone with the suggested CRF value of 18 (visually lossless), but it tends to give encodes with slightly lower bitrates than I usually expect. I’ve played with CRF values between 15-18 and can’t really tell any difference besides the increased file size.

15 thoughts on “Problems with 5.1 Audio Encodes

  1. Admins,
    I’ve recently found your site (after Apple download disappeared) and love the fact that you are producing 5.1 trailers. They sound so much better! I am just having an issue with the sound being OOS when playing on the PS3. I am using PS3 Media Server to browse to the trailer, then I copy it to the PS3 for viewing any time.

    Is there a better way I should be doing it? Something else I can check?

    Thanks so much for your service and your hard work.
    Andrew

    • Hmmm. I haven’t tried playing the 5.1 audio trailers on the PS3. Are all trailers having A/V sync issues? How much of a delay are you seeing? Are you seeing the A/V sync issues on your computer?

      • I’ve downloaded several 5.1 trailers now and they are all having sync issues on PS3, but no sync problems on PC. Delay seems to be ~ 100-200ms, with the audio ahead of the video. Thanks for looking into this. I have an extensive home theater and love running high quality trailers before I begin the movie. Thank you so much for providing these 5.1 trailers. The dynamic range is so much better! I hope we can get this resolved.

        • Sounds like a problem with the PS3 and AAC 5.1, given that it plays back on the PC w/o issues. I know many devices have problems playing AAC 5.1 and I’ve been contemplating on switching to AC3 for surround sound which is supported by more devices.

          • Works like a charm! Thank you so much!!! Is there any chance you can switch to this method, or generate this type alongside the PC friendly ones? These are all best in a massive home theater anyway!

      • Interesting, but I just downloaded the 5.1 Audio version of Pacific Rim Trailer 1 and the audio is out of sync on that one on the PC as well. Same symptom, with audio ahead of the video.

        • I’ve just rechecked the 1080p version of both Trailer 1 and International Trailer 1F and the don’t really see any audio sync issues. In the past, I’ve seen A/V sync issues if the cpu isn’t able to handle the high quality video. Have you check to see if there’s a sync issue in the lower 480p/720p?

  2. Hello, I’ve just found your site and I’m wondering where do you take your master files from? Apple Trailers and Yahoo! seem to offer 5.1 audio very rarely. And why do you reencode the video files (other blog post)? I’m just asking out of curiosity.

    • In the comments, I generally list the source of our 5.1 audio trailers.

      As for why we re-encode them, there’s a couple reason.

      1. First we wanted to lower the filesize to something reasonable. 30Mbps is overkill for 1080p video.

      2. The audio/video aren’t always encoded in web/device friendly codecs, so re-encoding them generally helps people.

  3. Hey,
    thank you. I have read this a while ago but now I’m wondering where the “comments” are? E.g. the new Hobbit trailer or Oblivion, or Man of Steel or Iron Man 3… What is your source for the 5.1 sound? I cannot find a comment on that. I’m just curious, I don’t want to ‘copy’ your site. ;)

  4. Hi, I’m having the exact same sync problems on my B&O V1 TV. The audio is in perfect sync using vlc, but it’s a couple of seconds ahead on the TV using Twonky as a mediaserver. I have only experienced this issue with the videos on this site. All of the stereo files I’ve tested from here play fine. Any iIdeas?

    Thanks

    • Sorry, we don’t have any experience with B&O V1 TV or Twonky. We encode our 5.1 audio with AC3. Your best bet is to send B&O or Twonky a sample video file that you’re having audio sync problems with and see if they have any ideas.

Leave a Reply