From cf81c63a70ce2a2cc7fbdea846fb293b678145b0 Mon Sep 17 00:00:00 2001 From: Erich Seifert Date: Sun, 11 Apr 2021 15:49:41 +0200 Subject: [PATCH] ffmpeg.FFmpegProcessor.resize() tries to preserve the quality of the input data. --- madam/ffmpeg.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/madam/ffmpeg.py b/madam/ffmpeg.py index d6d97d6..4f49119 100644 --- a/madam/ffmpeg.py +++ b/madam/ffmpeg.py @@ -499,11 +499,14 @@ def resize(self, asset: Asset, width: int, height: int) -> Asset: shutil.copyfileobj(asset.essence, temp_in) temp_in.flush() - command = ['ffmpeg', '-loglevel', 'error', - '-f', encoder_name, '-i', ctx.input_path, - '-filter:v', f'scale={width:d}:{height:d}', - '-threads', str(self.__threads), - '-f', encoder_name, '-y', ctx.output_path] + command = [ + 'ffmpeg', '-loglevel', 'error', + '-f', encoder_name, '-i', ctx.input_path, + '-filter:v', f'scale={width:d}:{height:d}', + '-qscale', '0', + '-threads', str(self.__threads), + '-f', encoder_name, '-y', ctx.output_path + ] try: subprocess.run(command, stderr=subprocess.PIPE, check=True) @@ -511,9 +514,11 @@ def resize(self, asset: Asset, width: int, height: int) -> Asset: error_message = ffmpeg_error.stderr.decode('utf-8') raise OperatorError(f'Could not resize asset: {error_message}') - metadata = _combine_metadata(asset, - 'mime_type', 'duration', 'video', 'audio', 'subtitle', - width=width, height=height) + metadata = _combine_metadata( + asset, + 'mime_type', 'duration', 'video', 'audio', 'subtitle', + width=width, height=height + ) return Asset(essence=result, **metadata)