Encoding video/audio on macOS

Hi! Would you mind answering a quick question?

I saw your post here:

  1. I am trying to encode using handbrake with the best settings for ALL devices and software.
  • Plex app on AppleTV and iOS
  • iTunes on macOS
  • AppleTV - TV app and Computer App
  • TV app on iPhone XS Max
  • Amazon Firestick
  • Google Chromcast
  1. To be specific to a current project I am working on… The source has an audio track, “DTS-HD MA”. That is an uncompressed audio track.
  2. Could I use Handbrake to passthru that 1 track only (DTS-HD MA)? and not encode a second 2.0 stereo audio track?
  3. And will that DTS-HD MA track be transcoded on the fly to 2.0 stereo when necessary by:
  • Plex
  • AND… iTunes and the Apple TV "Computer "app, using Homekit to stream a movie from my iTunes library on my Macbook Pro?

Thanks so much,

Jas

Older versions of Handbrake used to provide device specific presets… in those days you were best served with the Apple (iOS, tvOS) related presets as those tended to be the most restrictive.
In the meantime Handbrake offers more generic presets which should be working fine with most recent models (Apple or others).
Personally I’d go with the h264/mp4 based presets on either high or super high quality (impacts the transcoding time).

With DTS-HD MA things will get more tricky.

  1. it’s not supported by all containers — from what I remember only by MKV
  2. your Apple devices won’t play it (at least not natively / without transcoding) — that is probably true for most streaming devices/phones

That being said… if you pick MKV as the target container for Handbrake you can select that audio stream to be passed through.
For best compatibility you should however consider going with mp4/m4v and e.g. transcoding the audio track to AC3/AAC or at least include an AC3/AAC copy of that track alongside the original.

Plex will be able to deal with the file in an MKV container and transcoding the audio track on the fly. iTunes won’t…

1 Like

The limiting factors are iTunes and the AppleTV. iTunes limits you to the mp4/m4v container, which means AC3/EAC3/AAC audio. The AppleTV limits AAC audio to 320kbps (which isn’t really too bad for that codec). Subtitles are text/SRT only. No PGS or VOBSUB.

You’ll want to encode to the following:

MP4 container, with M4V extension
Video: H.264, High@4.0 or lower.
Audio: AAC 2.0, 320kbps or lower
Audio (optional): AC3 5.1, 640kbps or less.
Subtitles: SRT

Personally, I use the Super HQ 1080p30 Surround preset with a few modifications.

  • Summary Tab: Check Web Optimized (optimizes video for streaming) and Align A/V Start
  • Dimensions: No changes.
  • Filters: None for most media. See note below.
  • Video: Set FPS to match source, Quality to 20 for Blu-ray, 18 for DVD.
  • Audio: First track, AAC 2.0, 320kbps; Second track AC3 passthru or AC3 5.1, 640kbps.
  • Subtitles: If source has a foreign audio track, then I burn in it (personal preference). If I have a SRT source, then I’ll add (not burn) it as well.
  • Chapters: No change.

Regarding filters:

  1. Interlace Detection / Deinterlace
  • Examine the source with MediaInfo.
  • If progressive, disable the filter. If you leave it enabled it will slow down your transcode unecessarily.
  • If it is interlaced, then leave interlace detection & de-interlacing enabled. The default settings (default/decomb/default) work fine for me. If the source is heavily interlaced, realize there is only so much Handbrake can do. You’ll still end up with some artifacts.
  1. Denoise
    Many movies have a grainy picture. It is common in black and white films and in older color movies that have a poor transfer to disc. This can cause file sizes to balloon when transcoding, since compression efficiency takes a nosedive. The Denoise filter can help clean things up and reduce file size. Use the NLMeans filter. I use Ultralight or Medium presets depending on the amount of noise. Tune = none. This is one of those things you’ll have to try for yourself. You’ll get a feeling for it after a few attempts. Find a movie w/ a grainy picture and encode one or two chapters as a test. Vary the settings - none/ultralight/etc. You’ll see the difference.

