From 2565aea05f60b8e4a449bc6e19e4e701d3d0299f Mon Sep 17 00:00:00 2001 From: Michael Higgins Date: Thu, 22 Jan 2015 14:33:14 -0500 Subject: [PATCH] video-bitrate update Allows you to set a maximum video bitrate --- autoProcess.ini.sample | 1 + mkvtomp4.py | 14 +++++++++++--- readSettings.py | 11 +++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/autoProcess.ini.sample b/autoProcess.ini.sample index 306e35a6..7affe160 100644 --- a/autoProcess.ini.sample +++ b/autoProcess.ini.sample @@ -26,6 +26,7 @@ delete_original=True relocate_moov=True audio-codec=ac3 video-codec=h264,x264 +video-bitrate= ios-audio=True max-audio-channels= audio-language= diff --git a/mkvtomp4.py b/mkvtomp4.py index dc048213..668947d0 100644 --- a/mkvtomp4.py +++ b/mkvtomp4.py @@ -19,7 +19,8 @@ def __init__( self, settings=None, output_dir=None, relocate_moov=True, output_format = 'mp4', - video_codec=['h264', 'x264'], + video_codec=['h264', 'x264'], + video_bitrate=None, audio_codec=['ac3'], audio_bitrate=256, iOS=False, @@ -48,6 +49,7 @@ def __init__( self, settings=None, self.relocate_moov=relocate_moov # Video settings self.video_codec=video_codec + self.video_bitrate=video_bitrate # Audio settings self.audio_codec=audio_codec self.audio_bitrate=audio_bitrate @@ -81,6 +83,7 @@ def importSettings(self, settings): self.relocate_moov = settings.relocate_moov #Video settings self.video_codec=settings.vcodec + self.video_bitrate=settings.vbitrate #Audio settings self.audio_codec=settings.acodec self.audio_bitrate=settings.abitrate @@ -185,7 +188,12 @@ def generateOptions(self, inputfile, original=None): #Video stream print "Video codec detected: " + info.video.codec - vcodec = 'copy' if info.video.codec in self.video_codec else self.video_codec[0] + if self.video_bitrate is not None and info.format.bitrate > self.video_bitrate: + vcodec = self.video_codec + vbitrate = self.video_bitrate + else: + vcodec = 'copy' if info.video.codec in self.video_codec else self.video_codec[0] + vbitrate = info.format.bitrate #Audio streams audio_settings = {} @@ -362,7 +370,7 @@ def generateOptions(self, inputfile, original=None): 'video': { 'codec': vcodec, 'map': info.video.index, - 'bitrate': info.format.bitrate + 'bitrate': vbitrate }, 'audio': audio_settings, 'subtitle': subtitle_settings, diff --git a/readSettings.py b/readSettings.py index 16aef636..e4a70a73 100644 --- a/readSettings.py +++ b/readSettings.py @@ -39,6 +39,7 @@ def __init__(self, directory, filename): 'audio-codec': 'ac3', 'audio-channel-bitrate': '256', 'video-codec': 'h264, x264', + 'video-bitrate': '', 'subtitle-language': '', 'audio-default-language': '', 'subtitle-default-language': '', @@ -201,6 +202,16 @@ def __init__(self, directory, filename): else: self.vcodec = self.vcodec.lower().replace(' ', '').split(',') + self.vbitrate = config.get(section, "video-bitrate") + if self.vbitrate == '': + self.vbitrate = None + else: + try: + self.vbitrate = int(self.vbitrate) + except: + print "Invalid video bitrate, defaulting to no video bitrate cap" + self.vbitrate = None + self.awl = config.get(section, 'audio-language').strip().lower() # List of acceptable languages for audio streams to be carried over from the original file, separated by a comma. Blank for all if self.awl == '': self.awl = None