#NEWLINE# def generate_video( source , outname , settings , options = None ) : #NEWLINE# #INDENT# 'Video processor.\n\n    :param source: path to a video\n    :param outname: path to the generated video\n    :param settings: settings dict\n    :param options: array of options passed to ffmpeg\n\n    ' #NEWLINE# logger = logging . getLogger ( __name__ ) #NEWLINE# ( w_src , h_src ) = video_size ( source ) #NEWLINE# ( w_dst , h_dst ) = settings [ 'video_size' ] #NEWLINE# logger . debug ( 'Video size: %i, %i -> %i, %i' , w_src , h_src , w_dst , h_dst ) #NEWLINE# ( base , src_ext ) = splitext ( source ) #NEWLINE# ( base , dst_ext ) = splitext ( outname ) #NEWLINE# if ( ( dst_ext == src_ext ) and ( h_src <= w_dst ) and ( h_src <= h_dst ) ) : #NEWLINE# #INDENT# logger . debug ( 'Video is smaller than the max size, copying it instead' ) #NEWLINE# shutil . copy ( source , outname ) #NEWLINE# return #NEWLINE# #UNINDENT# if ( ( h_dst * w_src ) < ( h_src * w_dst ) ) : #NEWLINE# #INDENT# resize_opt = [ '-vf' , ( 'scale=trunc(oh*a/2)*2:%i' % h_dst ) ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# resize_opt = [ '-vf' , ( 'scale=%i:trunc(ow/a/2)*2' % w_dst ) ] #NEWLINE# #UNINDENT# if ( ( w_src <= w_dst ) and ( h_src <= h_dst ) ) : #NEWLINE# #INDENT# resize_opt = [ ] #NEWLINE# #UNINDENT# cmd = [ 'ffmpeg' , '-i' , source , '-y' ] #NEWLINE# if ( options is not None ) : #NEWLINE# #INDENT# cmd += options #NEWLINE# #UNINDENT# cmd += ( resize_opt + [ outname ] ) #NEWLINE# logger . debug ( 'Processing video: %s' , ' ' . join ( cmd ) ) #NEWLINE# check_subprocess ( cmd , source , outname )