Closed ahmadwali closed 11 years ago
Dear @chrippa,
Also this URL does not work http://www.ustream.tv/channel/Αρτ-tv with livestreamer. Probably they are using something different on those channels.
UStream has an alternative API for fetching streams and it seems like some channels are using this exclusively now. Problem is that this API is RTMP based and AFAIK there is no Python implementation of RTMP that is compatible with both Python 2 and 3, which is a requirement for any Livestreamer code. Therefore it looks unlikely that this bug will be solved any time soon unfortunately.
In order to build rtmp
into Livestreamer we need amf
and rtmp
protocol and rtmpclient
rtmplite
is one implementation (but don't know if they are Python 3 compatible)
http://code.google.com/p/rtmplite/source/browse/trunk/amf.py http://code.google.com/p/rtmplite/source/browse/trunk/rtmp.py http://code.google.com/p/rtmplite/source/browse/trunk/rtmpclient.py
rtmp-python
+ PyAMF
is another implementation (but don't know if they are Python 3 compatible)
https://github.com/hydralabs/pyamf https://github.com/prekageo/rtmp-python/blob/master/rtmp_protocol.py https://github.com/prekageo/rtmp-python/blob/master/sample_rtmp_client.py
python-flashmedia
is your implementation and since https://github.com/chrippa/python-flashmedia/commit/95da34a10c52072240aa8e9cb8d3babfa3479553 there is some progress (from you of course) adding AMF 3
.
Maybe add the missing AMF
parts into python-flashmedia
?
Edit1. Using librtmp from python is it possible to use API? (eg https://gist.github.com/athoik/5484842 )
Maybe add the missing AMF parts into python-flashmedia?
AMF support is pretty much done, but RTMP is a fairly complex protocol so I don't think I will add it to python-flashmedia anytime soon, if at all.
Using librtmp from python is it possible to use API? (eg https://gist.github.com/athoik/5484842 )
Using librtmp is probably the simplest option indeed. I'd rather write some Python bindings for librtmp than patching pyamf/rtmplite to support Python 3 since I don't know if they are even up to date with latest RTMP protocol, at least librtmp is still developed and fairly complete.
Dear @chrippa,
I thing we can use HLS
when no RTMP
streams found on UstreamTV module, or use it as a second option when rtmp stream exists.
athoik@pc:~$ livestreamer http://www.ustream.tv/channel/egnatiatv best -l debug
[cli][info] Found matching plugin ustreamtv for URL http://www.ustream.tv/channel/egnatiatv
[plugin.ustreamtv][debug] Fetching stream info
error: No streams found on this URL: http://www.ustream.tv/channel/egnatiatv
The above channel has cid = 6945431, we can use the following URL http://iphone-streaming.ustream.tv/uhls/6945431/streams/live/iphone/playlist.m3u8
It doesn't work directly (first we have to open the url as hls://
and then as hlsvariant://
)
athoik@pc:~$ livestreamer hlsvariant://http://iphone-streaming.ustream.tv/uhls/6945431/streams/live/iphone/playlist.m3u8 best -l debug
[cli][info] Found matching plugin stream for URL hlsvariant://http://iphone-streaming.ustream.tv/uhls/6945431/streams/live/iphone/playlist.m3u8
error: No streams found on this URL: hlsvariant://http://iphone-streaming.ustream.tv/uhls/6945431/streams/live/iphone/playlist.m3u8
athoik@pc:~$ livestreamer hls://http://iphone-streaming.ustream.tv/uhls/6945431/streams/live/iphone/playlist.m3u8 best -l debug[cli][info] Found matching plugin stream for URL hls://http://iphone-streaming.ustream.tv/uhls/6945431/streams/live/iphone/playlist.m3u8
[cli][info] Opening stream: live
[stream.hls][debug] Starting buffer filler thread
[stream.hls][debug] Reloading playlist
[stream.hls][debug] Adding sequence 0 to queue
[stream.hls][debug] Adding sequence 1 to queue
[cli][debug] Pre-buffering 8192 bytes
[cli][info] Starting player: vlc
[cli][debug] Writing stream to output
[stream.hls][debug] Reloading playlist
[stream.hls][debug] Reloading playlist
[stream.hls][debug] Download of sequence 0 complete
[stream.hls][debug] Download of sequence 1 complete
[stream.hls][debug] Reloading playlist
[stream.hls][debug] Reloading playlist
[stream.hls][debug] Reloading playlist
[stream.hls][debug] Reloading playlist
[stream.hls][debug] Reloading playlist
[stream.hls][debug] Reloading playlist
^C
athoik@pc:~$ livestreamer hvariant://http://iphone-streaming.ustream.tv/uhls/6945431/streams/live/iphone/playlist.m3u8 best -l debug
[cli][info] Found matching plugin stream for URL hlsvariant://http://iphone-streaming.ustream.tv/uhls/6945431/streams/live/iphone/playlist.m3u8
[cli][info] Opening stream: 240p
[stream.hls][debug] Starting buffer filler thread
[stream.hls][debug] Reloading playlist
[stream.hls][debug] Adding sequence 1 to queue
[stream.hls][debug] Adding sequence 2 to queue
[stream.hls][debug] Adding sequence 3 to queue
[cli][debug] Pre-buffering 8192 bytes
[cli][info] Starting player: vlc
[cli][debug] Writing stream to output
[cli][info] Player closed
[stream.hls][debug] Buffer filler thread completed
[cli][info] Stream ended
Using VLC this works too.
athoik@pc:~$ vlc --http-user-agent="Mozilla/5.0 (iPhone; CPU iPhone OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9B179 Safari/7534.48.3" http://iphone-streaming.ustream.tv/uhls/6945431/streams/live/iphone/playlist.m3u8
VLC media player 2.0.5 Twoflower (revision 2.0.5-0-g1661b7d)
[0x8725908] main libvlc: Running vlc with the default interface. Use 'cvlc' to use vlc without interface.
Got bus address: "unix:abstract=/tmp/dbus-vd8hlbJO5W,guid=3463127796e914f8d683fad300000216"
Connected to accessibility bus at: "unix:abstract=/tmp/dbus-vd8hlbJO5W,guid=3463127796e914f8d683fad300000216"
Registered DEC: true
Registered event listener change listener: true
[0xb7209838] stream_filter_httplive stream: HTTP Live Streaming (iphone-streaming.ustream.tv/uhls/6945431/streams/live/iphone/playlist.m3u8)
[0xb7209838] stream_filter_httplive stream: Meta playlist
[0xb7209838] stream_filter_httplive stream: bandwidth adaptation detected (program-id=1, bandwidth=389343).
[0xb7209838] stream_filter_httplive stream: Live Playlist HLS protocol version: 1
[0xb7209838] stream_filter_httplive stream: Choose segment 0/3 (sequence=43)
[0xb7209838] stream_filter_httplive stream: downloaded segment 43 from stream 0
[0xb7209838] stream_filter_httplive stream: downloaded segment 44 from stream 0
[0xb7209838] stream_filter_httplive stream: playing segment 43 from stream 0
libdvbpsi error (PSI decoder): TS discontinuity (received 12, expected 0) for PID 17
libdvbpsi error (PSI decoder): TS discontinuity (received 12, expected 0) for PID 0
libdvbpsi error (PSI decoder): TS discontinuity (received 12, expected 0) for PID 4095
[0xb7209a78] ts demux error: MPEG-4 descriptor not found
[0xb3cac420] packetizer_mpeg4audio packetizer: AAC channels: 1 samplerate: 44100
[0x876bf20] freetype spu text error: Breaking unbreakable line
[0xb7209838] stream_filter_httplive stream: downloaded segment 45 from stream 0
[0xb7209838] stream_filter_httplive stream: playing segment 44 from stream 0
[0xb7209838] stream_filter_httplive stream: Reloading HLS live meta playlist
[0xb7209838] stream_filter_httplive stream: Live Playlist HLS protocol version: 1
[0xb7209838] stream_filter_httplive stream: updating hls stream (program-id=1, bandwidth=389343) has 3 segments
[0xb7209838] stream_filter_httplive stream: - segment 46 appended
[0xb7209838] stream_filter_httplive stream: Reloading HLS live meta playlist
[0xb7209838] stream_filter_httplive stream: Live Playlist HLS protocol version: 1
[0xb7209838] stream_filter_httplive stream: updating hls stream (program-id=1, bandwidth=389343) has 3 segments
[0xb7209838] stream_filter_httplive stream: playing segment 45 from stream 0
[0xb7209838] stream_filter_httplive stream: Reloading HLS live meta playlist
[0xb7209838] stream_filter_httplive stream: Live Playlist HLS protocol version: 1
[0xb7209838] stream_filter_httplive stream: updating hls stream (program-id=1, bandwidth=389343) has 3 segments
[0xb7209838] stream_filter_httplive stream: downloaded segment 46 from stream 0
[0xb7209838] stream_filter_httplive stream: - segment 47 appended
[0xb7209838] stream_filter_httplive stream: Reloading HLS live meta playlist
[0xb7209838] stream_filter_httplive stream: Live Playlist HLS protocol version: 1
[0xb7209838] stream_filter_httplive stream: updating hls stream (program-id=1, bandwidth=389343) has 3 segments
[0xb7209838] stream_filter_httplive stream: downloaded segment 47 from stream 0
[0xb7209838] stream_filter_httplive stream: Reloading HLS live meta playlist
[0xb7209838] stream_filter_httplive stream: playing segment 46 from stream 0
[0xb7209838] stream_filter_httplive stream: Live Playlist HLS protocol version: 1
[0xb7209838] stream_filter_httplive stream: updating hls stream (program-id=1, bandwidth=389343) has 3 segments
[0xb7209838] stream_filter_httplive stream: - segment 48 appended
[0xb7209838] stream_filter_httplive stream: Reloading HLS live meta playlist
[0xb7209838] stream_filter_httplive stream: Live Playlist HLS protocol version: 1
[0xb7209838] stream_filter_httplive stream: updating hls stream (program-id=1, bandwidth=389343) has 3 segments
...
Maybe It would be nice also to be able to setup User Agent on HLS module but this probably related with https://github.com/chrippa/livestreamer/issues/126.
Probably livestreamer cannot handle directly the HLS from ustream.tv because there are using the #EXT-X-DISCONTINUITY
tag.
Downloading the playlist is like this:
#EXTM3U
#EXT-X-ALLOW-CACHE:NO
#EXT-X-TARGETDURATION:6
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-PLAYLIST-TYPE:EVENT
#EXT-X-DISCONTINUITY
#EXTINF:6,
http://cdn1.ustream.tv/preroll/preroll3.ts?n=1371405952
#EXT-X-DISCONTINUITY
Then downloading the playlist with hls://
we are getting #PROGRESSED
tag.
#EXTM3U
#EXT-X-ALLOW-CACHE:NO
#EXT-X-TARGETDURATION:6
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-PLAYLIST-TYPE:EVENT
#EXT-X-DISCONTINUITY
#EXTINF:6,
http://cdn1.ustream.tv/preroll/preroll3.ts?n=1371405991
#EXT-X-DISCONTINUITY
#PROGRESSED 50%
And then we are getting the following m3u8 witch is opening with hlsvariant://
not with hls://
#EXTM3U
#EXT-X-ALLOW-CACHE:NO
#EXT-X-TARGETDURATION:6
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-PLAYLIST-TYPE:EVENT
#EXT-X-DISCONTINUITY
#EXTINF:6,
http://cdn1.ustream.tv/preroll/preroll3.ts?n=1371405910
#EXT-X-DISCONTINUITY
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=146054,CODECS="avc1.77.13, mp4a.40.2",RESOLUTION=320x240
http://iphone-streaming.ustream.tv/sjc-uhls02/uhls/12548227/streams/live_3/iphone/playlist.m3u8
Probably we need to handle reload of playlist using variant parsing when tag #EXT-X-DISCONTINUITY
exists.
Some info of #EXT-X-DISCONTINUITY
tag are here: Technical Note TN2288
Supporting discontinuities is not possible in Livestreamer since we do not control the playback.
What is suppose to happen with this playlist is:
Number 2 is necessary since the next part is likely to be a different resolution/encoding setting. If we were to simply continue to stream the data we would just end up with a broken stream that the player would refuse to play when it encounters changes.
Closest we can get is to attempt to parse the playlist as variant first, if this fails return a regular HLSStream that will contain the preroll segment. After this finished playing the user will hopefully retry to access the channel and the variant playlist be available this time.
In this case though I'm not sure it's a good idea to brute force access to the HLS playlist. I've encounted playlists that are stuck on the preroll with '#PROGRESSED 0%' forever. I might look into what the android app does to see if there is a another API available for HLS.
Actually there is a solution here
Opening the following link the playlist is starting #PROGRESSED
immediatelly.
http://iphone-streaming.ustream.tv/uhls/%s/streams/live/iphone/playlist.m3u8?appType=11&appVersion=2
Created a new issue to track status of this problem, #144.
I'm trying this ustream channel; livestreamer http://www.ustream.tv/channel/onetv-afghanistan live
But its giving this error;
[cli][info] Found matching plugin ustreamtv for URL http://www.ustream.tv/channel/onetv-afghanistan [cli][error] No streams found on this URL: http://www.ustream.tv/channel/onetv-afghanistan
The link above is working perfect in ustream website and in embed. Has ustream change something or am I doing something wrong? With livestream website channels I have no problem!