Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Youtube-dl convert to mp4

(if it matters, I'm on windows)

So I am trying to download a Youtube video in an Mp4 format (the program I am putting it into has limited compatibility) with audio but whatever I find online either doesn't work how people are saying it does (leading me to believe it is either outdated, missing context, or for a different OS) or is formatted in a way that doesn't make sense.

My current code is :

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

but when I test it, it just seems to output the file as normal.(which I am guessing is the format the video file was uploaded to youtube as though I could be mistaken) What should I do/am I missing to make this only output (final) Mp4s? (after the fact ffmpeg conversion or something similar is fine for my purposes)

like image 252
TenDaysTillDallas Avatar asked Oct 25 '25 20:10

TenDaysTillDallas


1 Answers

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.

like image 176
Kalyan Srinivas Limkar Avatar answered Oct 27 '25 09:10

Kalyan Srinivas Limkar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!