首页 > 解决方案 > Python Youtube-dl 转换为 mp4

问题描述

(如果重要的话,我在窗户上)

因此,我正在尝试下载带有音频的 Mp4 格式的 Youtube 视频(我放入的程序的兼容性有限),但无论我在网上找到什么都不能像人们所说的那样工作(让我相信它是过时、缺少上下文或用于不同的操作系统)或以没有意义的方式格式化。

我当前的代码是:

if PreferredOutput == 1:
    with youtube_dl.YoutubeDL({'format' : 'bestvideo+bestaudio[ext=m4a]/bestvideo+bestaudio/best', 'merge-output-format' : 'mp4'}) as ydl:
        ydl.download([url])

但是当我测试它时,它似乎只是正常输出文件。(我猜这是视频文件上传到 youtube 的格式,好像我可能弄错了)我应该做什么/我错过了只做这个输出(最终)Mp4s?(事实上​​ffmpeg转换或类似的东西对我来说很好)

标签: pythonffmpegmp4data-conversionyoutube-dl

解决方案


Add the below option to convert videos to mp4.

'postprocessors': [{
    'key': 'FFmpegVideoConvertor',
    'preferedformat': 'mp4'
}]

After downloading the video, it will get converted to mp4 and the original file will get deleted.

Note: The conversion of the video will take a lot of time.


推荐阅读