Full Stack LAMP - MEAN Developer, Python developer. Certified Azure Developer. Freelance programmer/consultant/trainer.

How to download YouTube live stream video in chunks

In this tutorial, we gonna download YouTube live stream video in chunks for the given interval. We gonna run few commands in the terminal for this task, you can use any programming language to do the same to automate things.

FFmpeg is a complete, cross-platform solution to record, convert and stream audio and video.

Using FFmpeg we can easily create chunks of files for a given video file for the given interval.

Here is the command to create a chucks of video files:

#ffmpeg -i source_video_file.mp4 -c copy -map 0 -segment_time 02:00 -f segment output%03d.mp4

# The options are as follows:
# -i ‘something.mp4’ → the name of the input file
# -map 0 → use the first input file for all outputs
# -codec copy → do not recompress the video
# -f segment → the output file will be multiple segments
# -segment_time 02:00 → create segments of this duration (2 minutes in the example)
# ‘output%03d.mp4’ → name the output files like output001.mp4 etc. (3 is the number of digits in the counter)

To generate video chunks from the Youtube live feed, first, we should grab the manifest URL of the live stream. We gonna use https://github.com/ytdl-org/youtube-dl to get the manifest URL of youtube Livestream. Follow the official documentation of youtube-dl for installation steps.

After installation, run the following command to get the Manifest URL.

youtube-dl --print-traffic https://youtu.be/ \
| grep -oP "/api/manifest/dash/.*? " \
| echo "https://manifest.googlevideo.com/$(cat -)"

With the Manifest URL executes the following command from your terminal it will download video chunks for the given interval.

ffmpeg -i YOUR_manifest_URL -c copy -flags +global_header -f segment -segment_time 10 -strftime 1 -segment_format_options movflags=+faststart -reset_timestamps 1 file_%Y%m%d%H%M%S_%d.mp4

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments