在b站下载视频,视频和音频是分开的,得知ffmpeg可以将音频和视频合成,直接上代码。
#coding=utf-8
import os
import os.path
from shutil import move
i = 55
j = 97
for c in range(43):
src_pathlist = ['D:/BaiduNetdiskDownload/nmb/'+str(i)+'/64/audio.m4s','D:/BaiduNetdiskDownload/nmb/'+str(i)+'/64/video.m4s']
dst_path = 'D:/ffmpeg/bin'
for src_path in src_pathlist:
move(src_path, dst_path)
cmd = 'ffmpeg -i video.m4s -i audio.m4s -c:v copy -strict experimental '+str(i)+'.mp4'
# cmd ='D:/ffmpeg/bin>ffmpeg -i video.m4s -i audio.m4s -c:v copy -strict experimental 输出名.mp4'
# cmd ='dir'
res = os.popen(cmd)
output_str = res.read() # 获得输出字符串
print(output_str)
if output_str != None:
srcout_pathlist = ['D:/ffmpeg/bin/audio.m4s',
'D:/ffmpeg/bin/video.m4s',
'D:/ffmpeg/bin/' + str(i) + '.mp4'
]
dstout_path = 'D:/BaiduNetdiskDownload/nmb/'+str(i)+'/64'
for srcout_path in srcout_pathlist:
move(srcout_path, dstout_path)
i =i+1