Regarding Audio:

  1. Don’t oversample. If an audio track is at 192kbps (old movies, commentary tracks, etc), there’s no need to oversample. It doesn’t buy you anything.
  2. 320kbps is the limit for AAC on AppleTVs. Don’t exceed it our you may have playback problems.
  3. Handbrake looks at the dts core, so it won’t matter if you pick the dts-HD or dts audio track (blurays w/ dts-HD audio also have a corresponding dts track).
  4. Adjust as necessary. You’ll find some discs with mono audio, PCM audio, and other stuff.

Regarding video:
Quality is subjective. The constant quality settings, 18 & 20, are what I use. I have a hard time seeing a difference between the original and transcode at those settings. Adjust as you see fit. Remember 1) a lower number increases the quality; and 2) file size increases exponentially. Encode a movie at 18, then repeat at 15. You’ll see the difference in file size.

2 Likes

THANK YOU @FordGuy61 and THANK YOU @tom80H !

Please accept my apologies for the delay in response, I’ve been traveling.

@FordGuy61 I appreciate your detailed response! I have several things I’ve set aside to research and I’ll have a few more questions when I am finished. I’ll get back to you as soon as possible.

In the meantime, I’m trying to resolve another issue. A simple conversion. As I understand it, Handbrake does not do simple converts (e.g. mkv to m4v) it only does transcodes. In this case, I need a convert only, from mkv to m4v.

I am looking for a mac app that does this specifically:

  1. open mkv
  2. uncheck unwanted audio tracks
  3. select m4v as output
  4. convert (just a simple convert, with no transcoding, thereby avoiding quality loss)

Any mac apps that might do this?

Continued Appreciation,

Jas

Correct. Handbrake transcodes. It does not have a remux/copy function.

Look at Subler, subler.org. Originally started as a way to add subtitles to mp4/m4v files but now has many other capabilities.

Subler won’t directly open a MKV file. Open a window for a new file, then drag the MKV file into the window. You’ll see a dialog box where you can select what to import.

Also check MP4/MKV/AVI/SubTools: http://www.emmgunn.com/mp4tools-home/

If you do want to remux MKV files, look at MKVToolNix, https://mkvtoolnix.download/downloads.html.

Edit: FYI, be aware MP4 doesn’t support TrueHD audio or PGS/VOBSUB subtitles, at least Subler doesn’t. They’ll be converted to another format. Subler will import dts & dts-HD audio tracks into MP4 containers.

2 Likes

Hello @FordGuy61 & @tom80H,

I’m dealing with a complicated project I think is a best-case scenario for learning.

For the moment, to maintain maximum quality, I’m going to work with Subler to perform an .mkv to .m4v convert without transcoding video.

Subler has some confusing audio options (no user manual) for this project and the project itself is a bit complex. As you can see, there are quite a few audio tracks I will demux for the final file.



OBJECTIVE - THREE AUDIO TRACKS:

  • 6 Channel - for AppleTV via a 5.1 Home Theater
  • 2 Channel - for AppleTV via stereo TVs & iOS devices
  • 2 Channel - Isolated Score for All Devices


1. AUDIO TRACKS SELECTED IN BLUE - I’D LIKE TO KEEP IN THE FINAL FILE:





2. TRACK 1 AND 2 (DTS SOURCES) - BELOW ARE THE DROPDOWN OPTIONS:





3. TRACK 10 (AC3 SOURCE) - BELOW ARE THE DROPDOWN OPTIONS:

  • I understand you suggested I encode in AAC for the stereo track, but, in this case, would I really want to transcode from AC-3 to AAC or just use passthru and keep AC-3 to avoid quality loss/audio artifacts?

4. SUBLER OPTIONS

  • I unchecked AC-3 audio to AAC for the moment. Your answer to number 3 above will likely tell me if I need to recheck that option. And Keep AC-3 box below it?





What are your suggestions?

I’ll be using Subler to add metadata as well. It’s much more developed than MetaZ. Following, I’ll use Handbrake to create smaller files.


Continued Appreciation,

Jas

Passthrough for video, just like you have it.

6 Channel - for AppleTV via a 5.1 Home Theater
2 Channel - for AppleTV via stereo TVs & iOS devices

Here’s the question: For the 2 channel audio track, do you prefer (a) Subler to downmix dts 5.1 to AAC 2.0 or (b) do you prefer Subler to transcode dts 2.0 to AAC 2.0?

Since this is unknown, I propose you do both, at least for the first movie. See how things sound, then delete the unwanted track(s) when you finalize things.

