lisamelton / video-transcoding-scripts

Utilities to transcode, inspect and convert videos.
MIT License
603 stars 76 forks source link

Unexpected results when invoking transcode-video.sh with the add-audio argument #16

Closed kford closed 9 years ago

kford commented 9 years ago

Hi Don,

Thanks for the great scripts!

I'm having a problem that is likely an issue with the way I'm using transcode-video.sh. I have source video that has a single (or multiple) AC-3 audio tracks. I wanted to convert them all to AAC (not add additional tracks) during transcoding. Here's an example

source.mkv (mediainfo tells me there is only a single audio track, like below)

Audio ID : 2 Format : AC-3 Format/Info : Audio Coding 3

I execute the following transcode-video.sh command
transcode-video.sh --slow --mkv --add-subtitle 1 --add-audio 1 --crop 54:58:0:0 source.mkv
And it produces target.mkv (mediainfo tells me there are now 3 audo tracks in the target file, like below)

Audio #1 ID : 2 Format : AC-3 Format/Info : Audio Coding 3 ... Audio #2 ID : 3 Format : AAC Format/Info : Advanced Audio Codec ... Audio #3 ID : 4 Format : AAC Format/Info : Advanced Audio Codec

I'd appreciate any advice you can offer

Thank you.

lisamelton commented 9 years ago

kford,

I'm glad you like the scripts. Thanks.

By default, transcode-video.sh will create two audio tracks for input like your source.mkv example. You're getting a third track because you added that same main audio track again.

Let me explain in detail what's happening and then how you can easily fix it. First, the diagnosis... :)

The way that transcode-video.sh works is that, If possible, audio is first passed through in its original form. When audio transcoding is required, it's done in AAC format. And if the original is multi-channel surround sound (which your source.mkv file seems to be), it's also done in Dolby Digital AC-3 format. Meaning the output can contain two tracks from the same source in different formats.

Dual format audio tracks are essentially required for proper playback on Apple TV. Which is why this is the the default behavior.

For output in a Matroska format container (which you've requested via the --mkv option), the dual audio tracks are ordered AC-3 format first and then AAC format.

By default, transcode-video.sh uses the first audio track in the input as the main audio track. You can override that behavior by using the --audio option to identify a different track. (Note: not the --add-audio option.) You haven't done that and since source.mkv only contains a single audio track it doesn't matter.

However, you did request to add that that same track again to the output via the --add-audio 1 option and argument. By default, additional audio tracks are added in AAC format. Which means the second and third track of your output are identical.

Now, let me give your the cure... :)

For the case of an input file with a single audio track, simply use the --no-surround option to prevent creation of any AC-3 audio tracks and do not use the --add-audio option at all:

transcode-video.sh --slow --mkv --no-surround --add-subtitle 1 --crop 54:58:0:0 source.mkv

For the case of an input file with multiple audio tracks, you'll need to identify how many additional tracks there are and simply use an --add-audio option for each track with the appropriate track number. For example, here's how you might handle a file with two additional audio tracks:

transcode-video.sh --slow --mkv --no-surround --add-audio 2 --add-audio 3 --add-subtitle 1 --crop 54:58:0:0 source.mkv

In the future, I'm considering a way to do something like --add-audio all to make this even simpler. But for now, you need to use an option for each track. Which is how I use the script when I add named commentary tracks.

I hope that helps.

I'm closing this issue now but feel free to continue commenting here or in additional issues. Your questions and feedback are always welcome. Thanks.

kford commented 9 years ago

Thanks for the detailed response Don! I've read it and I'll be updating my batch script to reflect what you've just shared with me. Your example command was

transcode-video.sh --slow --mkv --no-surround --add-audio 2 --add-audio 3 --add-subtitle 1 --crop 54:58:0:0 source.mkv

I assume, based on the quote below, that you added audio tracks 2 and 3 because track 1 was added by default (and because you specified no-surround, it was added as AAC), so you query the source to determine number of tracks, and add them all, excluding the first one which is added by default. Correct?

For the case of an input file with multiple audio tracks, you'll need to identify how many additional tracks there are and simply use an --add-audio option for each track with the appropriate track number. For example, here's how you might handle a file with two additional audio tracks:

lisamelton commented 9 years ago

Correct.