提交 80911eaa 编写于 作者: K_O_Carnivist's avatar K_O_Carnivist

Init version

上级
import os
import json
import re
## 运行前设置ffmpeg的path环境变量
## Define
INPUT_PATH = 'D:/Videos/danmaku3'
OUTPUT_PATH = 'D:/Videos/danmaku_out'
## blv改成flv
for path,dir_list,file_list in os.walk(INPUT_PATH):
for file_name in file_list:
if os.path.splitext(file_name)[-1][1:] == 'blv':
os.rename(os.path.join(path, file_name), os.path.join(path, file_name)[:-3] + 'flv')
## 输出
for video_path in [f for f in os.scandir(INPUT_PATH) if f.is_dir()]:
for page_path in [f for f in os.scandir(video_path.path) if f.is_dir()]:
with open(page_path.path + '/entry.json', 'rb') as f_entry:
page_entry = json.load(f_entry)
output_video_path = OUTPUT_PATH + '/' + page_entry['title']
os.makedirs(output_video_path, exist_ok=True)
raw_input_path = [f.path for f in os.scandir(page_path.path) if f.is_dir()][0]
part_name = page_entry['page_data']['part']
# 弹幕
with open(page_path.path + '/danmaku.xml', 'rb') as f_i, open(output_video_path + '/' + part_name + '.xml', 'wb') as f_o:
f_o.write(f_i.read())
# m4s
if os.path.exists(raw_input_path + '/video.m4s') and os.path.exists(raw_input_path + '/audio.m4s'):
ffmpeg_cmd = 'ffmpeg ' + \
'-i \"' + raw_input_path + '/video.m4s\" ' + \
'-i \"' + raw_input_path + '/audio.m4s\" ' + \
'-c:v copy -c:a copy -strict experimental ' + \
'\"' + output_video_path + '/' + part_name + '.mp4\"'
print(ffmpeg_cmd)
os.system(ffmpeg_cmd)
# flv
elif os.path.exists(raw_input_path + '/0.flv'):
clip_list = [f.path for f in os.scandir(raw_input_path) if '.flv' in f.name]
clip_list.sort(key=lambda var:[int(x) if x.isdigit() else x for x in re.findall(r'[^0-9]|[0-9]+', var)])
temp_filename = raw_input_path + '/tmp_%s.txt' % os.getpid()
temp_file = open(temp_filename, 'w', encoding='utf-8')
for clip_filename in clip_list:
temp_file.write('file \'%s\'\n' % os.path.split(clip_filename)[1])
temp_file.close()
ffmpeg_cmd = 'ffmpeg ' + \
'-f concat -safe 0 ' + \
'-i \"' + temp_filename + '\" ' + \
'-c copy ' + \
'\"' + output_video_path + '/' + part_name + '.mp4\"'
print(ffmpeg_cmd)
os.system(ffmpeg_cmd)
os.remove(temp_filename)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册