So…
For DTS 6 ch, choose AAC + AC3
For DTS 2 ch, choose AAC - Stereo

You’ll end up with one AC3 audio track and two AAC tracks. Listen to both AAC audio tracks on appropriate devices, see which one sounds best, then delete the other AAC track.

2 Channel - Isolated Score for All Devices
This is up to you. Definitely passthrough the AC3 track for your home theater. If desired, you can add an AAC track for compatibility with older devices that don’t support AC3.

See notes below with respect to AAC audio and track order.

Advanced Tab Settings
Convert: Go ahead and check the box for “AC-3 audio to AAC” and “Keep AC-3.” I think this just enables options on the pull down menus when importing audio tracks, so you can always override it. You can always uncheck it later if you don’t need it. You can also just delete the audio track from the file if it is not needed.

Downmix audio to: Stereo or Dolby Pro Logic II (it doesn’t matter).
Unless you have a specific need for Dolby Pro Logic II, then just choose stereo. Note that if you play a Dolby Pro Logic II audio track on a device that doesn’t support it, you get stereo, so in truth, it really doesn’t matter. DPLII is a way to deliver 5.1 sound over a 2.0 audio stream. Details at Wikipedia and Dolby.

Bitrate: Choose 320kbps instead of default 160kbps. 320kbps is the max rate supported by an AppleTV (and Subler) for AAC audio and will give you the best audio quality. I do not know if you can hear the difference on an iPhone, but you’ll definitely hear the difference on a decent home theater setup.

AAC Audio Note

AAC audio is suggested for compatibility with older devices that do not support AC3/dts/etc audio formats. Including AAC audio is the safe thing to do.

However, most current devices support AC3 audio - iPhone 6S (2015) and later, iPad Air 2 (2014) and later, AppleTV 1st Gen (2007), and every TV in the US with a digital TV tuner (AC3 audio is part of the ATSC standard for over the air digital TV). Also every Amazon FireTV device (2014+) and my Nexus 5X Andoid phone from 2015.

What this implies is that you could possibly forgo AAC audio altogether if all of your clients support AC3 audio.

Personally, I always include an AAC audio track. It does not take up much space and provides a fallback in case somebody whips out a device that cannot play AC3. Just wanted to make you aware of the option.

Definitely test with current clients before deciding to leave out the AAC audio.

Audio Tip: Audio Track Order

When you first import the audio/video tracks from the MKV, but before you perform a save for the first time, you can re-order the tracks (The ID column will have “na” instead of “1,” “2,” etc).

Suggest you put the AC3 audio track before (higher) than the AAC audio track. Also, in the Enabled column, check the box for the AC3 audio, but not the AAC audio (determines default, not whether or not track will actually play).

Reason: Many Plex clients ignore the settings for default audio and choose the first track they find with preferred audio language. So, to make sure your home theater auto-selects the AC3 5.1 audio track, put it first, followed by the AAC audio track. This avoids you having to manually select the 5.1 audio every time you play a movie in your home theater.

Using Star Wars as an example, you would have:

1 Video 
2 AC3 5.1 version of "1977 70mm six track mix"
3 AAC 2.0 version of above track
4 AC3 2.0 passthru of "Isolated Score"
5 AAC 2.0 version of "Isolated Score"
6 Subtitles
7 Chapters

Subler Tip for iTunes: Organize Alternate Groups & Fix Audio Fallbacks
This does not matter to Plex. It helps if you want to import the movie into iTunes. After you have the tracks arranged as desired, from the Action pull down, select “Organize Alternate Groups” and then “Fix Audio Fallbacks.” This helps iTunes tell the difference between primary audio tracks, commentary tracks, etc. It also tells iTunes to try the AC3 audio first, then fallback to AAC if AC3 won’t play on the client. You can see/modify the results by highlighting an audio track then clicking on “Sound Settings.”

Subler Tip: Optimize
Be sure and Optimize the file. Do this as the last thing before you add the file to your Plex library (i.e. after adding audio/video tracks, metadata, etc). This re-organizes some bits to optimize streaming (See FAQ or Google “MP4 Fast Start”).

