Как скачать часть видео с YouTube
Table of Contents
Introduction
This tutorial will guide you through the process of downloading a specific segment of a YouTube video using two powerful tools: yt-dlp
and ffmpeg
. These tools allow you to extract and save just the part of the video you need, which is useful for creating clips, presentations, or simply saving highlights.
Step 1: Install yt-dlp and ffmpeg
Before you can download a segment of a video, you need to have both yt-dlp
and ffmpeg
installed on your system.
Installing yt-dlp
- Visit the yt-dlp GitHub page: yt-dlp GitHub.
- Follow the installation instructions for your operating system. Common methods include using pip:
pip install yt-dlp
Installing ffmpeg
- Visit the ffmpeg builds page: FFmpeg Builds.
- Download the appropriate version for your operating system.
- Follow the installation instructions provided on the website.
Step 2: Get the Video URL
You need the URL of the YouTube video you want to download a segment from.
- Go to the YouTube video page.
- Copy the URL from your browser’s address bar.
Step 3: Extract Video Stream URL
Using yt-dlp
, you will extract the direct video stream URL.
- Open your command-line interface.
- Run the following command, replacing
%URL%
with the actual video URL:yt-dlp -g %URL%
- This command will return the direct URL of the video stream. Copy this URL for the next step.
Step 4: Download the Video Segment
Now, use ffmpeg
to download the specific segment of the video.
- In your command-line interface, run the following command:
ffmpeg -hwaccel auto -i %URL1% -i %URL2% -map 0:0 -map 1:0 -c copy -ss 00:00:15 -to 00:00:30 -avoid_negative_ts make_zero -f matroska -y output.mkv
- Replace
%URL1%
with the video stream URL you obtained in Step 3. - Replace
%URL2%
with any additional input URL or leave it as is for a single stream. - Adjust the
-ss
and-to
parameters to specify the start and end times of the segment you want to download (in this case, from 15 seconds to 30 seconds). - The output file will be saved as
output.mkv
.
- Replace
Conclusion
You have now successfully downloaded a segment of a YouTube video using yt-dlp
and ffmpeg
. You can modify the start and end times as needed to capture different segments. This method is efficient for creating clips for personal use or sharing highlights from videos. For further exploration, consider experimenting with other ffmpeg
options for different output formats or additional processing.