How to Use the Command 'streamlink' (with Examples)
Streamlink is a versatile command-line utility that allows users to extract streaming content from various online services and pipe it into their preferred video player. This tool supports a myriad of streaming sources and provides flexible options for watching or saving content. Users can specify video quality, choose media players, and even save streams to files for offline viewing. Streamlink is a popular option for those who enjoy streaming content without the hassle of browser-related issues or for automating media consumption.
Use Case 1: Extract and List Available Streams
Code:
streamlink example.com/stream
Motivation: Imagine you’re browsing a website with several streaming options, and you’re unsure which quality will suit your needs. This command gives you a comprehensive list of available streams in different qualities, allowing for informed decision-making.
Explanation:
streamlink
: The core command for invoking the Streamlink utility.example.com/stream
: The URL of the stream you wish to investigate. Upon execution, Streamlink queries the website and assesses how many different qualities or types of streams are available.
Example Output:
[cli][info] Found matching plugin for URL example.com/stream of type generic
Available streams: 144p (worst), 360p, 720p, 1080p (best)
Use Case 2: Open a Stream with Specified Quality
Code:
streamlink example.com/stream 720p60
Motivation: Sometimes, you might want to view a stream in a specific quality for the best balance between performance and visuals. By specifying “720p60,” you ensure the video plays at 720 pixels with a smooth frame rate of 60fps, which is highly desirable for fast-paced or high-definition content.
Explanation:
720p60
: This specifies the desired stream quality. The number refers to the resolution height (720 pixels), while “60” describes the frame rate, which is frames per second.
Example Output:
[cli][info] Found matching plugin for URL example.com/stream of type generic
[cli][info] Available streams: 144p, 360p, 720p60, 1080p
[cli][info] Opening stream: 720p60 (hls)
Use Case 3: Select the Highest or Lowest Available Quality
Code:
streamlink example.com/stream best
Motivation: Want to get the best experience possible from a stream? By choosing the “best” option, you let Streamlink automatically select the highest quality stream available. Alternatively, using “worst” ensures minimal data usage, often needed for bandwidth conservation.
Explanation:
best|worst
: These keywords are used to select the highest or lowest quality stream, respectively, without needing to know the specific resolutions available ahead of time.
Example Output:
[cli][info] Found matching plugin for URL example.com/stream of type generic
[cli][info] Available streams: 144p (worst), 360p, 720p, 1080p (best)
[cli][info] Opening stream: 1080p (hls)
Use Case 4: Use a Specific Player to Feed Stream Data
Code:
streamlink --player=mpv example.com/stream best
Motivation: While Streamlink uses VLC by default if installed, you may prefer another media player due to personal preference or specific player capabilities. The --player
option gives you the flexibility to select from available media players like MPV or MPlayer.
Explanation:
--player=mpv
: This argument overrides the default player with MPV, a highly efficient and versatile media player.best
: Ensures you’re watching the stream at the highest available quality.
Example Output:
[cli][info] Found matching plugin for URL example.com/stream of type generic
[cli][info] Available streams: 144p, 360p, 720p, 1080p (best)
[cli][info] Opening stream: 1080p (hls)
[cli][info] Starting player: mpv
Use Case 5: Skip Time from Beginning of Stream
Code:
streamlink --hls-start-offset 00:05:00 example.com/stream best
Motivation: If you’re re-watching a stream or find the start redundant, you might want to skip a specific timeframe. This command allows you to start the stream five minutes in, skipping over content you might consider introductory or unnecessary.
Explanation:
--hls-start-offset [HH:]MM:SS
: Specifies the exact time offset to start playing the stream.00:05:00
: Formatted as HH:MM:SS to indicate a five-minute skip at the start of the stream.best
: Selects the highest quality stream to start streaming.
Example Output:
[cli][info] Found matching plugin for URL example.com/stream of type generic
[cli][info] Available streams: 144p, 360p, 720p, 1080p (best)
[cli][info] Opening stream: 1080p (hls)
[stream.hls][info] Seeking to timestamp from beginning: 00:05:00
Use Case 6: Skip to Beginning of a Live Stream
Code:
streamlink --hls-live-restart example.com/stream best
Motivation: Suppose you join a live stream late and wish to experience it from the beginning. This command ensures you won’t miss a moment, assuming the buffer exists to allow for such rewinding.
Explanation:
--hls-live-restart
: Commands the stream to rewind to its start, valuable for catching up from the beginning.best
: Again, ensures optimal quality selection.
Example Output:
[cli][info] Found matching plugin for URL example.com/stream of type generic
[cli][info] Available streams: 144p, 360p, 720p, 1080p (best)
[cli][info] Opening stream: 1080p (hls)
[stream.hls][info] Restarting from the beginning of the live stream
Use Case 7: Write Stream Data to a File
Code:
streamlink --output path/to/file.ts example.com/stream best
Motivation: In some scenarios, you might want to save a stream locally, perhaps due to unreliable internet connectivity or to archive content for future convenience. By specifying the file path, Streamlink downloads and stores the streaming data.
Explanation:
--output path/to/file.ts
: Designates a file path where the stream data should be saved. The.ts
extension is typical for transport streams.example.com/stream best
: Extracts the stream at the highest quality.
Example Output:
[cli][info] Found matching plugin for URL example.com/stream of type generic
[cli][info] Available streams: 144p, 360p, 720p, 1080p (best)
[cli][info] Opening stream: 1080p (hls)
[cli][info] Writing stream to: path/to/file.ts
Use Case 8: Open Stream While Recording to a File
Code:
streamlink --record path/to/file.ts example.com/stream best
Motivation: Dual-mode streaming—viewing online while simultaneously saving the content for later review—can be powerful, especially when dealing with ephemeral content that’s prone to disappear from the web.
Explanation:
--record path/to/file.ts
: Specifies both watching the stream and writing it simultaneously to a specified path.example.com/stream best
: Maintains both viewing and recording at the best available quality.
Example Output:
[cli][info] Found matching plugin for URL example.com/stream of type generic
[cli][info] Available streams: 144p, 360p, 720p, 1080p (best)
[cli][info] Opening stream: 1080p (hls)
[cli][info] Recording stream to: path/to/file.ts
Conclusion
Streamlink is a powerful utility for enthusiasts and professionals looking to manage and customize their streaming experiences with ease and precision. From selecting specific qualities, using favorite media players, to saving streams locally, this command-line tool covers a vast array of use cases, ensuring flexibility and reliability in media consumption.