FYI XMedia Recode: If you have access to a Windows PC, take a look at XMedia Recode. It would probably make remuxing from MKV to MP4/M4V easier than using Subler. Remuxing is a basic part of XMedia Recode’s capability. Subler was really designed for other things, so using it for remuxing can be difficult at times (as you’ve found out). XMedia Recode’s UI takes some getting used to. But after the first couple of runs, you’ll find it easy to copy or convert tracks as desired. After you remux/convert as needed, you can then pull the file into Subler to add metadata and such.

Hope this answers your questions and is not too confusing. I didn’t mean to write War & Peace. I just started typing and this is the result. :smile:

Cheers.

1 Like

Hi @FordGuy61

Excellent. I like War and Peace :smile: A few questions:



I’m not certain, but I will tell you this, the guy who mastered this fan edit is a genius and spent years of his life on it. He has included every track imaginable including Stereo tracks. It seems to me, I would want to transcode DTS 2.0 to AAC 2.0. Can you tell me why I would want to downmix from 6 track to stereo? Advantages? My thinking is, I want to do as little as possible and keep the converted file as pure and as close as possible to the original.



In Settings > Advanced, it reads, “Bitrate (per channel)” I entered 160 because, if it’s per channel 160 x 2 = 320. I read somewhere in a tutorial that is how it should be done. The default was much lower than that. I actually bumped it up to 160. Thoughts?



It is interesting to me when you use the preset for Apple TV, for example, in Handbrake it defaults to the stereo track first in the list, then the 5 channel second. Thoughts? It seems you are advising me to add the 6 channel first to adjust for Plex behavior and the other settings you mentioned ( Organize Alternate Groups & Fix Audio Fallbacks) are to adjust for iTunes. In Handbrake, it is preparing for AppleTV only. With your additional settings, I would have both Plex and iTunes working properly in regards to 5.1 playback on appropriate devices. Correct?



Sorry, where is the Optimize function? I remember seeing, but I don’t see it now. Also, that word Optimize scares me. Optimize usually means it will make the converted file smaller. I want it to be relatively the same as the source. I do not want to transcode video, only convert.

This is not difficult, it just requires the details you have provided me. I’m almost there!

Thank you! @FordGuy61

I cannot answer this.

  • I do not know the quality of either track. For all I know one could sound much better than the other.
  • What is the progeny of each track? Are they unaltered rips from a DVD/Bluray or has somebody processed them afterwards?
  • I do not know the differences between either track. Did the 35mm release have a different mix than the 70mm release (sound effects, music mix, etc). If so, do you prefer one over the other?

That’s why I answered the way I did.

Let’s assume that all the tracks are original, unaltered, excellent quality, etc.

There would be no advantage to having Subler downmix 5.1 to 2.0. Probably safe to assume the studio engineers did an excellent job and have the mix they want.

Then go with the dts 2.0 track and let Subler convert it to AAC 2.0.

The nerdy engineer in me would still convert the dts 5.1 to AAC 2.0 at least once, just out of curiosity. It is easy enough to delete the track later. :nerd_face:

Good catch.

I go with 320 kbps total, since that is the maximum supported by an AppleTV. A family member uses iTunes and an AppleTV and I need to keep things compatible for them.

FWIW, I just ran a quick test and it did not matter whether I set Subler to 160 or 320. It encoded the audio to AAC 2.0 at 320kbps total.

Maybe Subler has some internal limit to not exceed 320kbps for AAC? I don’t use the audio conversion capability in Subler much. There could be some limits, etc, of which I’m not aware.

FYI, 320kbps is an average bitrate. If you examine the file with MediaInfo or other tools, you may see a higher max rate.

Yes.

I have a FireTV Cube and a Nvidia Shield (both Android TV). The Plex app ignores any default audio track flags and chooses the first audio stream in the file that matches the preferred language setting. If that first stream is 2.0 and I’m watching in my home theater, I have to manually switch to the 5.1 mix.

If I stream the same movie via iTunes to an AppleTV, it picks follows the default and fallback settings in the MP4/M4V file, irrespective of the order of the audio tracks.

So, placing the 5.1 track first means I do not have to manually select it in Plex. The iTunes/AppleTV combo will also default to 5.1 in a home theater setup as it honors the flags in the file.

