1.下载ffmpeg https://ffmpeg.zeranoe.com/builds/win64/static/
2.添加环境变量
path: D:\ffmpeg\bin
3.手机位置 Android->data->tv.danmaku.bili->download->925792221
4.导入到电脑 切记不可有中文目录
5.在925792221文件创建 bili.py
#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 = [] # 保存每P视频所在的文件夹路径
paths = os.listdir(superPath) # 获取当前路径下所有的文件(包括文件夹)名称
# 获取每P视频所在的文件夹路径
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' # 获取保存单P视频信息的json文件的路径
# 保存视频的标题
videoTitle = ''
with open(videoJsonDir, 'r', encoding='utf-8') as load_f:
load_dict = json.load(load_f)
videoTitle += load_dict['page_data']['part'] # 从json文件中获取单P视频标题
videoDir = 'video.m4s'
audioDir = 'audio.m4s'
outDir = videoTitle+'.mp4'
# 构造命令行指令,用来操作ffmpeg
# ffmpeg -i video.m4s -i audio.m4s -c:v copy -c:a aac -strict experimental output.mp4
command = 'cd '+ eatchPath + '\\64 && ' #&& 多名命令
command += 'ffmpeg -i ' + videoDir + ' -i ' + audioDir + ' -c:v copy -c:a aac -strict experimental ' + outDir
print('执行{}'+command)
os.system(command)