Skip to content

Commit

Permalink
ffmpeg.FFmpegProcessor.resize() tries to preserve the quality of the …
Browse files Browse the repository at this point in the history
…input data.
  • Loading branch information
eseifert committed Apr 11, 2021
1 parent 2fcbc97 commit cf81c63
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions madam/ffmpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,21 +499,26 @@ 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)
except subprocess.CalledProcessError as ffmpeg_error:
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)

Expand Down

0 comments on commit cf81c63

Please sign in to comment.