当前位置: 首页 > news >正文

B站缓存视频数据m4s转mp4

B站缓存视频数据m4s转mp4

  • 结构分析

结构分析

在没有改变数据存储目录的情况下,b站默认数据保存目录为:
`Android->data->tv.danmaku.bili->download`

在这里插入图片描述
每个文件夹代表一个集合的视频,比如,我下载的”java从入门到精通“,那么就会保存到一个目录里面:
在这里插入图片描述
每个以c_开头的都是一个小章节。
在这里插入图片描述
每个小章节包含entry.json(视频标题及章节名称等信息),danmaku.xml(弹幕),64或80等(视频文件及音频文件等)
在这里插入图片描述
将audio.m4s以及video.m4s合成后就是一个完整的视频。本地得安装ffmpeg或者使用python-ffmpeg。
关键部分代码:

command = ["ffmpeg","-i", video_m4s,  # 输入视频文件"-i", audio_m4s,  # 输入音频文件'-c:v', 'copy',  # 不重新编码视频'-c:a', 'copy',  # 不重新编码音频"-y",  # 覆盖已存在的文件output_mp4  # 输出文件]# 使用 subprocess.run 执行命令result = subprocess.run(command)

将整个标题的视频转换出来。

#!/usr/bin/python3
from tkinter import *
from tkinter import messagebox
from tkinter import filedialog
import subprocess
import os
import json
import ffmpegdef select_source():# 选择视频源目录dir_path = filedialog.askdirectory(title="选择视频源目录")if dir_path:source_entry.delete(0, END)source_entry.insert(0, dir_path)def select_target():# 选择保存目录dir_path = filedialog.askdirectory(title="选择视频保存目录")if dir_path:target_entry.delete(0, END)target_entry.insert(0, dir_path)def convert_with_ffmpeg(video_m4s, audio_m4s, output_mp4):if os.path.getsize(video_m4s) < 0 or os.path.getsize(audio_m4s) <= 0:print("非法的音视频文件,{audio_m4s},视频文件:{video_m4s}")return Falsetry:# 输入视频和音频video = ffmpeg.input(video_m4s)audio = ffmpeg.input(audio_m4s)# 构造 FFmpeg 命令command = ["ffmpeg","-i", video_m4s,  # 输入视频文件"-i", audio_m4s,  # 输入音频文件'-c:v', 'copy',  # 不重新编码视频'-c:a', 'copy',  # 不重新编码音频"-y",  # 覆盖已存在的文件output_mp4  # 输出文件]# 使用 subprocess.run 执行命令result = subprocess.run(command)# 检查命令是否成功执行if result.returncode == 0:print(f"{output_mp4} -> 合并成功!")return Trueelse:print(f"合并失败, 视频文件:{video_m4s}, 音频文件:{audio_m4s}")print(f"错误信息: {result.stderr}")return Falseexcept ffmpeg.Error as e:print(f"合并失败,音频文件:{audio_m4s},视频文件:{video_m4s}")return Falsedef batch_convert_vedio(source_path, target_path):for dir in os.listdir(source_path):dir_path = os.path.join(source_path, dir)entry_file = os.path.join(dir_path, "entry.json")data_dir = os.listdir(dir_path).pop(0)audio_path = os.path.join(dir_path, data_dir, "audio.m4s")vedio_path = os.path.join(dir_path, data_dir, "video.m4s")with open(entry_file, 'r', encoding='utf-8') as f:entry_sjon = f.read()json_data = json.loads(entry_sjon)part_content = json_data.get("page_data", {}).get("part")title = json_data.get("title")if not os.path.exists(os.path.join(target_path, f'{title}')):os.makedirs(os.path.join(target_path, f'{title}'))target_vedio_path = os.path.join(target_path, f'{title}/{part_content}.mp4')convert_with_ffmpeg(vedio_path, audio_path, target_vedio_path)print(target_vedio_path)def convert_video():source_path = source_entry.get()target_path = target_entry.get()if not source_path or not target_path:messagebox.showerror("错误", "请选择源目录和目标目录!")else:batch_convert_vedio(source_path, target_path)messagebox.showinfo("成功", f"视频将从 {source_path} 转换保存到 {target_path}")root = Tk()
root.title("bili视频转换工具")# 设置窗口大小并居中
window_width = 500  # 稍微加宽窗口
window_height = 200
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
x = (screen_width - window_width) // 2
y = (screen_height - window_height) // 2
root.geometry(f"{window_width}x{window_height}+{x}+{y}")# 配置网格布局权重
for i in range(5):root.grid_columnconfigure(i, weight=1)
for i in range(4):root.grid_rowconfigure(i, weight=1)# 视频源目录选择
source_label = Label(root, text="视频源目录:")
source_label.grid(row=0, column=0, sticky="e", padx=5, pady=5)source_entry = Entry(root)
source_entry.grid(row=0, column=1, columnspan=3, sticky="ew", padx=5, pady=5)source_button = Button(root, text="浏览...", command=select_source)
source_button.grid(row=0, column=4, sticky="ew", padx=5, pady=5)# 视频保存目录选择
target_label = Label(root, text="视频保存目录:")
target_label.grid(row=1, column=0, sticky="e", padx=5, pady=5)target_entry = Entry(root)
target_entry.grid(row=1, column=1, columnspan=3, sticky="ew", padx=5, pady=5)target_button = Button(root, text="浏览...", command=select_target)
target_button.grid(row=1, column=4, sticky="ew", padx=5, pady=5)# 转换按钮
button_convert = Button(root, text="立即转换", command=convert_video)
button_convert.grid(row=2, column=1, columnspan=3, sticky="ew", padx=50, pady=20)# 进入消息循环
root.mainloop()

具体效果如下:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述


文章转载自:

http://Q8gc6sOY.cfrhc.cn
http://EtOIH1q7.cfrhc.cn
http://OXs1NIE4.cfrhc.cn
http://N94rQV1W.cfrhc.cn
http://36PjWel6.cfrhc.cn
http://hoBbd893.cfrhc.cn
http://ZivNMK8t.cfrhc.cn
http://NpNV9qc5.cfrhc.cn
http://ZyKyPjWW.cfrhc.cn
http://W68OGiKt.cfrhc.cn
http://4qgiILsn.cfrhc.cn
http://z1noayO0.cfrhc.cn
http://KCkQg7EK.cfrhc.cn
http://2XBPUdjF.cfrhc.cn
http://j7gkWrX1.cfrhc.cn
http://Vkf5dBXr.cfrhc.cn
http://AJr67evK.cfrhc.cn
http://stV2yZSh.cfrhc.cn
http://vgFtQBN1.cfrhc.cn
http://RTHTByGk.cfrhc.cn
http://VDGfYdNr.cfrhc.cn
http://KIkkZeX6.cfrhc.cn
http://Dd8fZJky.cfrhc.cn
http://KS8OTqC1.cfrhc.cn
http://AIZAAdoA.cfrhc.cn
http://XB6WGPlX.cfrhc.cn
http://XXfmNG1r.cfrhc.cn
http://8RgiJqTu.cfrhc.cn
http://hemTVjkR.cfrhc.cn
http://7ARwKpzq.cfrhc.cn
http://www.dtcms.com/a/228668.html

相关文章:

  • 网络安全-等级保护(等保) 3-3 GB/T 36627-2018 《信息安全技术 网络安全等级保护测试评估技术指南》-2018-09-17发布【现行】
  • 解锁Java多级缓存:性能飞升的秘密武器
  • 从基础原理到Nginx实战应用
  • Vert.x学习笔记-EventLoop与Handler的关系
  • AI数据集构建:从爬虫到标注的全流程指南
  • 人工智能挑战杯推荐项目
  • 【知识点】openai请求参数如何转为大模型的字符串?
  • 《仿盒马》app开发技术分享-- 个人中心关于逻辑完善(端云一体)
  • 嵌入式开发学习日志(linux系统编程--系统编程之 进程间通信IPC)Day32
  • [内核开发手册] ARM汇编指令速查表
  • 52. N 皇后 II【 力扣(LeetCode) 】
  • 涂装协作机器人:重新定义涂装工艺的智能化未来
  • Spring Cloud Eureka:微服务架构中的服务注册与发现核心组件
  • 网络安全:钓鱼邮件、虚假网站与诈骗信息的预防与应对
  • DPO 算法
  • 大模型模型推理的成本过高,如何进行量化或蒸馏优化
  • [概率论基本概念4]什么是无偏估计
  • VR线上展厅特点分析与优势
  • 阿里云无影云桌面深度测评
  • centos挂载目录满但实际未满引发系统宕机
  • 婚恋小程序直播系统框架搭建
  • 图解深度学习 - 激活函数和损失函数
  • 1130 - Host ‘xxx.x.xx.xxx‘is not allowed to connect to this MySQL server
  • 【JAVA版】意象CRM客户关系管理系统+uniapp全开源
  • 一、核心概念深入解析
  • 使用seaborn/matplotlib定制好看的confusion matrix
  • linux安全加固(非常详细)
  • 产品更新丨谷云科技ETLCloud 3.9.3 版本发布
  • Redis中的fork操作
  • Linux 软件安装方式全解(适用于 CentOS/RHEL 系统)