Python实现B站MP4格式音频与视频的合并!超详细的教程!

python 使用 ffmpeg 合并音频+视频 import subprocess def video_add_mp4(file_name,mp4_file): outfile_name = file_name.split('.')[0] + '-new.mp4' cmd = f'F:\\FFmpeg\\bin\\ffmpeg -i {mp4_file} -i {file_name} -acodec copy -vcodec copy {outfile_name}' print(cmd) subprocess.call( 阅读详情

安装

官网下载

PS:如有需要Python学习资料的小伙伴可以加点击下方链接自行获取

python免费学习资料以及群交流解答点击即可加入

http://ffmpeg.org/

选择需要的版本

在这个网址下载ffmpeg, https://github.com/BtbN/FFmpeg-Builds/releases

将解压后得到的以下几个文件放置在 E:\FFmpeg 下

环境变量

此电脑--属性--高级系统设置--环境变量

在系统变量(也就是下面那一半)处找到新建,按如下所示的方法填写

再将 %FFMPEG_HOME% 以及 %FFMPEG_HOME%\bin 写入系统变量的Path中

然后一路确定即可

验证

win+R,cmd

输入 ffmpeg -version 

ffmpeg的使用

对于我将B站PC端缓存的音频mp4和视频mp4文件合并的需求,需要用到的命令为:

ffmpeg.exe -i audio1.mp4 -i video.mp4 -acodec copy -vcodec copy output.mp4 

可以把mp4的文件设置成绝对路径,这样就可以转换指定路径的文件以及保存到指定路径了,比如这样:

ffmpeg.exe -i "E:\哔哩哔哩视频\ss27993\77413703\1\audio1.mp4" -i "E:\哔哩哔哩视频\ss27993\77413703\1\video.mp4" -acodec copy -vcodec copy "E:\B站导出视频\Dr.STONE石纪元\第22话宝物.mp4 

通过PC端缓存的未合并的视频和音频,全都是命名为video.mp4和audio.mp4

PS:有些兄弟是导出的手机端缓存的视频和音频,是m4s格式的,方法也一样

但光有这条命令还不够,需要自己手动一个个操作,太麻烦了

因此我还需要使用Python来自动帮我完成工作

Python实现自动处理

虽然Python可以实现自动化,减少时间的浪费,但最快的还是以后记得缓存时勾选自动合并

文件结构

PC端缓存的视频保存的文件结构有很多种,我只是根据我碰到的情况写的,但大同小异,修改起来也不麻烦,只是再加个if和else罢了

番剧缓存结构

缓存的番剧是这种结构:

上面举的例子是Dr.stone石纪元,我缓存的鬼灭之刃也是如此

特点是在一个以视频ID号名称的文件夹(ss27993)后,跟着许多子文件夹(57983089等),然后在这些子文件夹中又有一个或多个子文件夹(比如1),然后缓存的视频保存在这个文件夹里,里面有一个info文件(就是json格式),还有audio1.mp4和video.mp4。

PS:

还有一个xml文件,是弹幕信息,暂时我不知道怎么处理

常规缓存结构

除了番剧,一般的视频缓存的结构是这样的

不难看出,这比番剧要少一个层级

文件信息

文件信息主要由info文件和dvi文件来记录

这两种文件都可以直接以json文件来处理,也就是,首先open函数打开文件,然后用json.load转成字典。。。

然后我还发现了一个特点是,视频和音频所在的目录下是info文件,而它的上一层目录下是dvi文件

虽然文件格式基本是一致的,但是里面的键-值关系却不一致,单集视频的名称在番剧中对应的是键 Description ,在其他视频中对应的是 PartName 
视频总的名称保存在外层的目录下的info文件或dvi文件中,番剧中对应的键是 SeasonTitle ,在其他视频中对应的是 Title 

ffmpeg解决bilibili下载的音视频分离问题,将音视频一键合成 ffmpeg解决bilibili下载的音频分离问题,将音视频一键合成 阅读详情

相关推荐

python + ffmpeg 将某站的缓存视频文件批量转换为MP4格式

这是一篇很无聊的文章,之所以写它是因为这周还没写博客,但是好像没啥可写的,刚好今天突发奇想,想要把某站的APP缓存视频文件转化为mp4 格式,方便在电脑上看,方法很简答,很快就做完了,所以,又一篇水文诞生了,罪过,罪过。 水文警告!水文警告!这是一篇毫无营养的水文! 一、题外话 话说某站可真是个好地方,原本我只是在上面看看动漫,看看别人做的鬼畜视频而已。但最近我发现上面有好多学习的课程,全部免...

分享日常的学习,开展的项目,编写的软件,解决的问题等~ 4029

在手机或电脑上用Python爬取B站视频和音频

【代码】在手机或电脑上用Python爬取B站视频和音频。

weixin_56059924的博客 4444

python合并视频和音频_Python批量合并处理B站视频

最近想学习后端,又不想花钱,怎么办呢?于是在手机端B站(哔哩哔哩)上面找到了满意的免费视频教程,但是手机端看起来很不方便啊。于是,我通过在手机端缓存下来后,导入到了电脑端,但是我后面了发现两个问题:1.本来一集视频按理说一段吧,但是B站下载下来的视频并不是完整的一段,而是被分成了多段blv格式的视频,所以需要想办法把它们拼接成完整的一段视频!2.视频数量太大,不可能一个一个去修改,得想办法批量处理...

weixin_39585617的博客 1650

m4s格式转换mp4

注意,b站导出的m4s文件有时候会出现报错, Invalid data found when processing input。mac多说一句,直接用sublime text读取m4s文件,打开是数字编码,删除前九对30,删到00,保存就可以转了。https://www.bilibili.com/read/cv14802750/ 可以参考这篇文章。先安装 ffmpeg,具体从官网可以查到,https://ffmpeg.org,按流程走。mac如果直接用文本格式读取,即使手动删除前9个0还是不行。

weixin_44669441的博客 4202

BiliBili视频合并软件-audio.m4s-video.m4s合并成mp4.rar

内容包括python源代码,和py文件,以及批处理执行bat文件。 使用python批量将audio.m4s-video.m4s合并成mp4 BiliBili视频合并软件-audio.m4s-video.m4s合并成mp4

calibration的“前世今生”——从simulink开发到CANape的XCP标定

整体思路 备注: elf可简单的看作为hex和map的集合,其中包括可执行的程序、变量及其对应的地址(simulink生成代码是也可以勾选生成ASAP2的a2l文件,有变量但变量对应的地址为空,只有编译后才分配地址) 定义变量是观测值还是标定值需要在simulink中的数据字典定义变量存储类型,详见simulink系列。 1. 前期准备A2L的制作 安装完成CanApe软件 , 插上CanApe硬件( 如:vector 1640A)。打开A2L编辑软件 ASAP2 Editor(注意不是ASAP2 Vi

IHTY_NUI的博客 1万+

青龙人形机器人硬件平台设计全解析:从构型到控制系统的实战指南

本文深度解析了青龙人形机器人硬件平台的设计全流程,从需求分析、构型设计到核心系统实现。文章详细阐述了其43个自由度的仿生构型、高动态性下肢设计、灵巧作业系统以及分布式控制架构,并探讨了旋转关节与直线关节等关键技术选型,为开发者提供了从理论到实践的完整硬件设计指南。

weixin_29248313的博客 390

MATLAB Appdesigner开发独立桌面App全流程(一):以打开串口功能为例介绍Appdesigner的基本使用

本文详细介绍了Appdesigner的基本使用,以串口功能为例介绍按钮回调函数的实现以及控件之间通信的问题

Zhuwany的博客 3万+

【QEMU系统分析之TPM篇(一)】

本文以 QEMU 8.2.2 为例,分析其 TPM-emulator 模块的实现,并为 QEMU 添加 Windows 平台的TPM 模拟器的支持。

David唐辉的博客 1194

数学建模学习(75):全局敏感性分析Morris 方法

敏感性分析 (SA) 是分析不同应用条件下模型行为的基本实践。提出了许多 SA 技术,从简单的筛选方法到计算成本高昂的基于方差的方法。本篇内容我们通过将 Morris 方法来对模型进行分析。

全栈川川 1万+

9.1 机器人动力学建模

目录9.1 机器人动力学建模一、机器人动力学的基本概念1. 什么是机器人动力学?2. 动力学方程二、机器人动力学建模方法1. 拉格朗日方法2. 牛顿-欧拉方法三、Simulink 中的机器人动力学建模1. 使用 Simscape Multibody 建模示例:构建一个两连杆机械臂的动力学模型。步骤:2. 使用 Robotics System Toolbox 建模示例:构建一个六自由度工业机器人的动力学模型。步骤:四、示例:两连杆机械臂的动力学建模目标:步骤:五、结果分析1. 动态响应2. 参数敏感性六、总结

xiaoheshang_123的博客 627

图像处理入门007:图像处理中的数学基础:线性代数与卷积

一种:把 OpenCV 当黑盒,调用,效果不对就乱调参数;另一种:理解每个像素是怎么被周围邻域"加权平均"的,理解核翻转、边界填充、stride 的含义。前者能干活,后者能解难题。一旦遇到自定义核(比如 ISP 上的锐化)、深度学习反向传播、医学图像重建,你就必须把卷积、相关、矩阵乘法这些基本功捡回来。线性代数三件套:向量点积、矩阵乘法、线性变换;2D 卷积的数学定义:核翻转、滑动窗口、边界填充。并手写一个,验证它与和的结果完全一致(误差 < 1e-9)。f∗gn∑m−∞∞f。

专注:太空算力、AI infra、异构调度、大模型成本工程 388

工业相机通用SDK封装实战:C#硬件抽象层(HAL)实现多品牌无缝切换

本文介绍了一种解决工业相机SDK碎片化问题的通用解决方案。作者基于多年工业视觉项目经验,提出通过硬件抽象层(HAL)和适配器模式封装不同品牌相机的SDK差异,实现统一的相机操作接口。文章详细分析了传统直接对接SDK方式的四大痛点:接口碎片化、维护成本高、业务耦合度高和稳定性差,并给出了分层架构设计方案。该方案采用三层架构(业务层、抽象层、实现层),遵循最小接口原则和高内聚低耦合等设计理念,定义了包括触发模式、像素格式等通用枚举类型,以及图像数据结构等核心抽象。最终实现的HAL层能够支持多种品牌相机,显著降低

这里只有干货:从 Modbus 通信到 MES 对接,从 YOLO 训练到工控机部署,带你搞定工业软件开发全流程。 581

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

上一篇: 肯德基全国到处都有!用requests模块爬取肯德基餐厅信息!
下一篇: 手把手教你使用 Python 抓取并存储网页数据!最详细的爬虫教程!
爬遍天下无敌手
博客等级 码龄8年 6682粉丝 976原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址