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
609 views
in Technique[技术] by (71.8m points)

python - youtube_dl encoding mp3 with opus, not mp3 encoding

I'm using the youtube_dl library to download some videos as mp3 files. Here are the options I'm using:

ydl_opts = {
    'format': 'bestaudio/best',
    'outtmpl': music_directory + '/YouTube/' + '%(title)s.mp3',
    'noplaylist': True,
    'continue_dl': True,
    'quiet': True,
    'progress_hooks': [self.progress_hook],
    'postprocessors': [{
        'key': 'FFmpegExtractAudio',
        'preferredcodec': 'mp3',
        'preferredquality': '192', }]
}

I would have thought that the postprocessors should convert the downloaded file to mp3. However, the downloaded file isn't correctly encoded as an mp3. See:

When I run ffmpeg -i [file], it outputs this:

enter image description here

Note the matroska,webm and Audio: opus.

Whereas with normal mp3 files it specifies the audio is mp3:

enter image description here

Note the mp3 and Audio: mp3.

I'm having trouble playing the file in programs such as iTunes, and I believe this encoding error is the cause of the problem. How can I ensure youtube_dl encodes the mp3 file correctly?

Update:

After doing some more testing, it seems that youtube_dl is only downloading in mpeg and not converting to mp3 from that.

When I use these options, it downloads as an mpeg file. Testing with ffmpeg, the postprocessors don't make any difference on the audio encoding.

ydl_opts = {
    'format': 'bestaudio',
    'outtmpl': music_directory + '/YouTube/' + '%(title)s.%(ext)s',
    'noplaylist': True,
    'continue_dl': True,
    'quiet': True,
    'progress_hooks': [self.progress_hook],
    'postprocessors': [{
        'key': 'FFmpegExtractAudio',
        'preferredcodec': 'mp3',
        'preferredquality': '192', }]
}

So... I guess the problem is that I can't get youtube_dl to download anything other than an mpeg file.


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

1 Reply

0 votes
by (71.8m points)
等待大神答复

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

...