def ffmpeg_queryCodecs(): video_codecs = {} audio_codecs = {} status, (stdout, stderr) = mvexportutils.run(['ffmpeg', '-formats']) lines = stdout.splitlines() try: codec_start = lines.find('Codecs:') except: # Probably failed due to a newer version of ffmpeg. status, (stdout, stderr) = mvexportutils.run(['ffmpeg', '-codecs']) lines = stdout.splitlines() codec_start = 0 for line in lines[codec_start + 1:]: if len(line) == 0: break space_index = line.rfind(' ') if space_index >= 0: codec_flags = line[1:space_index] # We may not have enough characters, in which # case we skip this. if len(codec_flags) > 3: if codec_flags[2] == 'V': video_codecs[line[space_index + 1:]] = codec_flags elif codec_flags[2] == 'A': audio_codecs[line[space_index + 1:]] = codec_flags return video_codecs, audio_codecs
def encode(kwargs): args = [] args.append('mencoder') args.append('mf://' + ','.join(kwargs['imagefiles'])) # mf_filetype will be either jpg or png mf_filetype = (os.path.splitext(kwargs['imagefiles'][0])[1])[1:] mf_opts = "w=%d:h=%d:fps=%d:type=%s" % (kwargs['xres'], kwargs['yres'], kwargs['framerate'], mf_filetype) args.extend(['-mf', mf_opts]) audio_preset = {} audio_preset['aac'] = ['-oac', 'faac', '-faacopts', 'mpeg=4:raw:br=128'] audio_preset['mp3'] = ['-oac', 'mp3lame', '-lameopts', 'q=0:aq=2:vbr=2'] #audio_preset['mp3'] = ['-oac', 'mp3lame', '-lameopts', 'cbr:br=128'] video_preset = {} video_preset['mp4:h264'] = [ '-ovc', 'lavc', '-lavcopts', 'vcodec=libx264:vbitrate=1200:vglobal=1:aglobal=1' ] # 'vcodec=libx264:vbitrate=1200:mbd=2:cmp=2:subcmp=2:trell=yres:v4mv=yes' # ':aic=2:vglobal=1:aglobal=1'] video_preset['mp4:mpeg4'] = [ '-ovc', 'lavc', '-lavcopts', 'vcodec=mpeg4:vbitrate=5000:mbd=2:cmp=2:subcmp=2:trell=yres:v4mv=yes' ':aic=2:vglobal=1:aglobal=1' ":keyint=%g" % kwargs['framerate'] ] video_preset['msmpeg4v2'] = [ '-ovc', 'lavc', '-lavcopts', 'vcodec=msmpeg4v2:vhq:vbitrate=5000' ":keyint=%g" % kwargs['framerate'] ] format_args = {} format_args['mp4'] = ['-of', 'lavf', '-lavfopts', 'format=mp4'] # 'format=mp4:i_certify_that_my_video_stream_does_not_use_b_frames'] # lavc_opts = "vcodec=mpeg4:vbitrate=10000:keyint=%g" % kwargs['framerate'] # args.extend(['-ovc', 'lavc', '-lavcopts', lavc_opts]) args.extend(video_preset[kwargs['videopreset']]) if kwargs.has_key('audiofile') and len(kwargs['audiofile']) > 0: args.extend(['-audiofile', kwargs['audiofile']]) if kwargs.has_key('audiocopy') and kwargs['audiocopy']: args.extend(['-oac', 'copy']) else: args.extend(audio_preset[kwargs['audiopreset']]) if format_args.has_key(kwargs['outputformat']): args.extend(format_args[kwargs['outputformat']]) args.extend(['-o', kwargs['outputfile']]) #args.extend(['-endpos', "%g" % mvexportutils.videoDuration(kwargs)]) return mvexportutils.run(args)
def encode(kwargs): fps = 10 max_colors = 64 #YOUR PATH for CACHE pallete CACHE_PALLETE = 'D:/_CACHE/palette.png' #presets if kwargs['videopreset'].find('high') >= 0: fps = kwargs['framerate'] max_colors = 256 if kwargs['videopreset'].find('medium') >= 0: fps = 15 max_colors = 64 if kwargs['videopreset'].find('low') >= 0: fps = 10 max_colors = 32 args = [] args.append('ffmpeg') # Ensure that we don't prompt about overwriting output files. args.append('-y') args.extend(['-i', kwargs['imagefilesstringformat']]) #prepearre palette for gif args_pallete = [] args_pallete.append('ffmpeg') args_pallete.append('-y') args_pallete.extend(['-i', kwargs['imagefilesstringformat']]) args_pallete.extend([ '-vf', 'fps=%g ,scale=320:-1:flags=lanczos,palettegen=stats_mode=diff:max_colors=%s' % (fps, max_colors) ]) args_pallete.extend(['-y', CACHE_PALLETE]) args.extend(['-i', CACHE_PALLETE]) args.extend(['-lavfi', 'fps=%g [x];[x][1:v] paletteuse' % fps]) #print("%s",args_pallete) args.append(kwargs['outputfile']) #print("%s",args) return mvexportutils.run(args)
def encode(kwargs): args = [] args.append('ffmpeg') # Ensure that we don't prompt about overwriting output files. args.append('-y') args.extend(['-r', "%g" % kwargs['framerate']]) args.extend(['-i', kwargs['imagefilesstringformat']]) # args.append('-shortest') # Codec names are different depending on the version of ffmpeg installed # so query them directly from the application. video_codecs, audio_codecs = ffmpeg_queryCodecs() audio_preset = {} if audio_codecs.has_key('libfaac'): audio_preset['aac'] = ['-acodec', 'libfaac'] else: audio_preset['aac'] = ['-acodec', 'aac'] if audio_codecs.has_key('libmp3lame'): audio_preset['mp3'] = ['-acodec', 'libmp3lame', '-ab', '192k'] else: audio_preset['mp3'] = ['-acodec', 'mp3', '-ab', '192k'] if kwargs.has_key('audiofile') and len(kwargs['audiofile']) > 0: args.extend(['-i', kwargs['audiofile']]) if kwargs.has_key('audiocopy') and kwargs['audiocopy']: args.extend(['-acodec', 'copy']) else: args.extend(audio_preset[kwargs['audiopreset']]) # Restrict the duration to that of the video, in seconds, otherwise a # longer audio track will specified value in seconds, otherwise # a long args.extend(['-t', "%g" % mvexportutils.videoDuration(kwargs)]) if kwargs['videopreset'].find('hq') >= 0: args.extend(['-qscale', '1']) # highest quality VBR else: args.extend(['-qscale', '4']) args.append(kwargs['outputfile']) return mvexportutils.run(args)
def isSupported(): try: status, (stdout, stderr) = mvexportutils.run(['ffmpeg']) except: return False return True
def isSupported(): try: mvexportutils.run(['mencoder']) except: return False return True