How to watch live streaming video from the command line on Linux

There are quite a few popular live streaming services on the web (e.g., Dailymotion, YouTube Live, UStream, etc.). Most of these streaming services are accessed from a web browser via flash plugin. If you heavily use some of those services on Linux, you may notice that your web browser sometimes becomes unresponsive or otherwise consumes a lot of CPU resource and even leaks memory. That is because of the misbehaving/malfunctioning flash plugin.

If you hate the flash plugin as much as I do, you can consider another way to enjoy streamed contents from those services.

Enter Livestreamer.

Livestreamer is a command line interface (CLI) client which, upon given a streaming URL, retrieves live streaming video from the URL, and pipes it into a native video player running on local host. So with Livestreamer, you can enjoy live streaming from various sources via a much stable and lightweight video player such as VLC or mplayer, without opening a web browser.

Currently, Livestreamer supports streaming from over 20 different web sites including Dailymotion, YouTube Live, Twitch/Justin.tv, Livestream and UStream.

In this tutorial, I will describe how to access live streaming from the command line with Livestreamer.

Install Livestreamer on Linux

To install Livestreamer on Debian, Ubuntu or Linux Mint:

$ sudo apt-get install python-pip
$ sudo pip install livestreamer

To install Livestreamer on Fedora, CentOS or RHEL:

$ sudo yum install python-pip
$ sudo pip install livestreamer

By default, Livestreamer attempts to pipe streaming video into VLC player. Thus you also need to install VLC player on your Linux system.

Watch Live Streaming from the Command Line with Livestreamer

To watch any live streaming channel/program, first obtain its corresponding URL from its official site.

For example, let's say the URL for the live streaming content that you want to watch is http://www.youtube.com/watch?v=U4Pw3ofFWgs

To check available streaming quality (i.e., bitrate) of the given content, simply run livestreamer command with the URL:

$ livestreamer http://www.youtube.com/watch?v=U4Pw3ofFWgs
[cli][info] Found matching plugin youtube for URL http://www.youtube.com/watch?v=U4Pw3ofFWgs
Available streams: 240p, 360p, 480p (best), 72p (worst)

To watch a live stream in the best available quality, run livestreamer command in the following format. This will automatically launch VLC player, and streaming will start on VLC.

$ livestreamer http://www.youtube.com/watch?v=U4Pw3ofFWgs best

To watch a live stream in specific streaming quality (e.g., 360p), run livestreamer as follows.

$ livestreamer http://www.youtube.com/watch?v=U4Pw3ofFWgs 360p

If you have your own favorite streaming player, you can let Livestreamer launch the player instead of default VLC, as follows.

$ livestreamer --player=mplayer http://www.youtube.com/watch?v=U4Pw3ofFWgs 360p

Livestreamer supports an external configuration file, where you can specify frequently used options for Livestreamer. The configuration file is useful especially when you are trying to access content in the subscription channels which require authentication. In such cases, you can specify whatever required access credentials (e.g., password, OAuth token, cookie, etc) in the configuration files.

Livestreamer configuration file can be created at either ~/.config/livestreamer/config or ~/.livestreamerrc

The configuration file should contain one option per line in the format: option[=value]

For example:

http-proxy=http://hostname:port/
https-proxy=https://hostname:port/
player=mplayer -cache 2048

Subscribe to Xmodulo

Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.

The following two tabs change content below.
Dan Nanni is the founder and also a regular contributor of Xmodulo.com. He is a Linux/FOSS enthusiast who loves to get his hands dirty with his Linux box. He likes to procrastinate when he is supposed to be busy and productive. When he is otherwise free, he likes to watch movies and shop for the coolest gadgets.
Your name can also be listed here. Write for us as a freelancer.

22 thoughts on “How to watch live streaming video from the command line on Linux

  1. This seems ridiculous....why can't I just open VLC and type in the URL?

    This isn't really watching it from the command line, just launching the correct app.

    • It doesn't seem ridiculous to me.

      It's so much easier to use cli than native gui. besides it has far more ways to customize the streaming settings automatically for different services.

      • But it's not really cli....it just launches VLC (or your default player), something you could almost do with gnome-open if it supported urls.

        • It's not simply launching an app. It's piping streaming. It even offers APIs so that any other custom app you want can get the streaming from it, in all automatic fashion. No need to worry about service specific details (like authentication). That's neat.

        • No, you can't. VLC cannot stream directly from those pages; they are meant to be streamed in a browser. That's why someone made a clever script that gets the video stream and pipes it into whatever player (VLC in this case) that shows it on your screen. Or saves the stream to a file for watching later. There are browser plugins that do similar stuff, but in my experience they are quite limited.

  2. It is easy to spot that in the first commands the keyword install has been forgotten. So it should be:
    sudo apt-get install python-pip
    and for centos
    sudo yum install python-pip

  3. Dissappointed. I thought this was going to be something clever like turning the video stream into ascii art so it can be watched on machines with no GUI.

  4. This seems useless. If I'm already on Youtube (or whatever streaming site) why the extra steps? why can't just watch it on Youtube or whatever?. Plus you get to see comments and interact with viewers.

  5. yeah, it's hardly a cli. that's a terminal no X

    and what's with all this yum apt-get garbage,
    also, real CLI users, use REAL OS's, so how about referencing the homepage, or link to source pkgs

    ...if I want a click and install OS. i'd be using winblows

  6. I think it is neat that someone made a tool of this nature. +Michael Leo I agree that from a modern desktop perspective this may seem tedious, but it would be easy to build a GUI into it by using bindings of a toolkit, or even dialogs. To that effort, one could extend that further and make a plugin for a media player. Interesting post.

  7. VLC already natively supports this functionality. But it's still a good way to circumvent the high cpu usage often experienced with Linux flash apps.

Leave a comment

Your email address will not be published. Required fields are marked *

Current ye@r *