Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to download videos from audioset? #10

Open
Pixie8888 opened this issue Mar 13, 2021 · 1 comment
Open

How to download videos from audioset? #10

Pixie8888 opened this issue Mar 13, 2021 · 1 comment

Comments

@Pixie8888
Copy link

Hi,
Thank you for sharing code. Can I know how you download the videos?

@kyuyeonpooh
Copy link
Owner

kyuyeonpooh commented Mar 15, 2021

Hi, thank you for the interest in my project.

I had used youtube-dl for downloading AudioSet videos.

This is a part of my downloading code.

    with youtube_dl.YoutubeDL(ydl_opts) as ydl:
        # Download video information from YouTube
        try:
            vid_info = ydl.extract_info("https://www.youtube.com/watch?v=" + ytid, download=False)
            url = vid_info["url"]
            ext = vid_info["ext"]
            if not url:
                raise ValueError("Video URL is not available.")
            if ext != "mp4":
                raise ValueError("Video extension is not mp4.")
        except youtube_dl.utils.DownloadError as e:
            return False
        except Exception as e:
            print(e)
            return False
   
        # Video clip download with ffmpeg
        try:
            ret = subprocess.call([
                    "ffmpeg",
                    "-y",                   # Overwrite without asking
                    "-ss", start,           # Starting point (sec)
                    "-i", url,              # Input video path (YouTube video URL)
                    "-t", "10",             # Max duration (sec)
                    "-c:v", "copy",         # Video codec
                    "-c:a", "copy",         # Audio codec
                    "-loglevel", "error",   
                    "-hide_banner",
                    "--", vid_file_path     # Output video path
                ], timeout=timeout)
            if ret != 0:
                if os.path.exists(vid_file_path):
                    os.remove(vid_file_path)
                return False
        except subprocess.TimeoutExpired:
            print("Timeout after {} seconds.".format(timeout))
            return False
                
        return True

The code is obtaining the raw URL of YouTube video via youtube-dl into mp4 format, and then extract the particular clips with ffmpeg.

I hope the scripts above help you to implement source codes for downloading AudioSet videos.

Be aware, as your IP might be banned by YouTube if your request rate is too fast. I recommend you to add sleep function between downloading each video.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants