这个什么意思呀。刚刚下载成功了使用了一下,合并成功,但是报错看不懂
这个什么意思呀。刚刚下载成功了使用了一下,合并成功,但是报错看不懂。# 目标:哗哩哗哩插放页面输入网址栏的ur1,即可获取到视颊数据import re
import os
import json
import requests
import subprocess
from pprint import pprint
# 过滤Windows文件名中的非法字符
def setFileTitle(title):
rstr = r"[\/\\\:\*\?\"\<\>\|]"# '/ \ : * ? " < > |'
name = re.sub(rstr, "_", title)# 替换为下划线
return name
# 合并音频和视频
def merge(video_address, audio_address, merge_address):
# windows命令执行的时候如果路径带空格就会截断成多个参数,解决方法就是在路径两边加双引号,所以在 cmd 那里给大括号两边都加了双引号
cmd = fr'C:\Users\misaka\ffmpeg-master-latest-win64-gpl\bin\ffmpeg.exe -i "{video_address}" -i "{audio_address}" -acodec copy -vcodec copy "{merge_address}"'
subprocess.call(cmd, shell=True)
# 相应的数据内容在__playinfo__里
url = 'https://www.bilibili.com/video/BV1684y1G73z/?spm_id_from=333.1007.tianma.1-1-1.click'
headers = {
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36",
"cookie": "_uuid=6F74D356-D356-D741-D10D3-D7B6F5F8B29967778infoc; buvid_fp=da80279a888d378c2f4b8690887d5c58; CURRENT_FNVAL=4048; buvid3=4E7146FA-43A5-3251-AF99-30B56383F3A768920infoc; b_nut=1675329869; buvid4=D7668A3A-1793-39E0-25EE-938D236E2B7768920-023020217-WiXBYh03a5sqpgE/VvEB3g%3D%3D; rpdid=|(JYYu~Y))J|0J'uY~lJkm)~k; i-wanna-go-back=-1; b_ut=7; b_lsid=D2C8F6F6_18649B276B8; nostalgia_conf=-1; sid=7qns657c; innersign=1; theme_style=light; PVID=1",
}
res = requests.get(url, headers=headers)
# print(res.text)
# 获取防盗链
headers['referer'] = url
# 获取视频标题
title = re.findall('"title":"(.*?)","pubdate"', res.text)
name = setFileTitle(title)
# print(name)
# 获取视频数据信息
html_data = re.findall('<script>window.__playinfo__=(.*?)</script>', res.text)
# 转换数据类型字符串数据转成json字典数据类型
json_data = json.loads(html_data)
pprint(json_data)
# 提取音频和视频url
audio_url = json_data['data']['dash']['audio']['baseUrl']
video_url = json_data['data']['dash']['video']['baseUrl']
# print(audio_url)
# print(video_url)
audio_info = requests.get(audio_url, headers=headers)
video_info = requests.get(video_url, headers=headers)
# 保存内容
address = "C:/Users/misaka/Desktop/bilibili"
audio_address = address + f"/{name}.mp3"
video_address = address + f"/{name}.mp4"
with open(audio_address, mode='wb') as audio:
audio.write(audio_info.content)
with open(video_address, mode='wb') as video:
video.write(video_info.content)
merge_address = address + f"/合并/{name}.mp4"
# 如果不存在合并文件夹就创建一个
if not os.path.exists('bilibili/合并'):
os.makedirs('bilibili/合并')
# 合并
merge(video_address, audio_address, merge_address)
ffmpeg version N-106367-g505a7d39cd-20220321 Copyright (c) 2000-2022 the FFmpeg developers
built with gcc 11.2.0 (crosstool-NG 1.24.0.533_681aaef)
configuration: --prefix=/ffbuild/prefix --pkg-config-flags=--static --pkg-config=pkg-config --cross-prefix=x86_64-w64-mingw32- --arch=x86_64 --target-os=mingw32 --enable-gpl --enable-version3 --disable-debug --disable-w32threads --enable-pthreads --enable-iconv --enable-libxml2 --enable-zlib --enable-libfreetype --enable-libfribidi --enable-gmp --enable-lzma --enable-fontconfig --enable-libvorbis --enable-opencl --disable-libpulse --enable-libvmaf --disable-libxcb --disable-xlib --enable-amf --enable-libaom --enable-avisynth --enable-libdav1d --enable-libdavs2 --disable-libfdk-aac --enable-ffnvcodec --enable-cuda-llvm --enable-frei0r --enable-libgme --enable-libass --enable-libbluray --enable-libmp3lame --enable-libopus --enable-librist --enable-libtheora --enable-libvpx --enable-libwebp --enable-lv2 --enable-libmfx --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopenmpt --enable-librav1e --enable-librubberband --enable-schannel --enable-sdl2 --enable-libsoxr --enable-libsrt --enable-libsvtav1 --enable-libtwolame --enable-libuavs3d --disable-libdrm --disable-vaapi --enable-libvidstab --enable-vulkan --enable-libshaderc --enable-libplacebo --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxvid --enable-libzimg --enable-libzvbi --extra-cflags=-DLIBTWOLAME_STATIC --extra-cxxflags= --extra-ldflags=-pthread --extra-ldexeflags= --extra-libs=-lgomp --extra-version=20220321
libavutil 57. 24.101 / 57. 24.101
libavcodec 59. 25.100 / 59. 25.100
libavformat 59. 20.101 / 59. 20.101
libavdevice 59.6.100 / 59.6.100
libavfilter 8. 29.100 /8. 29.100
libswscale 6.6.100 /6.6.100
libswresample 4.6.100 /4.6.100
libpostproc 56.5.100 / 56.5.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'C:/Users/misaka/Desktop/bilibili/直击心灵的歌声《负重一万斤长大》少年版 _ __为什么挑中我一个”.mp4':
Metadata:
major_brand : iso5
minor_version : 1
compatible_brands: avc1iso5dsmsmsixdash
encoder : Lavf58.29.100
description : Packed by Bilibili XCoder v2.0.2
Duration: 00:04:19.41, start: 0.046000, bitrate: 460 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 854x478 , 10 kb/s, 30 fps, 30 tbr, 16k tbn (default)
Metadata:
handler_name : VideoHandler
vendor_id :
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'C:/Users/misaka/Desktop/bilibili/直击心灵的歌声《负重一万斤长大》少年版 _ __为什么挑中我一个”.mp3':
Metadata:
major_brand : iso5
minor_version : 1
compatible_brands: avc1iso5dsmsmsixdash
encoder : Lavf58.29.100
description : Packed by Bilibili XCoder v2.0.2
Duration: 00:04:19.46, start: 0.000000, bitrate: 125 kb/s
Stream #1:0(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 2 kb/s (default)
Metadata:
handler_name : SoundHandler
vendor_id :
Output #0, mp4, to 'C:/Users/misaka/Desktop/bilibili/合并/直击心灵的歌声《负重一万斤长大》少年版 _ __为什么挑中我一个”.mp4':
Metadata:
major_brand : iso5
minor_version : 1
compatible_brands: avc1iso5dsmsmsixdash
description : Packed by Bilibili XCoder v2.0.2
encoder : Lavf59.20.101
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 854x478 , q=2-31, 10 kb/s, 30 fps, 30 tbr, 16k tbn (default)
Metadata:
handler_name : VideoHandler
vendor_id :
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 2 kb/s (default)
Metadata:
handler_name : SoundHandler
vendor_id :
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #1:0 -> #0:1 (copy)
Press to stop, [?] for help
frame= 7781 fps=0.0 q=-1.0 Lsize= 18713kB time=00:04:19.45 bitrate= 590.8kbits/s speed=4.85e+03x
video:14485kB audio:3912kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.718858%
进程已结束,退出代码0
本帖最后由 isdkz 于 2023-2-13 20:36 编辑
这些信息不是报错,这只是 ffmpeg 的一些编译时候的配置信息和在处理音视频的时候的日志信息,
你不想让他输出的话可以加一个 -loglevel quiet
# 目标:哗哩哗哩插放页面输入网址栏的ur1,即可获取到视颊数据
import re
import os
import json
import requests
import subprocess
from pprint import pprint
# 过滤Windows文件名中的非法字符
def setFileTitle(title):
rstr = r"[\/\\\:\*\?\"\<\>\|]"# '/ \ : * ? " < > |'
name = re.sub(rstr, "_", title)# 替换为下划线
return name
# 合并音频和视频
def merge(video_address, audio_address, merge_address):
# windows命令执行的时候如果路径带空格就会截断成多个参数,解决方法就是在路径两边加双引号,所以在 cmd 那里给大括号两边都加了双引号
cmd = fr'D:\secureworks\important\study\Program\python\pyinstaller\ffmpeg\bin\ffmpeg.exe -loglevel quiet -i "{video_address}" -i "{audio_address}" -acodec copy -vcodec copy "{merge_address}"'
subprocess.call(cmd, shell=True)
# 相应的数据内容在__playinfo__里
url = 'https://www.bilibili.com/video/BV1684y1G73z/?spm_id_from=333.1007.tianma.1-1-1.click'
headers = {
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36",
"cookie": "_uuid=6F74D356-D356-D741-D10D3-D7B6F5F8B29967778infoc; buvid_fp=da80279a888d378c2f4b8690887d5c58; CURRENT_FNVAL=4048; buvid3=4E7146FA-43A5-3251-AF99-30B56383F3A768920infoc; b_nut=1675329869; buvid4=D7668A3A-1793-39E0-25EE-938D236E2B7768920-023020217-WiXBYh03a5sqpgE/VvEB3g%3D%3D; rpdid=|(JYYu~Y))J|0J'uY~lJkm)~k; i-wanna-go-back=-1; b_ut=7; b_lsid=D2C8F6F6_18649B276B8; nostalgia_conf=-1; sid=7qns657c; innersign=1; theme_style=light; PVID=1",
}
res = requests.get(url, headers=headers)
# print(res.text)
# 获取防盗链
headers['referer'] = url
# 获取视频标题
title = re.findall('"title":"(.*?)","pubdate"', res.text)
name = setFileTitle(title)
# print(name)
# 获取视频数据信息
html_data = re.findall('<script>window.__playinfo__=(.*?)</script>', res.text)
# 转换数据类型字符串数据转成json字典数据类型
json_data = json.loads(html_data)
pprint(json_data)
# 提取音频和视频url
audio_url = json_data['data']['dash']['audio']['baseUrl']
video_url = json_data['data']['dash']['video']['baseUrl']
# print(audio_url)
# print(video_url)
audio_info = requests.get(audio_url, headers=headers)
video_info = requests.get(video_url, headers=headers)
# 如果不存在合并文件夹就创建一个
if not os.path.exists('bilibili/合并'):
os.makedirs('bilibili/合并')
# 保存内容
address = "bilibili"
audio_address = address + f"/{name}.mp3"
video_address = address + f"/{name}.mp4"
with open(audio_address, mode='wb') as audio:
audio.write(audio_info.content)
with open(video_address, mode='wb') as video:
video.write(video_info.content)
merge_address = address + f"/合并/{name}.mp4"
# 合并
merge(video_address, audio_address, merge_address)
页:
[1]