Posts Tagged ubuntu
hls-player: A working Python m3u8 (live http streaming) player
Introduction:
Working m3u8 players on Ubuntu, (and possibly Windows) aren’t all that common at the moment. While vlc seems to deal with almost any video thrown at it, it does seem to struggle with m3u8 streams such as those used by Veetle. Fortunately, there’s a solution: hls-player. The player is written in Python, and while it isn’t perfect, works more-or-less out of the box.
Download and hacking:
Download the tarball and decompress somewhere. There’s a few changes I’d recommend which might make the code a little more stable. In the HLS subfolder, open the file m3u8.py with a text editor and edit line 26 and 27 from:
self._reload_delay = None # the initial reload delay self._update_tries = None # the number consecutive reload tries
to:
self._reload_delay = 2 # the initial reload delay self._update_tries = 10 # the number consecutive reload tries
The video player is GStreamer based. As it is currently written, it won’t allow you to vary the aspect ratio by resizing the window. If you want more flexibility, open the player.py file in a text editor (in the same directory as m3u8.py). Around about line 163, you should find a line:
imagesink.set_property("force-aspect-ratio", True)
Change it to:
imagesink.set_property("force-aspect-ratio", False)
Installation:
Make sure you have Python installed (there may be dependencies that might require installing and which you will be told about, such as the twisted library). Enter the directory where you decompressed the tarball. It should have a setup.py file. At the console type:
sudo python setup.py install
…and after entering your password, the setup should be complete.
Usage:
Console-based, I’m afraid. Get the url for an m3u8 stream such as http://www.nasa.gov/multimedia/nasatv/NTV-Public-IPS.m3u8
Then type:
hls-player http://www.nasa.gov/multimedia/nasatv/NTV-Public-IPS.m3u8
A window will appear and, all going well, video will start to play within a few seconds.
Warning:
Mileage may vary. The player still has a few bugs (maybe I’m being unfair, but it still freezes/crashes out occasionally for me). It runs reasonably for me under Ubuntu 10.10 and Python 2.6.6 (with the changes above). Sometimes it freezes for a few seconds. Usually it recovers. Under windows or other *nixes, you might have less luck.
