Cannot process HLS stream with Gstreamer / FFmpeg
AnsweredOur goal is to re-stream streams from Nx Meta to our app, and we considering using HLS streams for it. We are using Gstreamer API for media processing, but having trouble to ingest these streams:
gst-launch-1.0 -v souphttpsrc location="https://{system_id}.relay.vmsproxy.com/hls/{device_id}.m3u" extra-headers="extra-headers, x-runtime-guid=(string){token}, host=(string){system_id}.relay.vmsproxy.com" ! hlsdemux ! decodebin ! videoconvert ! x264enc ! mp4mux ! filesink location=output.mp4
Here is output:
Setting pipeline to PAUSED ...
Pipeline is PREROLLING ...
Got context from element 'souphttpsrc0': gst.soup.session=context, session=(GstSoupSession)NULL;
ERROR: from element /GstPipeline:pipeline0/GstHLSDemux:hlsdemux0: Could not open resource for reading.
Additional debug info:
../ext/hls/gsthlsdemux.c(811): gst_hls_demux_process_manifest (): /GstPipeline:pipeline0/GstHLSDemux:hlsdemux0:
Could not fetch media playlist: Bad Gateway: ../ext/soup/gstsouphttpsrc.c(1690): gst_soup_http_src_parse_status (): /GstSoupHTTPSrc:souphttpsrc1:
Bad Gateway (502), URL: https://eabweyb.relay.vmsproxy.com:443/hls/4c077800-6596-9a33-797e-f6018ee9f3c4.m3u?authKey=e58b6e95-d765-4d9c-a49a-2596b9812d1a&chunked&sessionID=24&hi, Redirect to: (NULL)
ERROR: pipeline doesn't want to preroll.
ERROR: from element /GstPipeline:pipeline0/GstHLSDemux:hlsdemux0: Invalid manifest.
Additional debug info:
../gst-libs/gst/adaptivedemux/gstadaptivedemux.c(690): gst_adaptive_demux_sink_event (): /GstPipeline:pipeline0/GstHLSDemux:hlsdemux0
Setting pipeline to NULL ...
ERROR: pipeline doesn't want to preroll.
Freeing pipeline ...
If you are not familiar with gstreamer I tried to do the same with ffmpeg:
ffmpeg -headers "x-runtime-guid: {token}"$'\r\n'"host: {system_id}.relay.vmsproxy.com"$'\r\n' -i "https://{system_id}.relay.vmsproxy.com/hls/{device_id}.m3u" -c copy output.mp4
Here is ffmpeg log:
Opening an input file: https://{system_id}.relay.vmsproxy.com/hls/{device_id}.m3u8.
[NULL @ 0x55d83f744780] Opening 'https://{system_id}.relay.vmsproxy.com/hls/{device_id}.m3u8' for reading
[https @ 0x55d83f745480] Setting default whitelist 'http,https,tls,rtp,tcp,udp,crypto,httpproxy'
[tcp @ 0x55d83f748a40] Original list of addresses:
[tcp @ 0x55d83f748a40] Address 195.181.174.35 port 443
[tcp @ 0x55d83f748a40] Interleaved list of addresses:
[tcp @ 0x55d83f748a40] Address 195.181.174.35 port 443
[tcp @ 0x55d83f748a40] Starting connection attempt to 195.181.174.35 port 443
[tcp @ 0x55d83f748a40] Successfully connected to 195.181.174.35 port 443
[https @ 0x55d83f745480] request: GET /hls/{device_id}.m3u8 HTTP/1.1
User-Agent: Lavf/58.76.100
Accept: */*
Range: bytes=0-
Connection: close
Icy-MetaData: 1
x-runtime-guid: {token}
host: {system_id}.relay.vmsproxy.com
[tcp @ 0x55d83f9f8e80] Original list of addresses:
[tcp @ 0x55d83f9f8e80] Address 138.199.41.85 port 443
[tcp @ 0x55d83f9f8e80] Interleaved list of addresses:
[tcp @ 0x55d83f9f8e80] Address 138.199.41.85 port 443
[tcp @ 0x55d83f9f8e80] Starting connection attempt to 138.199.41.85 port 443
[tcp @ 0x55d83f9f8e80] Successfully connected to 138.199.41.85 port 443
[https @ 0x55d83f745480] request: GET /hls/{device_id}.m3u8 HTTP/1.1
User-Agent: Lavf/58.76.100
Accept: */*
Range: bytes=0-
Connection: close
Icy-MetaData: 1
x-runtime-guid: {token}
host: {system_id}.relay.vmsproxy.com
[hls @ 0x55d83f744780] Format hls probed with size=2048 and score=100
[hls @ 0x55d83f744780] Opening 'https://scwhcxv.relay.vmsproxy.com:443/hls/{device_id}.m3u8?authKey=0ce15aa....f4fcdb4a4a&chunked&sessionID=13&hi' for reading
[tcp @ 0x55d83f847d40] Original list of addresses:
[tcp @ 0x55d83f847d40] Address 195.181.174.35 port 443
[tcp @ 0x55d83f847d40] Interleaved list of addresses:
[tcp @ 0x55d83f847d40] Address 195.181.174.35 port 443
[tcp @ 0x55d83f847d40] Starting connection attempt to 195.181.174.35 port 443
[tcp @ 0x55d83f847d40] Successfully connected to 195.181.174.35 port 443
[https @ 0x55d83f83cc40] request: GET /hls/{device_id}.m3u8?authKey=0ce15aa9-3bf8-4a90-8876-aff4fcdb4a4a&chunked&sessionID=13&hi HTTP/1.1
User-Agent: Lavf/58.76.100
Accept: */*
Range: bytes=0-
Connection: keep-alive
Icy-MetaData: 1
x-runtime-guid: {token}
host: {system_id}.relay.vmsproxy.com
[tcp @ 0x55d83f8441c0] Original list of addresses:
[tcp @ 0x55d83f8441c0] Address 138.199.41.85 port 443
[tcp @ 0x55d83f8441c0] Interleaved list of addresses:
[tcp @ 0x55d83f8441c0] Address 138.199.41.85 port 443
[tcp @ 0x55d83f8441c0] Starting connection attempt to 138.199.41.85 port 443
[tcp @ 0x55d83f8441c0] Successfully connected to 138.199.41.85 port 443
[https @ 0x55d83f83cc40] request: GET /hls/{device_id}.m3u8?authKey=0ce15aa9-3bf8-...4fcdb4a4a&chunked&sessionID=13&hi HTTP/1.1
User-Agent: Lavf/58.76.100
Accept: */*
Range: bytes=0-
Connection: keep-alive
Icy-MetaData: 1
x-runtime-guid: {token}
host: {system_id}.relay.vmsproxy.com
[tls @ 0x55d83f847ec0] Error in the pull function.
[hls @ 0x55d83f744780] parse_playlist error Invalid data found when processing input [https://scwhcxv.relay.vmsproxy.com:443/hls/{device_id}.m3u8?authKey=0ce15a...fcdb4a4a&chunked&sessionID=13&hi]
[AVIOContext @ 0x55d83fa34140] Statistics: 0 bytes read, 0 seeks
[AVIOContext @ 0x55d83fa071c0] Statistics: 201 bytes read, 0 seeks
https://{system_id}.relay.vmsproxy.com/hls/{device_id}.m3u8: Invalid data found when processing input
I think the problem appears when it tries to process link in .m3u playlist which looks something like this:
#EXTM3U
#EXT-X-STREAM-INF:BANDWIDTH=4194304
-
Hello,
Please try the following for troubleshooting.
Make sure the user account you're trying to authenticate with has the digest auth scheme enabled.
In VLC player open a network stream in format https://<your username>:<your password>@<system id>.relay.vmsproxy.com/hls/<camera id>.m3u
What is the result?
Please sign in to leave a comment.
Comments
2 comments