如何使用嵌入脚本向视频添加章节和元数据?
谢谢您的回答。
import yt_dlp
url = 'https://www.youtube.com/watch?v=BaW_jenozKc'
ydl_opts = {
'format': 'bestvideo[height<=720][ext=mp4]+bestaudio[ext=m4a]/best[height<=720][ext=mp4]',
'postprocessors': [
{'key': 'FFmpegVideoConvertor', 'preferedformat': 'mp4'},
{'key': 'EmbedThumbnail'},
{'key': 'EmbedChapters'},
{'key': 'EmbedMetadata'},
],
}
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
ydl.download(url)
embed-metadata
),但您的测试视频似乎没有任何内容。为了 EmbedThumbnail
,您应该首先使用 writethumbnail
将其写入磁盘:
import yt_dlp
url = 'https://www.youtube.com/watch?v=BaW_jenozKc'
ydl_opts = {
'format': 'bestvideo[height<=720][ext=mp4]+bestaudio[ext=m4a]/best[height<=720][ext=mp4]',
'postprocessors': [
{'key': 'FFmpegVideoConvertor', 'preferedformat': 'mp4'},
{'key': 'FFmpegMetadata'},
{'key': 'EmbedThumbnail'}
],
'writethumbnail': True
}
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
ydl.download(url)