2. Quick start¶
The Ytpb Command Line Interface (CLI) provides commands to download YouTube live stream excerpts and compose MPEG-DASH manifests to play excerpts later in different available qualities. Here are below basic examples demonstrating usage scenarios.
2.1. Download¶
Let’s start with downloading a 30-second excerpt of audio and video by specifying start and end dates and stream URL or ID:
$ ytpb download -i 2024-01-02T10:20:00+00/PT30S <STREAM> && ls
Stream-Title_20240102T102000+00.mp4
By default, it will download an excerpt in the best pre-defined quality: 128k AAC audio and 1080p30 (or less) H.264 video. See Specifying formats on how to choose the formats to download.
As for the start and end, they can be also defined in other ways (see
Specifying rewind interval). For example, it would be handy to locate
the desired moments first by previewing them and only after download a full
excerpt. To run downloading in the preview mode, use the
-ps / --preview-start or -ps / --preview-end options:
$ ytpb download -i 2024-01-02T10:20:00+00/PT30S -ps <STREAM>
Note that the duration of an output excerpt may be a bit longer because the merging of media segments is done without
cutting. You can use the -c / --cut option to frame-accurately cut an
excerpt, but this will require additional disk space almost equal to the size of
an excerpt.
Check also out how to download media segments with an external downloader.
2.2. Compose and play¶
If you want to play an excerpt without downloading it, you can compose a static MPEG-DASH manifest (MPD) file:
$ ytpb mpd compose -i 2024-01-02T10:20:00+00/PT1H <STREAM> && ls
$ Stream-Title_20240102T102000+00.mpd
By default, a manifest will contain a 128k AAC audio track and 720p (or better) 30 fps VP9 video channels.
Next, you can play a composed manifest in a player that supports MPEG-DASH. For example, with VLC:
$ vlc Stream-Title_20240102T102000+00.mpd
Or with mpv:
Note: Requires a custom mpv build. See #4 for details.
$ mpv Stream-Title_20240102T102000+00.mpd
Check also out how to convert a manifest to a media file with FFmpeg.
2.3. Play¶
Playing and rewinding live streams are possible without downloading or composing. Take a look at mpv-ytpb. It provides interactive experience with no need to leave the mpv player.
2.4. Capture¶
Capturing a frame (screenshot) of a moment or frames within an interval is possible without making a video.
2.4.1. One frame¶
For example, let’s take a picture of the moment happening right now:
$ ytpb capture frame --moment now <STREAM> && ls
Stream-Title_20231227T012954+00.jpg
2.4.2. Timelapse¶
Capture not just a single frame, but a whole timelapse with one frame every period of time:
$ ytpb capture timelapse -i 2024-01-02T10:20:00+00/PT30S --every 15S <STREAM>
$ tree Stream-Title
Stream-Title
└── 20240102T102000+00
└── ET15S
├── Stream-Title_20240102T102000+00_ET15S_0000.jpg
├── Stream-Title_20240102T102000+00_ET15S_0001.jpg
└── Stream-Title_20240102T102000+00_ET15S_0002.jpg