哔哩哔哩批量合并缓存音视频,从json中获取视频名称
简单命令
ffmpeg -i video.m4s -i audio.m4s -codec copy Output.mp4
在缓存视频集合目录下执行执行
#coding:utf-8
import os
import json
import time
# ffmpeg -i video.m4s -i audio.m4s -c:v copy -c:a aac -strict experimental output.mp4
superPath = os.getcwd()
partDirs = []
paths = os.listdir(superPath)
for p in paths:
if os.path.isdir(p):
partDirs.append(os.path.join(superPath, p))
print(partDirs)
for eatchPath in partDirs:
videoJsonDir = eatchPath+'\\'+'entry.json'
videoTitle = ''
with open(videoJsonDir, 'r', encoding='utf-8') as load_f:
load_dict = json.load(load_f)
videoTitle += '"'+load_dict['page_data']['part']+'"'
videoDir = 'video.m4s'
audioDir = 'audio.m4s'
outDir = videoTitle+'.mp4'
# ffmpeg -i video.m4s -i audio.m4s -c:v copy -c:a aac -strict experimental output.mp4
command = 'cd '+ eatchPath + '\\32 && ' #&& 多名命令,根据自己具体情况是32还是64
command += 'ffmpeg -i ' + videoDir + ' -i ' + audioDir + ' -c:v copy -c:a aac -strict experimental ' + outDir
print('{}'+command)
os.system(command)
最后需要将所以视频移动到vidio文件夹里
# coding:'utf-8'
import os
import platform
superPath = os.getcwd()
files = list()
def dirAll(pathName):
if os.path.exists(pathName):
fileList = os.listdir(pathName)
for f in fileList:
f = os.path.join(pathName, f)
if os.path.isdir(f):
dirAll(f)
else:
dirName = os.path.dirname(f)
baseName = os.path.basename(f)
if dirName.endswith(os.sep):
files.append(dirName + baseName)
else:
files.append(dirName + os.sep + baseName)
if __name__ == '__main__':
dirAll(superPath)
system = platform.system()
print(system)
moveDir = os.path.join(superPath, "video")
if not os.path.exists(moveDir):
os.mkdir(moveDir)
for f in files:
if str(f).endswith('.mp4'):
print(os.path.basename(f))
print(os.path.dirname(f))
if system == 'Windows':
os.system(r'cd %s & move %s %s\%s' % (
os.path.dirname(f), os.path.basename(f), os.path.join(superPath, "video"), os.path.basename(f)))
else:
os.system(r'cd %s & cp %s %s/%s' % (
os.path.dirname(f), os.path.basename(f), os.path.join(superPath, "video"), os.path.basename(f)))
ffmpeg下载
(资料来自网络 ffmpeg下载)[http://www.pc6.com/softview/SoftView_753971.html]