def video_init(opt, path): fps, endtime, height, width = ffmpeg.get_video_infos(path) if opt.fps != 0: fps = opt.fps continue_flag = False imagepaths = [] if os.path.isdir(opt.temp_dir): imagepaths = os.listdir(opt.temp_dir + '/video2image') if imagepaths != []: imagepaths.sort() last_frame = int(imagepaths[-1][7:13]) if (opt.last_time != '00:00:00' and last_frame > fps*(util.stamp2second(opt.last_time)-1)) \ or (opt.last_time == '00:00:00' and last_frame > fps*(endtime-1)): choose = input( 'There is an unfinished video. Continue it? [y/n] ') if choose.lower() == 'yes' or choose.lower() == 'y': continue_flag = True if not continue_flag: print('Step:1/4 -- Convert video to images') util.file_init(opt) ffmpeg.video2voice(path, opt.temp_dir + '/voice_tmp.mp3', opt.start_time, opt.last_time) ffmpeg.video2image( path, opt.temp_dir + '/video2image/output_%06d.' + opt.tempimage_type, fps, opt.start_time, opt.last_time) imagepaths = os.listdir(opt.temp_dir + '/video2image') imagepaths.sort() return fps, imagepaths, height, width
def video_init(opt, path): fps, endtime, height, width = ffmpeg.get_video_infos(path) if opt.fps != 0: fps = opt.fps # resume if os.path.isfile(os.path.join(opt.temp_dir, 'step.json')): step = util.loadjson(os.path.join(opt.temp_dir, 'step.json')) if int(step['step']) >= 1: choose = input('There is an unfinished video. Continue it? [y/n] ') if choose.lower() == 'yes' or choose.lower() == 'y': imagepaths = os.listdir(opt.temp_dir + '/video2image') imagepaths.sort() return fps, imagepaths, height, width print('Step:1/4 -- Convert video to images') util.file_init(opt) ffmpeg.video2voice(path, opt.temp_dir + '/voice_tmp.mp3', opt.start_time, opt.last_time) ffmpeg.video2image( path, opt.temp_dir + '/video2image/output_%06d.' + opt.tempimage_type, fps, opt.start_time, opt.last_time) imagepaths = os.listdir(opt.temp_dir + '/video2image') imagepaths.sort() step = {'step': 2, 'frame': 0} util.savejson(os.path.join(opt.temp_dir, 'step.json'), step) return fps, imagepaths, height, width
import os import sys import traceback from cores import Options, core from util import util from models import loadmodel opt = Options().getparse() util.file_init(opt) def main(): if os.path.isdir(opt.media_path): files = util.Traversal(opt.media_path) else: files = [opt.media_path] if opt.mode == 'add': netS = loadmodel.bisenet(opt, 'roi') for file in files: opt.media_path = file if util.is_img(file): core.addmosaic_img(opt, netS) elif util.is_video(file): core.addmosaic_video(opt, netS) else: print('This type of file is not supported') elif opt.mode == 'clean': netM = loadmodel.bisenet(opt, 'mosaic') if opt.traditional: