diff --git a/config_generator.py b/config_generator.py index 2b217df..ebedad3 100644 --- a/config_generator.py +++ b/config_generator.py @@ -19,6 +19,7 @@ def enroll_settings(): settings = {} settings['waifu2x_path'] = Avalon.gets('waifu2x-caffe-cui.exe path: ') settings['ffmpeg_path'] = Avalon.gets('ffmpeg binaries directory: ') + settings['ffmpeg_arguments'] = Avalon.gets('Extra arguments passed to ffmpeg: ') return settings diff --git a/ffmpeg.py b/ffmpeg.py index a7730a3..778a1a1 100755 --- a/ffmpeg.py +++ b/ffmpeg.py @@ -22,9 +22,10 @@ class Ffmpeg: and inserting audio tracks to videos. """ - def __init__(self, ffmpeg_path, outfile): - self.ffmpeg_path = ffmpeg_path + def __init__(self, ffmpeg_path, outfile, ffmpeg_arguments): + self.ffmpeg_path = '{}ffmpeg.exe'.format(ffmpeg_path) self.outfile = outfile + self.ffmpeg_arguments = ffmpeg_arguments def extract_frames(self, videoin, outpath): """Extract every frame from original videos @@ -36,7 +37,8 @@ class Ffmpeg: videoin {string} -- input video path outpath {string} -- video output folder """ - execute = "\"{}\" -i \"{}\" {}\\extracted_%0d.png -y".format(self.ffmpeg_path, videoin, outpath) + execute = '\"{}\" -i \"{}\" {}\\extracted_%0d.png -y {}'.format( + self.ffmpeg_path, videoin, outpath, self.ffmpeg_arguments) print(execute) subprocess.call(execute) @@ -50,7 +52,8 @@ class Ffmpeg: videoin {string} -- input video path outpath {string} -- video output folder """ - execute = "\"{}\" -i \"{}\" -vn -acodec copy {}\\output-audio.aac -y".format(self.ffmpeg_path, videoin, outpath) + execute = '\"{}\" -i \"{}\" -vn -acodec copy {}\\output-audio.aac -y {}'.format( + self.ffmpeg_path, videoin, outpath, self.ffmpeg_arguments) print(execute) subprocess.call(execute) @@ -65,8 +68,8 @@ class Ffmpeg: resolution {string} -- target video resolution upscaled {string} -- source images folder """ - execute = "\"{}\" -r {} -f image2 -s {} -i {}\\extracted_%d.png -vcodec libx264 -crf 25 -pix_fmt yuv420p {}\\no_audio.mp4 -y".format( - self.ffmpeg_path, framerate, resolution, upscaled, upscaled) + execute = '\"{}\" -r {} -f image2 -s {} -i {}\\extracted_%d.png -vcodec libx264 -crf 25 -pix_fmt yuv420p {}\\no_audio.mp4 -y {}'.format( + self.ffmpeg_path, framerate, resolution, upscaled, upscaled, self.ffmpeg_arguments) print(execute) subprocess.call(execute) @@ -79,6 +82,7 @@ class Ffmpeg: Arguments: upscaled {string} -- upscaled image folder """ - execute = "\"{}\" -i {}\\no_audio.mp4 -i {}\\output-audio.aac -shortest -codec copy {} -y".format(self.ffmpeg_path, upscaled, upscaled, self.outfile) + execute = '\"{}\" -i {}\\no_audio.mp4 -i {}\\output-audio.aac -shortest -codec copy {} -y {}'.format( + self.ffmpeg_path, upscaled, upscaled, self.outfile, self.ffmpeg_arguments) print(execute) subprocess.call(execute) diff --git a/video2x.py b/video2x.py index 2f4a51a..6ae8a4f 100755 --- a/video2x.py +++ b/video2x.py @@ -107,7 +107,7 @@ def get_video_info(): dictionary -- original video information """ json_str = subprocess.check_output( - '{} -v quiet -print_format json -show_format -show_streams \"{}\"'.format('\"' + ffmpeg_path + 'ffprobe.exe\"', args.video)) + '\"{}ffprobe.exe\" -v quiet -print_format json -show_format -show_streams \"{}\"'.format(ffmpeg_path, args.video)) return json.loads(json_str.decode('utf-8')) @@ -199,7 +199,7 @@ def video2x(): method = 'cudnn' # Initialize objects for ffmpeg and waifu2x-caffe - fm = Ffmpeg('\"' + ffmpeg_path + 'ffmpeg.exe\"', args.output) + fm = Ffmpeg(ffmpeg_path, args.output, ffmpeg_arguments) w2 = Waifu2x(waifu2x_path, method, args.model_type) # Clear and create directories @@ -286,7 +286,12 @@ args.output = os.path.abspath(args.output) config = read_config() waifu2x_path = config['waifu2x_path'] ffmpeg_path = config['ffmpeg_path'] +ffmpeg_arguments = config['ffmpeg_arguments'] +# Add a forward slash to directory if not present +# otherwise there will be a format error +if ffmpeg_path[-1] != '/' and ffmpeg_path[-1] != '\\': + ffmpeg_path = '{}/'.format(ffmpeg_path) # Check if FFMPEG and waifu2x are present if not os.path.isdir(ffmpeg_path):