From 0fd8b5210c760904344c00035158f0d6459db36f Mon Sep 17 00:00:00 2001 From: RealStickman Date: Fri, 11 Nov 2022 09:32:50 +0100 Subject: [PATCH] Wrap ffmpeg calls in "try/except" blocks. Log errors --- encode_single_video.py | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/encode_single_video.py b/encode_single_video.py index ce8f5c2..b65bc74 100755 --- a/encode_single_video.py +++ b/encode_single_video.py @@ -367,17 +367,48 @@ def main(inputfile: str, outputpath: str = "encodes", keepencodes: bool = False) # execute previously defined encoding settings starttime = now() - ff.run() + try: + ff.run() + except ffmpy.FFRuntimeError: + with open("error.log", "a") as file: + file.write( + "FFMPEG error. Failed encoding", + inputfile, + "to", + outputfile, + ) + endtime = now() difftime = int(endtime - starttime) outputfilesize = os.path.getsize(outputfile) / 1024 / 1024 - vmaf = score_vmaf(outputfile=outputfile, inputfile=inputfile) + try: + vmaf = score_vmaf(outputfile=outputfile, inputfile=inputfile) + except ffmpy.FFRuntimeError: + with open("error.log", "a") as file: + file.write( + "FFMPEG error. To calculate VMAF score of", + outputfile, + ) - ssim = score_ssim(outputfile=outputfile, inputfile=inputfile) + try: + ssim = score_ssim(outputfile=outputfile, inputfile=inputfile) + except ffmpy.FFRuntimeError: + with open("error.log", "a") as file: + file.write( + "FFMPEG error. To calculate SSIM score of", + outputfile, + ) - mse = score_psnr(outputfile=outputfile, inputfile=inputfile) + try: + mse = score_psnr(outputfile=outputfile, inputfile=inputfile) + except ffmpy.FFRuntimeError: + with open("error.log", "a") as file: + file.write( + "FFMPEG error. To calculate MSE score of", + outputfile, + ) write_line( datafile=datafile,