youtube-dl python 脚本后处理错误:无法识别 FFMPEG 编解码器 [英] youtube-dl python script postprocessing error: FFMPEG codecs aren't being recognized

查看:19
本文介绍了youtube-dl python 脚本后处理错误:无法识别 FFMPEG 编解码器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 python 脚本正在尝试使用 youtube-dl.py 下载 youtube 视频.除非需要后处理,否则工作正常.代码:

My python script is trying to download youtube videos with youtube-dl.py. Works fine unless postprocessing is required. The code:

import youtube_dl

options = {
    'format':'bestaudio/best',
    'extractaudio':True,
    'audioformat':'mp3',
    'outtmpl':'%(id)s',     #name the file the ID of the video
    'noplaylist':True,
    'nocheckcertificate':True,
    'postprocessors': [{
        'key': 'FFmpegExtractAudio',
        'preferredcodec': 'mp3',
        'preferredquality': '192',
    }]
}

with youtube_dl.YoutubeDL(options) as ydl:
    ydl.download(['http://www.youtube.com/watch?v=BaW_jenozKc'])

以下是我收到的输出:

如果我尝试将preferredcodec"设置为opus"或best",我会遇到类似的错误.我不确定这是否相关,但我可以运行对应的命令行:

I get a similar error if I try setting 'preferredcodec' to 'opus' or 'best'. I'm not sure if this is relevant, but I can run the command line counterpart fine:

youtube-dl -o 'test2.%(ext)s' --extract-audio --audio-format mp3 --no-check-certificate https://www.youtube.com/watch?v=BaW_jenozKc

我从互联网和其他问题中得到了一些线索,据我所知,这很可能是我的 ffmpeg 的问题,它不是 Python 模块,对吗?这是我的 ffmpeg 版本和配置:

I've gotten a few clues from the internet and other questions and from what i understand this is most likely an issue with my ffmpeg, which isn't a python module right? Here is my ffmpeg version and configuration:

如果我的问题的答案是向我的 ffmpeg 添加一些配置设置,请解释我是如何做的.

If the answer to my problem is to add some configuration setting to my ffmpeg please explain how i go about doing that.

推荐答案

这是 youtube-dl 和 ffmpeg 之间相互作用的错误,由文件名中缺少扩展名引起.youtube-dl 调用 ffmpeg.由于文件名不包含任何扩展名,youtube-dl 要求 ffmpeg 生成一个临时文件 mp3.但是,ffmpeg 通过扩展自动检测输出容器类型并失败,因为 mp3 没有扩展.

This is a bug in the interplay between youtube-dl and ffmpeg, caused by the lack of extension in the filename. youtube-dl calls ffmpeg. Since the filename does not contain any extension, youtube-dl asks ffmpeg to generate a temporary file mp3. However, ffmpeg detects the output container type automatically by the extension and fails because mp3 has no extension.

作为一种解决方法,只需在您的文件名模板中添加 %(ext)s:

As a workaround, simply add %(ext)s in your filename template:

'outtmpl': u'%(id)s.%(ext)s',

这篇关于youtube-dl python 脚本后处理错误:无法识别 FFMPEG 编解码器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