Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
515 views
in Technique[技术] by (71.8m points)

youtube-dl python script postprocessing error: FFMPEG codecs aren't being recognized

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'])

Below is the output I receive:enter image description here

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

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: enter image description here

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...