diff --git a/README.md b/README.md index d70cce40..27cfc8e1 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ General Installation Instructions - `delete_original` = True/False - `relocate_moov` = True/False - relocates the MOOV atom to the beginning of the file for better streaming - `ios-audio` = creates a 2nd copy of an audio stream that will be iOS compatible (AAC Stereo) if the normal output will not be. If a stereo source stream is detected with this option enabled, an AAC stereo stream will be the only one produced (essentially overriding the codec option) to avoid multiple stereo audio stream copies in different codecs. + - `max-audio-channels` = Sets a maximum number of audio channels. This may provide an alternative to the iOS audio option, where instead users can simply select the desired output codec and the max number of audio channels without the creation of an additional audio track. - `video-codec` = set your desired video codecs. May specificy multiple comma separated values (ex: h264, x264). The first value specified will be the default conversion choice when an undesired codec is encountered; any codecs specified here will be remuxed/copied rather than converted. - `audio-codec` = set your desired audio codecs. May specificy multiple comma separated values (ex: ac3, aac). The first value specified will be the default conversion choice when an undesired codec is encountered; any codecs specified here will be remuxed/copied rather than converted. - `audio-language` = 3 letter language code for audio streams you wish to copy. Leave blank to copy all. Separate multiple audio streams with commas (ex: eng,spa) diff --git a/autoProcess.ini.sample b/autoProcess.ini.sample index d8c5a818..62e4c2ec 100644 --- a/autoProcess.ini.sample +++ b/autoProcess.ini.sample @@ -27,6 +27,7 @@ relocate_moov=True audio-codec=ac3 video-codec=h264,x264 ios-audio=True +max-audio-channels= audio-language= audio-default-language= subtitle-language= diff --git a/mkvtomp4.py b/mkvtomp4.py index db81c97b..5b6d5168 100644 --- a/mkvtomp4.py +++ b/mkvtomp4.py @@ -23,6 +23,7 @@ def __init__( self, settings=None, audio_codec=['ac3'], audio_bitrate=None, iOS=False, + maxchannels=None, awl=None, swl=None, adl=None, @@ -51,6 +52,7 @@ def __init__( self, settings=None, self.audio_codec=audio_codec self.audio_bitrate=audio_bitrate self.iOS=iOS + self.maxchannels=maxchannels self.awl=awl self.adl=adl # Subtitle settings @@ -83,6 +85,7 @@ def importSettings(self, settings): self.audio_codec=settings.acodec #self.audio_bitrate=settings.abitrate self.iOS=settings.iOS + self.maxchannels=settings.maxchannels self.awl=settings.awl self.adl=settings.adl #Subtitle settings @@ -214,10 +217,18 @@ def generateOptions(self, inputfile, original=None): else: abitrate = self.audio_bitrate + # Audio channel adjustments + if self.maxchannels and a.audio_channels > self.maxchannels: + audio_channels = self.maxchannels + if acodec == 'copy': + acodec = self.audio_codec[0] + else: + audio_channels = a.audio_channels + audio_settings.update({l: { 'map': a.index, 'codec': acodec, - 'channels': a.audio_channels, + 'channels': audio_channels, 'bitrate': abitrate, 'language': a.language, }}) diff --git a/readSettings.py b/readSettings.py index 4d971497..ee196e2c 100644 --- a/readSettings.py +++ b/readSettings.py @@ -32,6 +32,7 @@ def __init__(self, directory, filename): 'delete_original': 'True', 'relocate_moov': 'True', 'ios-audio': 'True', + 'max-audio-channels': '', 'audio-language': '', 'audio-codec': 'ac3', 'video-codec': 'h264, x264', @@ -161,6 +162,20 @@ def __init__(self, directory, filename): self.embedsubs = config.getboolean(section, 'embed-subs') + #Setup variable for maximum audio channels + self.maxchannels = config.get(section, 'max-audio-channels') + if self.maxchannels == "" + self.maxchannels = None + else: + try: + self.maxchannels = int(self.maxchannels) + except: + print "Invalid number of audio channels specified" + self.maxchannels = None + if self.maxchannels is not None and self.maxchannels < 1: + print "Must have at least 1 audio channel" + self.maxchannels = None + self.vcodec = config.get(section, "video-codec") if self.vcodec == '': self.vcodec == ['h264', 'x264']