The issue you might run into is a Plex client that does not support AC3, so PMS would probably transcode the audio to AAC 2.0. However, most recent (last 5 yrs) devices support AC3 so you probably won’t run across it much. Even if you do, transcoding audio doesn’t hit the CPU much, so the impact on your PMS server should be minimal if/when it happens.

Obviously all this is based on how I use Plex. If it works better for you to have the tracks in a different order then do so. There’s no right or wrong, just what best fits your needs.

File → Optimize.

Doesn’t alter audio/video. Reorders bits in mp4 headings for better streaming. You can search Google for the details. It is a good thing.

Hi @FordGuy61

Excellent point and much more apparent when I’m not typing at 4 am. I’m going to research this before I convert. I’ll let you know what I discover. This is STAR WARS. So, it’s of the utmost significance :joy:



Thanks. My usage will strictly be iTunes and Plex on the newest devices. This is an extremely helpful detail, thank you. There is an AppleTV 3 & 4 in the mix, but everything else, AppleTV 4K, Macs, iPhones & iPads, are less than a year old.



As you can see in the 2 attached screenshots, there are two locations where Optimize is available.

  • FIle > Optimize
    • This is greyed out. Any idea why based on this screenshot?



  • Save As Dialogue Box
    • I imagine this is the same functionality as the above location?





I think we’ve covered everything. As soon as you get back to me, I’ll begin converting.

:folded_hands: Jas

If optimize is greyed out, perform a save first. You’ll then be able to optimize the file.

You might be able to optimize when doing a save as. It does the same thing. Just potentially saves you a step.

1 Like

Alternatively… e.g. if you’re dealing with multiple files… open Subler‘s queue, check the actions listed under the gear icon (e.g. optimize… but there’s more useful ones), drag&drop the Media files into the queue and click Run

1 Like

I’ve used Subler for ages and didn’t know about the queue. Thanks for mentioning it!

Very helpful when you want to add metadata from iTunes or TheMovieDb to a hole lot of (correctly named) files

Update @FordGuy61 & @tom80H


There are two parts to this puzzle:

  • Bitrate level
  • Origin of each track, differences etc. (as you mentioned - still waiting on someone to get back to me on this)

See attached images. I used Mediainfo app for Mac to pull up these details. These should answer some questions. What are your thoughts?

Also, how well does 5.1 downmix to 2.0? Since 5.1 was not intended to be 2.0, I would imagine the end 2.0 result will not be perfect. That also might be a reason to chose the existing stereo track, since it was originally recorded with the intention of 2.0, no?



Audio%206%20Track

Audio%202%20Track

Thank you,

Jas

I’ve never had a problem downmixing 5.1 to 2.0 in Handbrake, which is the tool I primarily use to transcode movies.

However, the studio is giving you a 2.0 track already, so why not use it? They’ve already done the downmixing for you.

If it were me I would try them both and pick the one I liked best.

Also, who is going to be listening to the 2.0 track - people on their phone/tablet with bluetooth headphones or TV using TV speakers? They probably won’t be able to tell the difference anyway.

Audio conversion runs fast. It will take a just a few minutes to add an audio track to an existing movie.

Make several versions, experiment with the tools to see how they work.

Toss all the versions in a test library and see which you like best.

Use an “Other Videos” type library, so Plex won’t try to download metadata, etc. Give the versions descriptive titles so you know which is which - SW_downmix.mp4; SW_dts2.0.mp4, etc (use whatever name you want).

If you screw up and one of them sounds like :poop:, who cares? That’s how you learn. Just toss it in the trash and make another one.

@FordGuy61

Quick question. Do those screenshots above tell you that the 5.1 track has a higher bitrate (per channel) than the 2.0 track?

Thanks,

Jas

Average bitrates for the entire stream/track are…

  • 2.0 track: 1,026 kb/s
  • 5.1 track: 2,369 kb/s

So in pure theory, you’re getting a better quality baseline from the stereo track (based on bitrate). As for reality… I’m with FordGuy61: test it to see if you can make out a difference.

I tend to be a little cynical about this as many will claim to notice a significant quality difference when only very few actually do / are capable to make out the slightest difference.

2 Likes

Hi @tom80H & @FordGuy61, I’ve been traveling and will be for a while longer. I didn’t want this post to close. I appreciate your help and will get back to you ASAP!

Much appreciation,

Jasmer