There is an example of Postprocessing in Youtube-dl wiki page for audio extracting but I could not do the same thing for video format converting. I am aware that there are options to select the video format before downloading but sometimes my desired format isn't available so I need to convert the downloaded video file. What is the key
and other parameters to be passed?
ydl_opts = {
'format': 'bestvideo[height<=480]+bestaudio/best[height<=480]',
'videoformat' : "mp4",
'outtmpl': '%(title)s.%(ext)s',
'writethumbnail': True,
'writesubtitles': True,
'writeautomaticsub': True,
'subtitleslangs': 'en',
'postprocessors': [{
'key': 'FFmpegExtractAudio', #what to use for video format converting?
'preferredcodec': 'mp3', #what to use for video format converting?
'preferredquality': '192', #what to use for video format converting?
}],
'logger': MyLogger(),
'progress_hooks': [my_hook],
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download([video_url])
The available postprocessors are listed in postprocessor/__init__.py
:
ydl_opts = {
# ...
'postprocessors': [{
'key': 'FFmpegVideoConvertor',
'preferedformat': 'mp4', # one of avi, flv, mkv, mp4, ogg, webm
}],
}
(A better name for that key would have been convert_to
, but changing it now would needlessly break compatibility.)