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.

Attacks on DreamHost and Enabling CloudFlare

For the past 2 days, our site has been going up and down like a roller coaster due to attacks and connection issues at our webhost (DreamHost):

As a temporary fix (maybe permanent?) against the attacks, they’re limiting every account to only 3 simultaneous connections, which has created a new set of problems for us, causing what many of you saw yesterday as 503 Service Temporarily Unavailable.

For now, we’ve enabled CloudFlare on our site, hoping by having CloudFlare cache our site (which is mostly static), it would help relieve some of our simultaneous connections issues.

We’ve also reworked how our site caching worked, making it less agressive at expiring cache. You might end up seeing some stale pages once in awhile. Hopefully that’ll help too.

In the meantime, we’re looking into options for a more reliable webhost.

Converting MKV to MP4 on Mac OSX

So I’ve been using QuickTime Player to re-encode most videos into 1080p, 720p, and 480p resolutions and that’s been working out great so far. The only problem is it doesn’t seem to understand MKV files, making it unable to re-encode them.

I’ve been searching for a tool for Mac that can do that job. On Windows, I’ve have an arsenal of tools that I used to use (e.g. Yamb, MeGUI). On Mac, everything I’ve tried seemed to do a rather poor job. Audio/Video quality was bad and often times would just fail trying to re-encode the file.

Today I happened to find this thread, which was extremely helpful: Why is it so freaking hard to convert .mkv to .MP4? Despite the topic, there were some really good information on which tools to try:

So the first one I tried was FFMpeg, because it was free and I was able to quickly install using HomeBrew. The command to run looked easy enough:
ffmpeg -i video.mkv -vcodec copy video.mp4

The video output was flawless, but the audio was all garbled up. Not that it was unrecognizable, but the audio had a much deeper pitch than the original. I’m pretty sure there’s some options I could pass into it to increase the audio quality, but I decided try some of the other suggestions.

I tried Subler next and this one failed hard. I selected the tracks I wanted followed by how to encode it, but every configuration I tried errored out with no message or log.

I looked at iVI next, but it was linked to a $10 app on the app store, and I wasn’t willing to purchase it w/o confirming that it would do the job. Later I found out their website actually allowed you to download a trial. They should probably mention that on their app store.

iFlicks looked more like a media manager that made videos compatible with your iDevice, so I skipped that one.

From the thread, HandBrake was suggested if I wanted to passthrough the video and audio, but I knew I needed to re-encode the audio track, so I skipped this one too.

I finally ended up at MP4Tools. I had skipped this initially because it sounded like a tool I’ve tried on Windows which was rather bad. But it turned out this tool was the best for the job on the Mac. Interface was pretty straight forward and at the outputted file’s video/audio quality was top notch. This is shareware and I ended up paying the $6 registration fee because this app’s going to save me a lot of time in the future.

Hope this post helps anyone looking for a better way to convert MKVs to MP4 on Mac OSX.

Review: The Perks of Being a Wallflower

theperksofbeingawallflower-poster-jpg_220830I wasn’t very interested when I first saw the trailer for The Perks of Being a Wallflower, but Netflix suggested I should watch it (4-star worthy) and they really know me better than myself.

Though one thing I do have to say about the trailer was that it introduced me to Imagine Dragons, one of my favorite new bands. After rewatching the trailer, I noticed they pulled out “BE AGGRESSIVE! PASSIVE AGGRESSIVE!” scene.

I initially thought the story was about a coming of age story about a boy starting high school with no friends, but it’s so much more than that. The 3 main characters (Logan Lerman as Charlie, Emma Watson as Sam, and Ezra Miller as Patrick) gave outstanding performances.

<spoilers>
Right off the bat, you get a vibe there’s something not quite right with Charlie. He seems like a kid dealing with depression. You have a feeling the family understands Charlie isn’t quite alright, but doesn’t really know everything that is going on. Whatever it is, it’s preventing Charlie from making friends.

Charlie meets up with Patrick and Sam shortly after starting high school and he feels he could be friends with them. One time at a party after getting stoned, he divulges that his best (only?) friend had shot himself. Not too much details here, and it felt a bit forced just to set the mood, but you learn this was really curve ball for the much bigger reveal at the end of the story.

Update: So after watching the deleted scenes, his best friend does show up in a memory sequence. It doesn’t really explain why he killed himself, but does explain the cafeteria scene where he doesn’t sit next to a girl he pointed out. Apparently that girl was his best friend’s girlfriend.

The story is told through a series of letters he writes to an anonymous person he “overheard” from some other students. I understand that the recipient of the letters isn’t really important, but it’s another aspect of the story that felt a bit forced. Who is the recipient? Was there a recipient? Given that that recipient never plays an active role in the story, would the story have been any different if Charlie wrote in a journal? If there was a really a recipient, was there really a reason he replied to offer help.

Update: I was reading the book’s plot on Wikipedia and was wondering why they didn’t include the part where Charlie’s sister got pregnant and confides in Charlie. Charlie sticks by her while she got an abortion. The scene was actually shot, but removed from the final cut. You can watch it in the deleted scenes.
</spoilers>

Very melodramatic, just the way I like it.

Netflix | Amazon | iTunes