Watch Live Video of Earth on your Raspberry Pi

Posted by
on under

A few weeks ago NASA started streaming live video of Earth from cameras installed aboard the International Space Station (ISS), and some of the views are nothing short of breathtaking. If you haven't seen this stream yet, then stop reading and go watch it now. Keep in mind that you have a 50% chance of catching the dark part of the planet, so if all you find is an all black image then try again a little later. You can always check to find out over which region the ISS is over and if it is day or night there.

I thought it would be a cool idea to have this stream running constantly on a screen by my desk. Something I can keep an eye on while I work, so that I can catch the most interesting views without having to have it constantly taking space on my main computer's screens.

In this short article I'm going to show you how to play the ISS live stream on your Raspberry Pi.

Playing Video Streams on the Raspberry Pi

The Raspberry Pi is well equipped for the task of playing video streams because it can decode the video in the GPU, so the amount of work done in the CPU is minimal. The Pi's GPU comes with a H.264 video decoder from the factory. This is the format most web based video streams use, including the ISS stream. As a side note, an MPEG-2 decoder is also available, but a license needs to be purchased from the Raspberry Pi Foundation to use it.

The ISS live stream is provided by UStream. The stream is delivered in short segments, presented to the player in a constantly changing playlist, using a format called HLS. But UStream does not openly advertise how to access these playlists, instead they expect clients to embed a UStream web based video player applet based on Flash or HTML5, where all the HLS processing is done.

Unfortunately playing this type of stream in a browser on the Raspberry Pi is kind of complicated, as you need a modern browser that can run their Flash/HTML5 video player, and on top of that you need the player to be specifically designed to use the hardware accelerated decoder in the Pi. So in my view, using a web browser for this project is not an option.

I have found that omxplayer is a pretty good command line player, specifically created for the Pi and with support for hardware decoding. To use omxplayer you do not even need to be running the graphical environment, the video plays as an overlay, even on top of the console. Recent releases of Raspbian include omxplayer, so chances are you already have it installed. If not, you can always install it:

$ sudo apt-get install omxplayer

But how do we connect the HLS stream from UStream to omxplayer?

The livestreamer utility helps simplify the process of downloading video from UStream and other video stream providers. This tool does all the processing and converts the stream to a standard video file that can be sent to a player like omxplayer. To install livestreamer you have to run the following commands:

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

For those of you that know their way around Python, you should know that livestreamer is written in that language, and that it can be installed in a virtual environment if you prefer to keep it separate from your system Python interpreter.

The command that combines livestream and omxplayer and starts the ISS stream in full screen mode is as follows:

$ livestreamer mobile_480p --player omxplayer --fifo

The first argument is the URL for the streaming channel. This is followed by "mobile_480p" which tells livestreamer to select one of the available resolutions for the given channel (the list of choices are printed to the console). Livestreamer by default will try to launch the stream on VLC, so we use --player to tell it to use omxplayer instead. Finally, the --fifo argument selects the use of a named pipe as a mechanism for livestreamer to communicate with omxplayer.

If you try the above command you may find that everything works great, so you are good to go. In my case, however, I've found that the playback window did not cover the entire screen. The reason is that omxplayer by default plays at 1920x1080, but I have my console running at 1600x1200. This is easy to fix using the --win argument:

$ livestreamer mobile_480p --player omxplayer --fifo \
> --player-args "--win \"0 0 1600 1200\" {filename}"

If you are running under a different resolution you may need to play with the numbers given to --win to make the video fill your screen.

Final Touches

If you try this you will find that from time to time the stream halts and you are sent back to the command line. This is probably some sort of interruption to the stream that causes omxplayer to error. But whatever causes this resolves pretty fast, because the video is back up a couple of seconds later after restarting the process.

To avoid having to manually restart the process each time it stops, a wrapper bash script can be created to do this for us:

while true
    livestreamer mobile_480p --player omxplayer --fifo --player-args "--win \"0 0 1600 1200\" {filename}"

If you put the above in a file named iss-streamer you can make it executable and run it as a command:

$ chmod +x iss-streamer
$ ./iss-streamer

And now the stream will restart itself whenever there is an interruption. Note that when you do want to stop the stream, you will have to hold the Ctrl+C for a couple of seconds to also break out of the while loop in the bash script.

I thought it would also be useful to have the stream autostart when the Pi is plugged in, so that it can run completely unattended. This is achieved by adding the command to the /etc/rc.local file, right before the exit 0 line:

# start the ISS video stream
sudo -u pi /home/pi/iss/iss-streamer >/dev/null 2>&1 &

There are a few details that were required to make the stream work. First of all, the /etc/rc.local script runs as the root user, so I use sudo to downgrade the user to the regular "pi" user as a safety measure. The command needs to run in the background, so I added & at the end. And because it runs in the background, I also suppressed all the output from stdout and stderr. Finally, since the PATH environment variable is not set when the command runs, I specified the full path to the iss-streamer script.

The End

I hope you find this entertaining, fascinating and mind blowing as I do. Obviously this technique can be used with many other internet streams, so feel free to experiment!

If you have any tips to improve this idea be sure to let me know in the comments below!

Become a Patron!

