@ -849,24 +849,30 @@ class FFmpegThumbnailsConvertorPP(FFmpegPostProcessor):
info [ ' __files_to_move ' ] . pop ( thumbnail_filename ) , ' webp ' )
info [ ' __files_to_move ' ] . pop ( thumbnail_filename ) , ' webp ' )
def convert_thumbnail ( self , thumbnail_filename , ext ) :
def convert_thumbnail ( self , thumbnail_filename , ext ) :
if ext != ' jpg ' :
if ext == ' jpg ' :
raise FFmpegPostProcessorError ( ' Only conversion to jpg is currently supported ' )
format_name = ' JPEG '
opts = [ ' -bsf:v ' , ' mjpeg2jpeg ' ]
elif ext == ' png ' :
format_name = ' PNG '
opts = [ ]
else :
raise FFmpegPostProcessorError ( ' Only conversion to either jpg or png is currently supported ' )
# NB: % is supposed to be escaped with %% but this does not work
# NB: % is supposed to be escaped with %% but this does not work
# for input files so working around with standard substitution
# for input files so working around with standard substitution
escaped_thumbnail_filename = thumbnail_filename . replace ( ' % ' , ' # ' )
escaped_thumbnail_filename = thumbnail_filename . replace ( ' % ' , ' # ' )
os . rename ( encodeFilename ( thumbnail_filename ) , encodeFilename ( escaped_thumbnail_filename ) )
os . rename ( encodeFilename ( thumbnail_filename ) , encodeFilename ( escaped_thumbnail_filename ) )
escaped_thumbnail_jpg_filename = replace_extension ( escaped_thumbnail_filename , ' jpg ' )
escaped_thumbnail_ conv _filename = replace_extension ( escaped_thumbnail_filename , ext )
self . to_screen ( ' Converting thumbnail " %s " to JPEG ' % escaped_thumbnail_filename )
self . to_screen ( ' Converting thumbnail " %s " to %s ' % ( escaped_thumbnail_filename , format_name ) )
self . run_ffmpeg ( escaped_thumbnail_filename , escaped_thumbnail_ jpg_filename, [ ' -bsf:v ' , ' mjpeg2jpeg ' ] )
self . run_ffmpeg ( escaped_thumbnail_filename , escaped_thumbnail_ conv_filename, opts )
thumbnail_ jpg_filename = replace_extension ( thumbnail_filename , ' jpg ' )
thumbnail_ conv_filename = replace_extension ( thumbnail_filename , ext )
# Rename back to unescaped
# Rename back to unescaped
os . rename ( encodeFilename ( escaped_thumbnail_filename ) , encodeFilename ( thumbnail_filename ) )
os . rename ( encodeFilename ( escaped_thumbnail_filename ) , encodeFilename ( thumbnail_filename ) )
os . rename ( encodeFilename ( escaped_thumbnail_ jpg_filename) , encodeFilename ( thumbnail_jpg _filename) )
os . rename ( encodeFilename ( escaped_thumbnail_ conv_filename) , encodeFilename ( thumbnail_conv _filename) )
return thumbnail_ jpg _filename
return thumbnail_ conv _filename
def run ( self , info ) :
def run ( self , info ) :
if self . format != ' jpg ' :
if self . format not in ( ' jpg ' , ' png ' ) :
raise FFmpegPostProcessorError ( ' Only conversion to jpg is currently supported' )
raise FFmpegPostProcessorError ( ' Only conversion to either jpg or pn g is currently supported' )
files_to_delete = [ ]
files_to_delete = [ ]
has_thumbnail = False
has_thumbnail = False