tmpdir = tempfile.mkdtemp() log.info('Temp dir ' + tmpdir) log.info('PNG -> MPG') outfile_start = tmpdir + '/' + START_IMG + OUT_EXT1 cmd = 'ffmpeg -loop 1 -f image2 -i ' + START_IMG + ' -t 5 -f lavfi -i aevalsrc=0 -vf "fade=in:0:25,fade=out:110:25" -r 29.97 -qscale:v 1 ' + outfile_start log.info(cmd) os.system(cmd) log.info('MP4s -> MPGs') mpg_file_list = list() mpg_file_list.append(outfile_start) for infile in os.listdir(indir): if infile.upper().endswith(INPUT_EXT1): outfile = tmpdir + '/' + infile + OUT_EXT1 frames = mediainfo.get_frames(infile) start_end_frame = frames - FADE_FRAMES cmd = 'ffmpeg -i ' + infile + ' -qscale:v 1 -vf "fade=in:0:' + str( FADE_FRAMES) + ',fade=out:' + str(start_end_frame) + ':' + str( FADE_FRAMES) + '" ' + outfile log.info(cmd) os.system(cmd) mpg_file_list.append(outfile) log.info('MPGs -> MP4') mpg_files_str = '' for mpg_file in mpg_file_list: mpg_files_str = mpg_files_str + mpg_file + '|' cmd = 'ffmpeg -i concat:"' + mpg_files_str + '" -c:v libx264 -preset slow -crf ' + str( VIDEO_QUALITY) + ' -c:a aac -strict -2 ' + MP4_RESULT_FILE
tmpdir = tempfile.mkdtemp() log.info('Temp dir ' + tmpdir + ' is created.') log.info('PNG > MPG') outfile_start = tmpdir + '/' + START_IMG + OUT_EXT1 cmd = 'ffmpeg -loop 1 -f image2 -i ' + START_IMG + ' -t 5 -f lavfi -i aevalsrc=0 -vf "fade=in:0:25,fade=out:110:25" -r 29.97 -qscale:v 1 ' + outfile_start log.info(cmd) os.system(cmd) log.info('MOVs > MPGs') fps = 0 total_frames = mediainfo.get_frames(outfile_start) mpg_file_list = list() mpg_file_list.append(outfile_start) for infile in os.listdir(indir): if infile.upper().endswith(INPUT_EXT1): outfile = tmpdir + '/' + infile + OUT_EXT1 frames = mediainfo.get_frames(infile) total_frames = total_frames + frames if fps == 0: fps = mediainfo.get_fps(infile) start_end_frame = frames - FADE_FRAMES cmd = 'ffmpeg -i ' + infile + ' -qscale:v 1 -vf "fade=in:0:' + str(FADE_FRAMES) + ',fade=out:' + str(start_end_frame) + ':' + str(FADE_FRAMES) + '" ' + outfile log.info(cmd)
#!/usr/bin/python import sys import mediainfo infile = sys.argv[1] print 'file', infile frames = mediainfo.get_frames(infile) print 'frames', frames fps = mediainfo.get_fps(infile) print 'fps', fps lenght = mediainfo.get_length_str(frames, fps) print 'lenght', lenght #frames 2817.18 #time 00:01:34
lfh.setFormatter(formatter) log.addHandler(lfh) tmpdir = tempfile.mkdtemp() log.info('Temp dir ' + tmpdir + ' is created.') log.info('PNG > MPG') outfile_start = tmpdir + '/' + START_IMG + OUT_EXT1 cmd = 'ffmpeg -loop 1 -f image2 -i ' + START_IMG + ' -t 5 -f lavfi -i aevalsrc=0 -vf "fade=in:0:25,fade=out:110:25" -r 29.97 -qscale:v 1 ' + outfile_start log.info(cmd) os.system(cmd) log.info('MOVs > MPGs') fps = 0 total_frames = mediainfo.get_frames(outfile_start) mpg_file_list = list() mpg_file_list.append(outfile_start) for infile in os.listdir(indir): if infile.upper().endswith(INPUT_EXT1): outfile = tmpdir + '/' + infile + OUT_EXT1 frames = mediainfo.get_frames(infile) total_frames = total_frames + frames if fps == 0: fps = mediainfo.get_fps(infile) start_end_frame = frames - FADE_FRAMES cmd = 'ffmpeg -i ' + infile + ' -qscale:v 1 -vf "fade=in:0:' + str( FADE_FRAMES) + ',fade=out:' + str(start_end_frame) + ':' + str(