ffmpeg now uses the veryslow libx264 preset to give better compression (the videos are so short it doesn't make much difference to the time) and when mixing sound effects the output volume from amix is doubled to compensate for the volume halving as the sound effects are mixed

This commit is contained in:
WORD559 committed 2018-07-06 01:22:48 +01:00
1 parent 97c3f67d14
commit 9c1ffcd290
1 file changed
+10 -4
+10 -4
View File
@@ -868,11 +868,11 @@ if __name__ == '__main__':
# Now to make the video in ffmpeg # Now to make the video in ffmpeg
print "Exporting video with 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","-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),"-i","{path}/sounds/BGM.wav".format(path=tempdir),"-c:v","libx264","-preset","veryslow","-c:a","pcm_s16le","-shortest","-y",out_file]
if not os.path.isfile(tempdir+"/sounds/BGM.wav"): if not os.path.isfile(tempdir+"/sounds/BGM.wav"):
print "No background music. Adding silent track..." print "No background music. Adding silent track..."
#has_bgm = False #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","-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","libx264","-preset","veryslow","-c:a","pcm_s16le","-shortest","-y",out_file]
else: else:
#has_bgm = True #has_bgm = True
pass pass
@@ -900,8 +900,9 @@ if __name__ == '__main__':
# The second concatenates the silent track and the sound effect, producing a sound file that can be mixed into the video's audio track so that it plays at the correct time. # The second concatenates the silent track and the sound effect, producing a sound file that can be mixed into the video's audio track so that it plays at the correct time.
SFX_command = ["ffmpeg","-i","{path}/silence.wav","-i","{path}/sounds/{sfx}.wav","-filter_complex","[0:a] [1:a] concat=n=2:v=0:a=1","-y","{path}/sfx.wav"] SFX_command = ["ffmpeg","-i","{path}/silence.wav","-i","{path}/sounds/{sfx}.wav","-filter_complex","[0:a] [1:a] concat=n=2:v=0:a=1","-y","{path}/sfx.wav"]
# The third mixes the silence+sound effect into the video file # The third mixes the silence+sound effect into the video file
merge_command = ["ffmpeg","-i",out_file,"-i","{path}/sfx.wav","-filter_complex","[0:a][1:a] amix=inputs=2:duration=longest","-c:a","pcm_s16le","-c:v","copy","-y","{path}/temp_out.mkv"] merge_command = ["ffmpeg","-i",out_file,"-i","{path}/sfx.wav","-filter_complex","[0:a][1:a] amix=inputs=2:duration=longest:dropout_transition={video_length},volume=2","-c:a","pcm_s16le","-c:v","copy","-max_muxing_queue_size","1024","-y","{path}/temp_out.mkv"]
## normalise_command = ["ffmpeg","-i",out_file,"-filter_complex","dynaudnorm","{path}/temp_out.mkv".format(path=tempdir)]
## for sfx in ["SFX1","SFX2","SFX3"]: ## for sfx in ["SFX1","SFX2","SFX3"]:
## if not os.path.isfile("{path}/sounds/{sfx}.wav".format(path=tempdir,sfx=sfx)): ## if not os.path.isfile("{path}/sounds/{sfx}.wav".format(path=tempdir,sfx=sfx)):
## print sfx+" does not exist." ## print sfx+" does not exist."
@@ -926,12 +927,17 @@ if __name__ == '__main__':
with open(os.devnull,"w") as null: with open(os.devnull,"w") as null:
subprocess.call([i.format(path=tempdir,sfx=sfx,length=length) for i in silence_command],stdout=null,stderr=null) subprocess.call([i.format(path=tempdir,sfx=sfx,length=length) for i in silence_command],stdout=null,stderr=null)
subprocess.call([i.format(path=tempdir,sfx=sfx) for i in SFX_command],stdout=null,stderr=null) subprocess.call([i.format(path=tempdir,sfx=sfx) for i in SFX_command],stdout=null,stderr=null)
subprocess.call([i.format(path=tempdir) for i in merge_command],stdout=null,stderr=null) subprocess.call([i.format(path=tempdir,video_length=fps*len(sfx_usage)) for i in merge_command],stdout=null,stderr=null)
os.remove(out_file) os.remove(out_file)
shutil.move("{path}/temp_out.mkv".format(path=tempdir),out_file) shutil.move("{path}/temp_out.mkv".format(path=tempdir),out_file)
print "Done!" print "Done!"
time.sleep(sleep_time) # optional sleep -- in case you want to slow things down for HDD strain or reliability or something time.sleep(sleep_time) # optional sleep -- in case you want to slow things down for HDD strain or reliability or something
## subprocess.call(normalise_command)
## os.remove(out_file)
## shutil.move("{path}/temp_out.mkv".format(path=tempdir),out_file)
# Remove the temp dir and all files in it # Remove the temp dir and all files in it
print "Removing temporary directory..." print "Removing temporary directory..."
shutil.rmtree(tempdir) shutil.rmtree(tempdir)