def test_profile_merge(self): p1 = Profile("p1", {"one": 1, "two": 2, "input_options": ["three", "four", "five"]}) p2 = Profile("p2", {"one": 11, "six": 6, "input_options": ["seven", "four"]}) p2.include(p1) self.assertEqual(p2.get("one"), 11, 'expected 11 for "one"') self.assertEqual(p2.get("two"), 2, 'expected 2 for "two"') self.assertEqual(p2.get("six"), 6, 'expected 6 for "six"') op2 = sorted(p2.input_options.as_list()) expected = sorted(["three", "four", "five", "seven"]) self.assertEqual(op2, expected, "Unexpected input_options merger")
def rule_hook(mediainfo: MediaInfo) -> Optional[Profile]: # # skip of already hevc # if mediainfo.vcodec == "hevc": raise ProfileSKIP() # # small enough already # if mediainfo.filesize_mb < 2500 and 720 < mediainfo.res_height < 1081 and 30 < mediainfo.runtime < 65: raise ProfileSKIP() # # skip video if resolution < 700: # don't re-encode something this small - no gain in it # if mediainfo.res_height < 700: raise ProfileSKIP() # # Here is a complex example you can only perform with a custom hook. # # strip redundant HD audio tracks from 4k to make it smaller # if mediainfo.vcodec == 'hevc' and mediainfo.res_height >= 2160 and len( mediainfo.audio) > 1: profile = Profile("strip-DTS") truehd_track = None ac3_track = None for track in mediainfo.audio: if track['lang'] != 'eng': continue if track['format'] == 'truehd': truehd_track = track['stream'] elif track['format'] == 'ac3': ac3_track = track['stream'] # if both English tracks exist, eliminate truehd and keep ac3 - don't transcode video if truehd_track and ac3_track: profile.automap = False # override default profile.output_options.merge({ '-map': ac3_track, '-c:v': 'copy', '-c:s': 'copy', '-c:a': 'copy', '-f': 'matroksa' }) profile.extension = '.mkv' return profile # # anime # if '/anime/' in mediainfo.path: profile = Profile("anime") profile.include(common) # include: common profile.output_options.merge([ "-c:v hevc_nvenc", "-profile:v main", "-preset medium", "-crf 20" ]) profile.queue_name = "cuda" # queue: cuda profile.automap = True # automap: yes return profile # # high frame rate # if mediainfo.fps > 30 and mediainfo.filesize_mb > 500: profile = Profile("high-frame-rate") profile.include(common) # include: common profile.output_options.merge([ "-c:v hevc_nvenc", "-profile:v main", "-preset medium", "-crf 20", "-r 30" ]) profile.queue_name = "cuda" # # default to no profile to continue on and evaluate defined rules next (transcoder.yml) # return None