批量合并bilibili m4s格式音视频
1.说明
遍历转换指定路径下所有目录, 合并m4s格式音视频, 输出到指定目录
2.文件命名方式:
文件名来自entry.json文件, 由title, index, index_title 三部分组合而成
3.前提条件:
1.需要安装ffmpeg, 并设置环境变量
2.安装python3
4.使用方式
填写需要合并的文件所在目录, 及合并后的存放目录, 执行
import os
import subprocess
def bili():
source_src = r"源文件的路径" #源文件路径
out_src = r"合并后文件的路径" #输出保存目录
command = "ffmpeg -y -i video.m4s -i audio.m4s -vcodec copy -acodec copy" #ff命令
name_json = "entry.json" #存有文件名的文件
reg = re.compile(r'"title":"(.+?)".+?"index":"(.+?)"') # 提取文件名的正則
for root,dirs,files in os.walk(source_src):
for file in files:
if file.endswith('.m4s'):
subprocess.run(r"cd {0} & {1} {2}\{3}.mp4".format(root,command, out_src, name), shell=True) #合併輸出到指定目錄
continue
elif file == name_json: #获取文件名
src = r'{}\{}'.format(root, name_json)
with open(src, 'r', encoding='utf-8') as f:
result = reg.search(f.read())
title = result[1].replace(' ', '').replace(r'\t', '').replace(r'\n', '')
index = result[2].replace(' ', '').replace(r'\t', '').replace(r'\n', '')
index_title = result[3].replace(' ', '').replace(r'\t', '').replace(r'\n', '')
name = title + index + index_title

浙公网安备 33010602011771号