From 6f1b5cc2572eb138222aef4632a19ba5274fc836 Mon Sep 17 00:00:00 2001 From: Joshua Barrass Date: Fri, 26 Aug 2022 01:55:19 +0100 Subject: [PATCH 1/4] Reduce transcoding in flipnote export --- PPM.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/PPM.py b/PPM.py index 849fda5..2226487 100755 --- a/PPM.py +++ b/PPM.py @@ -671,7 +671,8 @@ if __name__ == '__main__': print " -f: Extracts the frame(s) to " print " -s: Dumps the sound files to the folder " print " -S: Same as mode -s, but will also dump the raw sound data files" - print " -e: Exports the flipnote to an MKV" + print " -e: Exports the flipnote to an MKV with minimal transcoding" + print " -E: Same as -e, but will encode the video as lossless H.265" print " -m: Prints out the metadata. Can also write it to which also" print " supports unicode charactes." print " -oa: Seach a directory for an original author that matches the RegEx" @@ -822,7 +823,7 @@ if __name__ == '__main__': if regex.match(meta["Original author"]): print filename - elif sys.argv[1] == "-e": + elif sys.argv[1] == "-e" or sys.argv[1] == "-E": if not hasffmpeg: print "Error!\nffmpeg is not installed." sys.exit() @@ -885,14 +886,22 @@ if __name__ == '__main__': # Now to make the video in ffmpeg print "Exporting video with ffmpeg..." - export_command = ["ffmpeg","-framerate",str(fps),"-start_number","1","-i","{path}/frame %03d.png".format(path=tempdir),"-i","{path}/sounds/BGM.wav".format(path=tempdir),"-c:v","libx264","-preset","veryslow","-c:a","pcm_s16le","-t","{dur}".format(dur=duration),"-y",out_file] + export_command = ["ffmpeg","-framerate",str(fps),"-start_number","1","-i","{path}/frame %03d.png".format(path=tempdir),"-i","{path}/sounds/BGM.wav".format(path=tempdir),"-c:v","copy","-c:a","copy","-t","{dur}".format(dur=duration),"-y",out_file] if not os.path.isfile(tempdir+"/sounds/BGM.wav"): print "No background music. Adding silent track..." #has_bgm = False - export_command = ["ffmpeg","-framerate",str(fps),"-start_number","1","-i","{path}/frame %03d.png".format(path=tempdir),"-f","lavfi","-i","anullsrc=r=8192:cl=mono","-c:v","libx264","-preset","veryslow","-c:a","pcm_s16le","-shortest","-y",out_file] + export_command = ["ffmpeg","-framerate",str(fps),"-start_number","1","-i","{path}/frame %03d.png".format(path=tempdir),"-f","lavfi","-i","anullsrc=r=8192:cl=mono","-c:v","copy","-c:a","pcm_s16le","-shortest","-y",out_file] else: #has_bgm = True pass + # use libx265 in lossless mode, rather than MPNG + if sys.argv[1] == "-E": + # insert the necessary arguments into the existing command + codec_index = export_command.index("-c:v") + export_command[codec_index+1] = "libx265" + export_command.insert(codec_index+2, "-x265-params") + export_command.insert(codec_index+3, "crf=0:lossless=1:preset=veryslow:qp=0") + print " ".join(export_command) with open(os.devnull) as null: subprocess.call(export_command,stdout=null,stderr=null) print "Done!" From 3a12e002afd6cd8bf0bd8f45a1901035c0e6aa0a Mon Sep 17 00:00:00 2001 From: Joshua Barrass Date: Fri, 26 Aug 2022 02:13:41 +0100 Subject: [PATCH 2/4] Remove redundant libx265 options --- PPM.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PPM.py b/PPM.py index 2226487..3276fcb 100755 --- a/PPM.py +++ b/PPM.py @@ -900,7 +900,7 @@ if __name__ == '__main__': codec_index = export_command.index("-c:v") export_command[codec_index+1] = "libx265" export_command.insert(codec_index+2, "-x265-params") - export_command.insert(codec_index+3, "crf=0:lossless=1:preset=veryslow:qp=0") + export_command.insert(codec_index+3, "lossless=1:preset=veryslow") print " ".join(export_command) with open(os.devnull) as null: subprocess.call(export_command,stdout=null,stderr=null) From 6cef15827cd1f0a5cb8e28417a5262d2fe00c2eb Mon Sep 17 00:00:00 2001 From: Joshua Barrass Date: Fri, 26 Aug 2022 02:17:11 +0100 Subject: [PATCH 3/4] Properly insert speed preset -- produces better compression --- PPM.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/PPM.py b/PPM.py index 3276fcb..33350bf 100755 --- a/PPM.py +++ b/PPM.py @@ -900,7 +900,9 @@ if __name__ == '__main__': codec_index = export_command.index("-c:v") export_command[codec_index+1] = "libx265" export_command.insert(codec_index+2, "-x265-params") - export_command.insert(codec_index+3, "lossless=1:preset=veryslow") + export_command.insert(codec_index+3, "lossless=1") + export_command.insert(codec_index+2, "-preset") + export_command.insert(codec_index+3, "veryslow") print " ".join(export_command) with open(os.devnull) as null: subprocess.call(export_command,stdout=null,stderr=null) From 39c98ccdb7d82e81a8fb03e17a9018fbb449de90 Mon Sep 17 00:00:00 2001 From: Joshua Barrass Date: Fri, 26 Aug 2022 02:38:55 +0100 Subject: [PATCH 4/4] Spaces -> Tabs to match existing code --- PPM.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/PPM.py b/PPM.py index 33350bf..8f887b2 100755 --- a/PPM.py +++ b/PPM.py @@ -896,14 +896,14 @@ if __name__ == '__main__': pass # use libx265 in lossless mode, rather than MPNG if sys.argv[1] == "-E": - # insert the necessary arguments into the existing command - codec_index = export_command.index("-c:v") - export_command[codec_index+1] = "libx265" - export_command.insert(codec_index+2, "-x265-params") - export_command.insert(codec_index+3, "lossless=1") - export_command.insert(codec_index+2, "-preset") - export_command.insert(codec_index+3, "veryslow") - print " ".join(export_command) + # insert the necessary arguments into the existing command + codec_index = export_command.index("-c:v") + export_command[codec_index+1] = "libx265" + export_command.insert(codec_index+2, "-x265-params") + export_command.insert(codec_index+3, "lossless=1") + export_command.insert(codec_index+2, "-preset") + export_command.insert(codec_index+3, "veryslow") + print " ".join(export_command) with open(os.devnull) as null: subprocess.call(export_command,stdout=null,stderr=null) print "Done!"