最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - Trying to download YouTube video using yt_dlp I get error: Error: '__files_to_merge' - Stack Overflow

programmeradmin3浏览0评论

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
Add a comment  | 

1 Answer 1

Reset to default 0

What worked for me was to use CLI:yt-dlp -f 137+140 --merge-output-format mp4 https://youtu.be/e-QzJnego04

发布评论

评论列表(0)

  1. 暂无评论