提交 347fb5ca 编写于 作者: H hypox64

Modified file system

上级 33ceac66
......@@ -13,7 +13,7 @@ from options import Options
opt = Options().getparse()
util.init(opt)
util.file_init(opt)
if opt.mode == 'add':
......@@ -29,7 +29,9 @@ if opt.mode == 'add':
fps = ffmpeg.get_video_infos(path)[0]
ffmpeg.video2voice(path,'./tmp/voice_tmp.mp3')
ffmpeg.video2image(path,'./tmp/video2image/output_%05d.'+opt.tempimage_type)
for imagepath in os.listdir('./tmp/video2image'):
imagepaths=os.listdir('./tmp/video2image')
imagepaths.sort()
for imagepath in imagepaths:
imagepath = os.path.join('./tmp/video2image',imagepath)
print('Add Mosaic:',imagepath)
img = cv2.imread(imagepath)
......@@ -90,4 +92,4 @@ elif opt.mode == 'clean':
'./tmp/voice_tmp.mp3',
os.path.join(opt.result_dir,os.path.splitext(os.path.basename(path))[0]+'_CleanMosaic.mp4'))
util.clean_tempfiles()
\ No newline at end of file
util.clean_tempfiles(tmp_init = False)
\ No newline at end of file
......@@ -7,7 +7,8 @@ def video2voice(videopath,voicepath):
os.system('ffmpeg -i '+videopath+' -f mp3 '+voicepath)
def image2video(fps,imagepath,voicepath,videopath):
os.system('ffmpeg -y -r '+str(fps)+' -i '+imagepath+' -vcodec libx264 '+'./tmp/video_tmp.mp4')
#os.system('ffmpeg -y -r '+str(fps)+' -i '+imagepath+' -vcodec libx264 '+'./tmp/video_tmp.mp4')
os.system('ffmpeg -f image2 -i '+imagepath+' -vcodec libx264 -r '+str(fps)+' ./tmp/video_tmp.mp4')
os.system('ffmpeg -i ./tmp/video_tmp.mp4 -i '+voicepath+' -vcodec copy -acodec copy '+videopath)
def get_video_infos(videopath):
......
import os
import shutil
def Traversal(filedir):
file_list=[]
for root,dirs,files in os.walk(filedir):
......@@ -24,21 +24,29 @@ def is_video(path):
return True
else:
return False
def init(opt):
if not os.path.isdir(opt.result_dir):
os.makedirs(opt.result_dir)
print('makedir:',opt.result_dir)
def writelog(path,log):
f = open(path,'a+')
f.write(log+'\n')
def clean_tempfiles():
# def del_all(dir_path):
# files = Traversal(dir_path)
# for file in files:
# os.remove(file)
# os.removedirs(dir_path)
def clean_tempfiles(tmp_init=True):
if os.path.isdir('./tmp'):
os.system('rm -rf ./tmp')
os.makedirs('./tmp')
os.makedirs('./tmp/video2image')
os.makedirs('./tmp/addmosaic_image')
os.makedirs('./tmp/mosaic_crop')
os.makedirs('./tmp/replace_mosaic')
\ No newline at end of file
shutil.rmtree('./tmp')
if tmp_init:
os.makedirs('./tmp')
os.makedirs('./tmp/video2image')
os.makedirs('./tmp/addmosaic_image')
os.makedirs('./tmp/mosaic_crop')
os.makedirs('./tmp/replace_mosaic')
def file_init(opt):
if not os.path.isdir(opt.result_dir):
os.makedirs(opt.result_dir)
print('makedir:',opt.result_dir)
clean_tempfiles()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册