I want to download a YouTube video, I did but the audio is not merged with the video(audio is not audible). How can I fix that using yt-dlp?
Error: '__files_to_merge'
import os
import yt_dlp
def download_video(video_url, save_path):
if not save_path.endswith('.mp4'):
save_path += '.mp4'
try:
ydl_opts = {
'outtmpl': save_path,
'format': 'bestvideo+bestaudio/best',
'merge_output_format': 'mp4',
'postprocessors': [
{'key': 'FFmpegMerger'},
],
}
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
ydl.download([video_url])
print(f"Downloaded: {save_path}")
except Exception as e:
print(f"Failed to download: {video_url}\nError: {e}")
def main():
# List of video URLs
video_urls = [
'', # Example URL
'',
# Add more video URLs here
]
# Directory to save videos
save_dir = 'Udacity_GenAI_Videos'
if not os.path.exists(save_dir):
os.makedirs(save_dir)
for i, video_url in enumerate(video_urls):
save_path = os.path.join(save_dir, f'video_{i+1}.mp4')
download_video(video_url, save_path)
if __name__ == "__main__":
main()
I want to download a YouTube video, I did but the audio is not merged with the video(audio is not audible). How can I fix that using yt-dlp?
Error: '__files_to_merge'
import os
import yt_dlp
def download_video(video_url, save_path):
if not save_path.endswith('.mp4'):
save_path += '.mp4'
try:
ydl_opts = {
'outtmpl': save_path,
'format': 'bestvideo+bestaudio/best',
'merge_output_format': 'mp4',
'postprocessors': [
{'key': 'FFmpegMerger'},
],
}
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
ydl.download([video_url])
print(f"Downloaded: {save_path}")
except Exception as e:
print(f"Failed to download: {video_url}\nError: {e}")
def main():
# List of video URLs
video_urls = [
'https://youtu.be/u_CQggTmSO8', # Example URL
'https://youtu.be/vCzMfZtrdjk',
# Add more video URLs here
]
# Directory to save videos
save_dir = 'Udacity_GenAI_Videos'
if not os.path.exists(save_dir):
os.makedirs(save_dir)
for i, video_url in enumerate(video_urls):
save_path = os.path.join(save_dir, f'video_{i+1}.mp4')
download_video(video_url, save_path)
if __name__ == "__main__":
main()
Share
Improve this question
asked Feb 7 at 15:41
Kaleab WoldemariamKaleab Woldemariam
2,9935 gold badges28 silver badges49 bronze badges
1 Answer
Reset to default 0What worked for me was to use CLI:yt-dlp -f 137+140 --merge-output-format mp4 https://youtu.be/e-QzJnego04