def encode(clip: vs.VideoNode, binary: str, output_file: str, **args) -> None: """Stolen from lyfunc Args: clip (vs.VideoNode): Source filtered clip binary (str): Path to x264 binary. output_file (str): Path to the output file. """ cmd = [binary, "--demuxer", "y4m", "--frames", f"{clip.num_frames}", "--sar", "1:1", "--output-depth", "10", "--output-csp", "i420", "--colormatrix", "bt709", "--colorprim", "bt709", "--transfer", "bt709", "--no-fast-pskip", "--no-dct-decimate", "--partitions", "all", "-o", output_file, "-"] for i, v in args.items(): i = "--" + i if i[:2] != "--" else i i = i.replace("_", "-") if i in cmd: cmd[cmd.index(i)+ 1] = str(v) else: cmd.extend([i, str(v)]) print("Encoder command: ", " ".join(cmd), "\n") process = subprocess.Popen(cmd, stdin=subprocess.PIPE) clip.output(process.stdin, y4m=True, progress_update=lambda value, endvalue: print(f"\rVapourSynth: {value}/{endvalue} ~ {100 * value // endvalue}% || Encoder: ", end="")) process.communicate()
def do_encode(clip: vs.VideoNode) -> vs.VideoNode: """Compression with x26X""" if not os.path.isfile(JPBD.output): print('\n\n\nVideo encoding') bits = clip.format.bits_per_sample x265_cmd = f'x265 -o {JPBD.output} - --y4m' + ' ' x265_cmd += f'--csv {JPBD.name}_log_x265.csv --csv-log-level 2' + ' ' x265_cmd += '--preset slower' + ' ' x265_cmd += f'--frames {clip.num_frames} --fps {clip.fps_num}/{clip.fps_den} --output-depth {bits}' + ' ' x265_cmd += '--rd 3 --no-rect --no-amp --rskip 1 --tu-intra-depth 2 --tu-inter-depth 2 --tskip' + ' ' x265_cmd += '--merange 48 --weightb' + ' ' x265_cmd += '--no-strong-intra-smoothing' + ' ' x265_cmd += '--psy-rd 2.0 --psy-rdoq 1.5 --no-open-gop --keyint 240 --min-keyint 23 --scenecut 40 --rc-lookahead 60 --bframes 16' + ' ' x265_cmd += '--crf 15 --aq-mode 3 --aq-strength 0.85 --cbqpoffs -2 --crqpoffs -2 --qcomp 0.70' + ' ' x265_cmd += '--deblock=-1:-1 --no-sao --no-sao-non-deblock' + ' ' x265_cmd += f'--sar 1 --range limited --colorprim 1 --transfer 1 --colormatrix 1 --min-luma {str(16 << (bits - 8))} --max-luma {str(235 << (bits - 8))}' print("Encoder command: ", " ".join(shlex.split(x265_cmd)), "\n") process = subprocess.Popen(shlex.split(x265_cmd), stdin=subprocess.PIPE) clip.output(process.stdin, y4m=True, progress_update=lambda value, endvalue: print(f"\rVapourSynth: {value}/{endvalue} ~ {100 * value // endvalue}% || Encoder: ", end="")) process.communicate() print('\n\n\nAudio extraction') eac3to_args = ['eac3to', JPBD.src, '2:', JPBD.a_src.format(1), '3:', JPBD.a_src.format(2), '-log=NUL'] subprocess.run(eac3to_args, text=True, check=True, encoding='utf-8') print('\n\n\nAudio cutting') eztrim(JPBD.src_clip, (JPBD.frame_start, JPBD.frame_end), JPBD.a_src.format(1), JPBD.a_src_cut.format(1)) eztrim(JPBD.src_clip, (JPBD.frame_start, JPBD.frame_end), JPBD.a_src.format(2), JPBD.a_src_cut.format(2))
def do_encode(clip: vs.VideoNode)-> None: """Compression with x265""" print('\n\n\nVideo encoding') if not os.path.exists(JPBD.output): x265_args = [ "x265", "--y4m", "--frames", f"{clip.num_frames}", "--sar", "1", "--output-depth", "10", "--colormatrix", "bt709", "--colorprim", "bt709", "--transfer", "bt709", "--range", "limited", "--min-luma", str(16<<2), "--max-luma", str(235<<2), "--fps", f"{clip.fps_num}/{clip.fps_den}", "-o", JPBD.output, "-", "--frame-threads", "4", "--no-sao", "--fades", "--preset", "slower", "--crf", "15", "--qcomp", "0.70", "--bframes", "16", "--psy-rd", "2.0", "--psy-rdoq", "1.0", "--deblock", "-1:-1", "--rc-lookahead", "96", "--min-keyint", "23", "--keyint", "360", "--aq-mode", "3", "--aq-strength", "1.0" ] print("Encoder command: ", " ".join(x265_args), "\n") process = subprocess.Popen(x265_args, stdin=subprocess.PIPE) clip.output(process.stdin, y4m=True, progress_update=lambda value, endvalue: print(f"\rVapourSynth: {value}/{endvalue} ~ {100 * value // endvalue}% || Encoder: ", end="")) process.communicate() print('\n\n\nAudio extraction') eac3to_args = ['eac3to', JPBD.src, '2:', JPBD.a_src, '-log=NUL'] subprocess.run(eac3to_args, text=True, check=True, encoding='utf-8') print('\n\n\nAudio cutting') eztrim(JPBD.src_clip, (JPBD.frame_start, JPBD.frame_end), JPBD.a_src, JPBD.a_src_cut.format(1)) print('\n\n\nAudio encoding') qaac_args = ['qaac', JPBD.a_src_cut.format(1), '-V', '127', '--no-delay', '-o', JPBD.a_enc_cut.format(1)] subprocess.run(qaac_args, text=True, check=True, encoding='utf-8') ffprobe_args = ['ffprobe', '-loglevel', 'quiet', '-show_entries', 'format_tags=encoder', '-print_format', 'default=nokey=1:noprint_wrappers=1', JPBD.a_enc_cut.format(1)] encoder_name = subprocess.check_output(ffprobe_args, shell=True, encoding='utf-8') f = open("tags_aac.xml", 'w') f.writelines(['<?xml version="1.0"?>', '<Tags>', '<Tag>', '<Targets>', '</Targets>', '<Simple>', '<Name>ENCODER</Name>', f'<String>{encoder_name}</String>', '</Simple>', '</Tag>', '</Tags>']) f.close() print('\nFinal muxing') mkv_args = ['mkvmerge', '-o', JPBD.output_final, '--timestamps', '0:symphogearg_12_timecode.txt', '--track-name', '0:HEVC BDRip by Vardë@Kodoku-no-Kawarini', '--language', '0:jpn', JPBD.output, '--tags', '0:tags_aac.xml', '--track-name', '0:AAC 2.0', '--language', '0:jpn', JPBD.a_enc_cut.format(1), '--chapter-language', 'fra', '--chapters', JPBD.chapter] subprocess.run(mkv_args, text=True, check=True, encoding='utf-8') # Clean up files = [JPBD.a_src, JPBD.a_src_cut.format(1), JPBD.a_enc_cut.format(1), 'tags_aac.xml'] for file in files: if os.path.exists(file): os.remove(file)
def do_encode(clip: vs.VideoNode) -> None: """Compression with x26X""" print('\n\n\nVideo encoding') print('\n\n\nVideo encoding') x265_cmd = f'x265 -o {JPBD.output} - --y4m' + ' ' x265_cmd += f'--csv {JPBD.name}_log_x265.csv --csv-log-level 2' + ' ' x265_cmd += '--frame-threads 8 --pmode --pme --preset slower' + ' ' x265_cmd += f'--frames {clip.num_frames} --fps {clip.fps_num/clip.fps_den} --output-depth 10' + ' ' x265_cmd += '--rd 3 --no-rect --no-amp --rskip 1 --tu-intra-depth 2 --tu-inter-depth 2 --tskip' + ' ' x265_cmd += '--merange 48 --weightb' + ' ' x265_cmd += '--no-strong-intra-smoothing' + ' ' x265_cmd += '--psy-rd 2.0 --psy-rdoq 1.0 --no-open-gop --keyint 360 --min-keyint 12 --scenecut 45 --rc-lookahead 120 --bframes 16' + ' ' x265_cmd += '--crf 15 --aq-mode 3 --aq-strength 0.85 --qcomp 0.70' + ' ' x265_cmd += '--deblock=-1:-1 --no-sao --no-sao-non-deblock' + ' ' x265_cmd += f'--sar 1 --range limited --colorprim 1 --transfer 1 --colormatrix 1 --min-luma {str(16<<2)} --max-luma {str(235<<2)}' # + ' ' print("Encoder command: ", " ".join(shlex.split(x265_cmd)), "\n") process = subprocess.Popen(shlex.split(x265_cmd), stdin=subprocess.PIPE) clip.output( process.stdin, y4m=True, progress_update=lambda value, endvalue: print( f"\rVapourSynth: {value}/{endvalue} ~ {100 * value // endvalue}% || Encoder: ", end="")) process.communicate() print('\n\n\nAudio extraction') eac3to_args = ['eac3to', JPBD.src, '2:', JPBD.a_src, '-log=NUL'] subprocess.run(eac3to_args, text=True, check=True, encoding='utf-8') print('\n\n\nAudio cutting') eztrim(JPBD.src_clip, (JPBD.frame_start, JPBD.frame_end), JPBD.a_src, JPBD.a_src_cut.format(1)) print('\n\n\nAudio encoding') ffmpeg_args = [ 'ffmpeg', '-i', JPBD.a_src_cut.format(1), '-compression_level', '12', '-lpc_type', 'cholesky', '-lpc_passes', '3', '-exact_rice_parameters', '1', JPBD.a_enc_cut.format(1) ] subprocess.run(ffmpeg_args, text=True, check=True, encoding='utf-8') print('\nFinal muxing') mkv_args = [ 'mkvmerge', '-o', JPBD.output_final, '--track-name', '0:HEVC BDRip by Vardë@Raws-Maji', '--language', '0:jpn', JPBD.output, '--track-name', '0:FLAC 2.0', '--language', '0:jpn', JPBD.a_enc_cut.format(1) ] subprocess.run(mkv_args, text=True, check=True, encoding='utf-8') # Clean up files = [JPBD.a_src, JPBD.a_src_cut.format(1), JPBD.a_enc_cut.format(1)] for file in files: if os.path.exists(file): os.remove(file)
def do_encode(clip: vs.VideoNode)-> None: """Compression with x26X""" print('\n\n\nVideo encoding') bits = clip.format.bits_per_sample x265_cmd = f'x265 -o {JPBD.output} - --y4m' + ' ' x265_cmd += f'--csv {JPBD.name}_log_x265.csv --csv-log-level 2' + ' ' x265_cmd += '--frame-threads 4 --pmode --pme --preset slower' + ' ' x265_cmd += f'--frames {clip.num_frames} --fps {clip.fps_num}/{clip.fps_den} --output-depth {bits}' + ' ' x265_cmd += '--rd 3 --no-rect --no-amp --rskip 1 --tu-intra-depth 2 --tu-inter-depth 2 --tskip' + ' ' x265_cmd += '--merange 36 --weightb' + ' ' x265_cmd += '--no-strong-intra-smoothing' + ' ' x265_cmd += '--psy-rd 1.85 --psy-rdoq 0.8 --no-open-gop --keyint 240 --min-keyint 23 --scenecut 45 --rc-lookahead 60 --bframes 10' + ' ' x265_cmd += '--crf 16 --aq-mode 3 --aq-strength 0.85 --qcomp 0.75' + ' ' x265_cmd += '--deblock=-1:-1 --no-sao --no-sao-non-deblock' + ' ' x265_cmd += f'--sar 1 --range limited --colorprim 1 --transfer 1 --colormatrix 1 --min-luma {str(16<<(bits - 8))} --max-luma {str(235<<(bits - 8))}'# + ' ' print("Encoder command: ", " ".join(shlex.split(x265_cmd)), "\n") process = subprocess.Popen(shlex.split(x265_cmd), stdin=subprocess.PIPE) clip.output(process.stdin, y4m=True, progress_update=lambda value, endvalue: print(f"\rVapourSynth: {value}/{endvalue} ~ {100 * value // endvalue}% || Encoder: ", end="")) process.communicate() print('\n\n\nAudio extraction') eac3to_args = ['eac3to', JPBD.src, '2:', JPBD.a_src, '-log=NUL'] subprocess.run(eac3to_args, text=True, check=True, encoding='utf-8') print('\n\n\nAudio cutting') eztrim(JPBD.src_clip, (JPBD.frame_start, JPBD.frame_end), JPBD.a_src, JPBD.a_src_cut.format(1)) print('\n\n\nAudio encoding') qaac_args = ['qaac', JPBD.a_src_cut.format(1), '-V', '127', '--no-delay', '-o', JPBD.a_enc_cut.format(1)] subprocess.run(qaac_args, text=True, check=True, encoding='utf-8') ffprobe_args = ['ffprobe', '-loglevel', 'quiet', '-show_entries', 'format_tags=encoder', '-print_format', 'default=nokey=1:noprint_wrappers=1', JPBD.a_enc_cut.format(1)] encoder_name = subprocess.check_output(ffprobe_args, shell=True, encoding='utf-8') f = open("tags_aac.xml", 'w') f.writelines(['<?xml version="1.0"?>', '<Tags>', '<Tag>', '<Targets>', '</Targets>', '<Simple>', '<Name>ENCODER</Name>', f'<String>{encoder_name}</String>', '</Simple>', '</Tag>', '</Tags>']) f.close() print('\nFinal muxing') mkv_args = ['mkvmerge', '-o', JPBD.output_final, '--track-name', '0:HEVC BDRip by Vardë@Natsumi-no-Sekai', '--language', '0:jpn', JPBD.output, '--tags', '0:tags_aac.xml', '--track-name', '0:AAC 2.0', '--language', '0:jpn', JPBD.a_enc_cut.format(1), '--chapter-language', 'fr', '--chapters', JPBD.chapter] subprocess.run(mkv_args, text=True, check=True, encoding='utf-8') # Clean up files = [JPBD.a_src, JPBD.a_src_cut.format(1), JPBD.a_enc_cut.format(1), 'tags_aac.xml'] for file in files: if os.path.exists(file): os.remove(file)
def do_encode(clip: vs.VideoNode)-> None: """Compression with x265""" print('\n\n\nVideo encoding') if not os.path.exists(JPBD_NCOP.output): ffv1_args = [ 'ffmpeg', '-i', '-', '-vcodec', 'ffv1', '-coder', '1', '-context', '0', '-g', '1', '-level', '3', '-threads', '8', '-slices', '24', '-slicecrc', '1', "_assets/" + JPBD_NCOP.name + "_lossless.mkv" ] print("Encoder command: ", " ".join(ffv1_args), "\n") process = subprocess.Popen(ffv1_args, stdin=subprocess.PIPE) clip.output(process.stdin, y4m=True, progress_update=lambda value, endvalue: print(f"\rVapourSynth: {value}/{endvalue} ~ {100 * value // endvalue}% || Encoder: ", end="")) process.communicate()
def do_encode(clip: vs.VideoNode)-> None: """Compression with x264""" print('\n\n\nVideo encoding') x265_args = [ X265, "--y4m", "--frames", f"{clip.num_frames}", "--sar", "1", "--output-depth", "10", "--colormatrix", "bt709", "--colorprim", "bt709", "--transfer", "bt709", "--range", "limited", "--min-luma", str(16<<2), "--max-luma", str(235<<2), "--fps", f"{clip.fps_num}/{clip.fps_den}", "-o", JPBD.output, "-", "--frame-threads", "16", "--no-sao", "--fades", "--preset", "slower", "--crf", "14.5", "--qcomp", "0.72", "--bframes", "16", "--psy-rd", "2.0", "--psy-rdoq", "1.0", "--deblock", "-1:-1", "--rc-lookahead", "96", "--min-keyint", "23", "--keyint", "360", "--aq-mode", "3", "--aq-strength", "1.0" ] print("Encoder command: ", " ".join(x265_args), "\n") process = subprocess.Popen(x265_args, stdin=subprocess.PIPE) clip.output(process.stdin, y4m=True, progress_update=lambda value, endvalue: print(f"\rVapourSynth: {value}/{endvalue} ~ {100 * value // endvalue}% || Encoder: ", end="")) process.communicate() print('\n\n\nAudio extraction') mka = MKVFile() mka.add_track(MKVTrack(JPBD.src, 1)) mka.mux(JPBD.a_src) print('\n\n\nAudio cutting') eztrim(JPBD.src_clip, (JPBD.frame_start, JPBD.frame_end), JPBD.a_src, mkvextract_path='mkvextract') print('\n\n\nAudio encoding') qaac_args = ['qaac64', JPBD.a_src_cut.format(1), '-V', '127', '--no-delay', '-o', JPBD.a_enc_cut.format(1)] subprocess.run(qaac_args, text=True, check=True, encoding='utf-8') print('\nFinal muxing') mkv = MKVFile() mkv.add_track(MKVTrack(JPBD.output, language='jpn', default_track=True)) mkv.add_track(MKVTrack(JPBD.a_enc_cut.format(1), language='jpn', default_track=True)) mkv.chapters(JPBD.chapter, 'jpn') mkv.mux(JPBD.output_final)
def do_encode(clip: vs.VideoNode) -> None: """Compression with x265""" print('\n\n\nVideo encoding') x265_args = [ X265, "--y4m", "--frames", f"{clip.num_frames}", "--sar", "1", "--output-depth", "10", "--colormatrix", "bt709", "--colorprim", "bt709", "--transfer", "bt709", "--range", "limited", "--min-luma", str(16 << 2), "--max-luma", str(235 << 2), "--fps", f"{clip.fps_num}/{clip.fps_den}", "-o", JPBD.output, "-", "--frame-threads", "16", "--no-sao", "--fades", "--preset", "slower", "--crf", "15", "--qcomp", "0.70", "--bframes", "16", "--psy-rd", "2.0", "--psy-rdoq", "1.0", "--deblock", "-1:-1", "--rc-lookahead", "72", "--min-keyint", "23", "--keyint", "240", "--aq-mode", "3", "--aq-strength", "1.0" ] print("Encoder command: ", " ".join(x265_args), "\n") process = subprocess.Popen(x265_args, stdin=subprocess.PIPE) clip.output( process.stdin, y4m=True, progress_update=lambda value, endvalue: print( f"\rVapourSynth: {value}/{endvalue} ~ {100 * value // endvalue}% || Encoder: ", end="")) process.communicate()
def do_encode(clip: vs.VideoNode) -> None: """Compression with x26X""" if not os.path.isfile(JPBD.output): print('\n\n\nVideo encoding') bits = clip.format.bits_per_sample x265_cmd = f'x265 -o {JPBD.output} - --y4m' + ' ' x265_cmd += f'--csv {JPBD.name}_log_x265.csv --csv-log-level 2' + ' ' x265_cmd += '--preset veryslow' + ' ' x265_cmd += f'--frames {clip.num_frames} --fps {clip.fps_num}/{clip.fps_den} --output-depth {bits}' + ' ' x265_cmd += '--rd 3 --rskip 0' + ' ' x265_cmd += '--subme 5' + ' ' x265_cmd += '--no-strong-intra-smoothing' + ' ' x265_cmd += '--psy-rd 2.15 --psy-rdoq 2.5 --no-open-gop --keyint 240 --min-keyint 24 --scenecut 40 --bframes 16' + ' ' x265_cmd += '--crf 15.75 --aq-mode 3 --aq-strength 0.85 --no-cutree --cbqpoffs -2 --crqpoffs -2 --qcomp 0.7' + ' ' x265_cmd += '--deblock=-2:-2 --no-sao --no-sao-non-deblock' + ' ' x265_cmd += '--zones ' for i, (cred_s, cred_e) in enumerate(CREDITS): x265_cmd += f'{cred_s},{cred_e},b=0.65' if i != len(CREDITS) - 1: x265_cmd += '/' x265_cmd += ' ' x265_cmd += f'--sar 1 --range limited --colorprim 1 --transfer 1 --colormatrix 1 --min-luma {str(16<<(bits - 8))} --max-luma {str(235<<(bits - 8))}' # + ' ' print("Encoder command: ", " ".join(shlex.split(x265_cmd)), "\n") process = subprocess.Popen(shlex.split(x265_cmd), stdin=subprocess.PIPE) clip.output( process.stdin, y4m=True, progress_update=lambda value, endvalue: print( f"\rVapourSynth: {value}/{endvalue} ~ {100 * value // endvalue}% || Encoder: ", end="")) process.communicate() if not os.path.exists(JPBD.a_src.format(1)): print('\n\n\nAudio extraction') eac3to_args = [ 'eac3to', JPBD.src, '2:', JPBD.a_src.format(1), '-log=NUL' ] subprocess.run(eac3to_args, text=True, check=True, encoding='utf-8') if not os.path.exists(JPBD.a_src_cut.format(1)): print('\n\n\nAudio cutting') eztrim(JPBD.src_clip, (JPBD.frame_start, JPBD.frame_end), JPBD.a_src.format(1), JPBD.a_src_cut.format(1)) if not os.path.exists(JPBD.a_enc_cut.format(1)): print('\n\n\nAudio encoding') qaac_args = [ 'qaac', JPBD.a_src_cut.format(1), '-V', '127', '--no-delay', '-o', JPBD.a_enc_cut.format(1) ] subprocess.run(qaac_args, text=True, check=True, encoding='utf-8') if not os.path.isfile('tags_aac_1.xml'): ffprobe_args = [ 'ffprobe', '-loglevel', 'quiet', '-show_entries', 'format_tags=encoder', '-print_format', 'default=nokey=1:noprint_wrappers=1', JPBD.a_enc_cut.format(1) ] encoder_name = subprocess.check_output(ffprobe_args, shell=True, encoding='utf-8') f = open("tags_aac.xml", 'w') f.writelines([ '<?xml version="1.0"?>', '<Tags>', '<Tag>', '<Targets>', '</Targets>', '<Simple>', '<Name>ENCODER</Name>', f'<String>{encoder_name}</String>', '</Simple>', '</Tag>', '</Tags>' ]) f.close() if not os.path.exists(JPBD.output_final): print('\nFinal muxing') mkv_args = [ 'mkvmerge', '-o', JPBD.output_final, '--track-name', '0:HEVC BDRip by Vardë@Raws-Maji', '--language', '0:jpn', JPBD.output, '--tags', '0:tags_aac.xml', '--track-name', '0:AAC 2.0', '--language', '0:jpn', JPBD.a_enc_cut.format(1), '--chapter-language', 'jpn', '--chapters', JPBD.chapter ] print(*mkv_args) subprocess.run(mkv_args, text=True, check=True, encoding='utf-8') # Clean up files = [ JPBD.a_src.format(1), JPBD.a_src_cut.format(1), JPBD.a_enc_cut.format(1), 'tags_aac_1.xml' ] for file in files: if os.path.exists(file): os.remove(file)