Pipe a HLS m3u8 to /dev/stdout using hlsdemux2

Hi,

I’m looking to use GStreamer to pipe a HLS m3u8 from the Internet to stdout, making sure I use hlsdemux2 and hlssink2 (if needed?), without reencoding the stream. I’m using GStreamer in Ubuntu.

This command does not work:

gst-launch-1.0 -q souphttpsrc location=“URL” ! hlsdemux2 ! hlssink2 location=/dev/stdout

What is the correct way to do this?

I was using ffmpeg but it does not support EXT-X-DISCONTINUITY, which hlsdemux2 does. For reference, this is the command I’m using:

ffmpeg -loglevel warning -i URL -c copy -f hls pipe:1

Thank you for the help.

Assuming there is only one elementary stream, something like below would work

gst-launch-1.0 urisourcebin uri=<HLS url> ! queue ! hlssink2

This might not work, if the HLS stream has multiple variant streams or renditions. Note that hlsdemux2 or adaptivedemux2 plugin outputs parsed elementary streams, one for each available media type. Also note that, urisourcebin will use hlsdemux2 underneath.

If you just want the original segments, you might want to use one of the HLS downloader tools out there.

Is your HLS playlist, a multi-variant/master playlist or a media playlist?

It did not work. And I need to pipe to stdout. Any idea?

gst-launch-1.0 urisourcebin uri=https://spt-sonyoneemocoes-1-br.samsung.wurl.tv/playlist.m3u8 ! queue ! hlssink2

Log:

Setting pipeline to PAUSED ...
Pipeline is PREROLLING ...
Got context from element 'souphttpsrc0': gst.soup.session=context, session=(GstSoupSession)NULL;
Redistribute latency...
ERROR: from element /GstPipeline:pipeline0/GstURISourceBin:urisourcebin0/GstHLSDemux2:hlsdemux2-0: Internal data stream error.
Additional debug info:
../ext/adaptivedemux2/gstadaptivedemux.c(3606): gst_adaptive_demux_output_loop (): /GstPipeline:pipeline0/GstURISourceBin:urisourcebin0/GstHLSDemux2:hlsdemux2-0:
streaming stopped, reason not-negotiated (-4)
ERROR: pipeline doesn't want to preroll.
Setting pipeline to NULL ...
Freeing pipeline ...

Can you give the below pipeline a try?

gst-launch-1.0 -v urisourcebin uri=https://spt-sonyoneemocoes-1-br.samsung.wurl.tv/playlist.m3u8 name=demux connection-speed=1000 \
  hlssink2 name=hlssink \
  demux. ! audio/mpeg ! aacparse ! queue name=audio_queue ! hlssink.audio \
  demux. ! video/x-h264 ! h264parse ! queue name=video_queue ! hlssink.video

The playlist seems to be a multi-variant playlist with 3 variant streams for video.

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-MEDIA:TYPE=CLOSED-CAPTIONS,GROUP-ID="captions",NAME="Portuguese",DEFAULT=NO,LANGUAGE="por",INSTREAM-ID="CC1"
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=921600,CODECS="avc1.4d0029,mp4a.40.2",RESOLUTION=640x360,CLOSED-CAPTIONS="captions"
1200.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=2048000,CODECS="avc1.4d0029,mp4a.40.2",RESOLUTION=960x540,CLOSED-CAPTIONS="captions"
2000.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=3072000,CODECS="avc1.4d0029,mp4a.40.2",RESOLUTION=1280x720,CLOSED-CAPTIONS="captions"
3000.m3u8

The connection-speed property can be changed depending on the bandwidth and resolution required. For connection-speed=1000, the lowest resolution will be selected.