Hello, and thank you for visiting my blog! If you enjoyed this article, please consider supporting my work on this blog on Patreon!

  • #1 Aba Even said

    Works great. Awesome!

  • #2 Miguel Maldonado said

    Thanks, this is working great...transferred streaming video to large screen. My daughter loves it..!

  • #3 Liam Kennedy said

    Great post. Thanks for sharing. I could never get the mobile_480p stream to come up. I installed a couple of additional libraries (libffi-dev and python-librtmp I think) and then I managed to get the 720p+ and 480p_alt_akamai stream to work just perfectly.

  • #4 Chinna said

    Hi, very nice project! How can I make the video to be played only when somebody is near to the display. I know, I should use a PIR detector, but I don't know the code. Could you please point me in the right direction.

  • #5 Stuart said

    I get python-librtmp is not installed and no streams found on this URL

    Any ideas please?? Thanks.

  • #6 Miguel Grinberg said

    @Stuart: I just tested this, and only the HD resolutions need librtmp, there are mobile resolutions up to 480p that play fine without that. But in any case, you can run "sudo apt-get install librtmp-dev", "pip install cffi" and finally "pip install python-librtmp". Then the HD streams should be accessible as well.

  • #7 David said

    Great tutorial! I'm going to add this to my laundry list of "Raspberry Pi Projects". I just thought of a cool enhancement to this. I think it'd be great if you could snap an HD screenshot of the feed if you happen to see something particularly beautiful and want to capture it.

  • #8 Jeremie said

    Sounds great I'll give it a go!!

    Would it be possible to have this live street as a background on your desktop rather than on a seperate screen?

  • #9 Miguel Grinberg said

    @Jeremie: I'm not sure, I haven't really tried to do it as a live wallpaper. This StackOverflow question may give you some ideas:

  • #10 Raj said

    Hey Miguel, great tutorial. Thanks. I've followed it and got the stream running on my new Pi. My problem is that once I get to the 'Final touches' section of your guide I'm lost. You say 'a wrapper bash script can be created' and show us she script itself but I don't actually know how to go about creating it! it was so step by step before. I'm sure its super simple for someone with experience in linux but for those of us new to linux and the pi, its a missing step. Little help for a noob please?

    I'd love to follow your guide through to the end so i can have the stream auto start with my pi so it can run unattended.

  • #11 Miguel Grinberg said

    @Raj: you need to use your favorite text editor to create the script. You will also need a text editor for the next step, when you need to edit the /etc/rc.local file. An easy to use text editor is "nano", which should be already installed in your Pi.

  • #12 Kalpesh said

    Hey Miguel, Great mind blowing tutorial. after reading this i bought new raspberry pi 2 yesterday to test this. im a totally new to all this. will do first time. basically i want to play Adaptive HLS stream with .m3u8 extension from Akamai. can you please help and give more detail tutorial for new learner like do i need to use micro sd card in new pi 2 model? if yes then which os i need to install on that and what extension do i have to give to bash file after editing in text editor. sorry for asking dummy question and will be thank full to you for the help.

  • #13 Miguel Grinberg said

    @Kalpesh: Try the latest release of Raspbian, that is the most user-friendly OS for the Pi, in my opinion.

  • #14 jef said

    Great information, works very well, thanks :)

  • #15 kalpesh said

    hi miguel: finally i started playing stream with adding hlsvariant:// after livestreamer and before my .m3u8 link. the omxplayer plays it successfully for 30 seconds only then it exits but same with mplayer plays fine in small screen please help me playing in omxplayer more then 30 second...

  • #16 Momanon said

    Thanks for this info! I was able to get this running on my Raspberry Pi 2 using NOOBS. I've just been leaving it up all the time. This "payload" link seems to have better views than their main ustream channel.

  • #17 Nick said

    Hi. Thanks for all this work.

    I keep getting the error...

    error: No streams found on this URL:

    Any ideas?

  • #18 Miguel Grinberg said

    @Nick: looks like the video streaming is going to be offline between March 20 and 23. Try again in a couple of days.

  • #19 waymon said

    @miguel What would be the URL to the HD streams? I installed both librtmp-dev and python-librtmp but do not know the URL to the HD stream. Any advice?

    Thanks for the great write up!

  • #20 Miguel Grinberg said

    @waymon: It's the same URL. You have to use "720p+" instead of "mobile_480p".

  • #21 Liam Kennedy said

    Or just use "best" and you will get the current best stream available (which would usually be 720p+). I have found sometimes not all stream quality types are available - so using "best" seems to be more reliable.

  • #22 Marc said

    Miguel, Thank you for the whole write up and programming lines to get a full screen video stream. I'm currently running Ubuntu (on a PC) and I would like to setup up a 'system' where I click on a button and it not only goes to a specific site with a live stream, but also automatically makes the stream full screen. You can imagine, this would be so cool to be able to simply double click on an icon and have the 'TV Channel' full screen. If I can get this right I would then like to transfer the code to a Raspberry Pi project that has a small monitor with the ability to select TV Channels.
    Your help would be greatly appreciated.

  • #23 Miguel Grinberg said

    @Marc: your problem is unrelated to the video streaming, you just need to figure out how to start an application full screen in the window manager that you are using, or what command options to include in the start up command for the video player to make it go full screen.

  • #24 RV said

    Can this be used to stream as well? I would love to be able to watch Nasa TV on my home TV. I have a Pi.

  • #25 Miguel Grinberg said

    @RV: I think so. I don't have my Pi at hand right now to try, but I think if you use URL you'll get the main Nasa channel.

Leave a Comment