Restreaming hls stream to rtmp stream using ffmpeg

0

I am trying to re-stream an hls stream to rtmp stream using ffmpeg :

as example :

ffmpeg -loglevel debug -re \
  -i "https://hddn01.skylinewebcams.com/live.m3u8?a=c6kekc4h116t1m5jbtei273bq0" \
  -bufsize 4000k -preset ultrafast -vcodec libx264 -tune zerolatency \
  -b:v 900k -an -f flv rtmp://127.0.0.1/live/stream.flv

The stream is available on the website: https://www.skylinewebcams.com/en/webcam/malta/malta/traffic/traffic-cam2.html

The issue is that input fps value is very low and q value is very high or -1 most of the times.

Please take a look at the following log:

ffmpeg version 3.4.2-1~16.04.york0.2 Copyright (c) 2000-2018 the FFmpeg developers
  built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.9) 20160609
  configuration: --prefix=/usr --extra-version='1~16.04.york0.2' --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avi
synth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --e
nable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --e
nable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi
 --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
  libavutil      55. 78.100 / 55. 78.100
  libavcodec     57.107.100 / 57.107.100
  libavformat    57. 83.100 / 57. 83.100
  libavdevice    57. 10.100 / 57. 10.100
  libavfilter     6.107.100 /  6.107.100
  libavresample   3.  7.  0 /  3.  7.  0
  libswscale      4.  8.100 /  4.  8.100
  libswresample   2.  9.100 /  2.  9.100
  libpostproc    54.  7.100 / 54.  7.100
[hls,applehttp @ 0x5649bd7463e0] Opening 'https://hddn01.skylinewebcams.com/03042101ANC5-1544185331502.ts' for reading
[hls,applehttp @ 0x5649bd7463e0] Could not find codec parameters for stream 1 (Audio: aac ([15][0][0][0] / 0x000F), 0 channels, fltp): unspecified sample rate
Consider increasing the value for the 'analyzeduration' and 'probesize' options
Input #0, hls,applehttp, from 'https://hddn01.skylinewebcams.com/live.m3u8?a=c6kekc4h116t1m5jbtei273bq0':
  Duration: N/A, start: 22431.033000, bitrate: N/A
  Program 0 
    Metadata:
      variant_bitrate : 0
    Stream #0:0: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p, 1280x1024, 12 fps, 12 tbr, 90k tbn, 180k tbc
    Metadata:
      variant_bitrate : 0
    Stream #0:1: Audio: aac ([15][0][0][0] / 0x000F), 0 channels, fltp
    Metadata:
      variant_bitrate : 0
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
Press [q] to stop, [?] for help
[libx264 @ 0x5649bdc1ba80] VBV maxrate unspecified, assuming CBR
[libx264 @ 0x5649bdc1ba80] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0x5649bdc1ba80] profile Constrained Baseline, level 3.2
[libx264 @ 0x5649bdc1ba80] 264 - core 152 r2854 e9a5903 - H.264/MPEG-4 AVC codec - Copyleft 2003-2017 - http://www.videolan.org/x264.html - options: cabac=0 ref=1 deblock=0:0:0 analyse=0:0 me=dia subme=0 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=4 lookahead_threads=4 sliced_threads=1 slices=4 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=0 keyint=250 keyint_min=12 scenecut=0 intra_refresh=0 rc_lookahead=0 rc=cbr mbtree=0 bitrate=900 ratetol=1.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 vbv_maxrate=900 vbv_bufsize=4000 nal_hrd=none filler=0 ip_ratio=1.40 aq=0
Output #0, flv, to 'rtmp://127.0.0.1/live/dhruv.flv':
  Metadata:
    encoder         : Lavf57.83.100
    Stream #0:0: Video: h264 (libx264) ([7][0][0][0] / 0x0007), yuv420p, 1280x1024, q=-1--1, 900 kb/s, 12 fps, 1k tbn, 12 tbc
    Metadata:
      variant_bitrate : 0
      encoder         : Lavc57.107.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/900000 buffer size: 4000000 vbv_delay: -1
[hls,applehttp @ 0x5649bd7463e0] Opening 'https://hddn01.skylinewebcams.com/03042101ANC5-1544185339480.ts' for reading
[hls,applehttp @ 0x5649bd7463e0] Opening 'https://hddn01.skylinewebcams.com/03042101ANC5-1544185347525.ts' for reading
[hls,applehttp @ 0x5649bd7463e0] Opening 'https://hddn01.skylinewebcams.com/03042101ANC5-1544185355483.ts' for reading
[hls,applehttp @ 0x5649bd7463e0] Opening 'https://hddn01.skylinewebcams.com/03042101ANC5-1544185363466.ts' for reading
[hls,applehttp @ 0x5649bd7463e0] Opening 'https://hddn01.skylinewebcams.com/03042101ANC5-1544185371496.ts' for reading
[flv @ 0x5649bdc1aae0] Failed to update header with correct duration.939.0kbits/s speed=0.991x    
[flv @ 0x5649bdc1aae0] Failed to update header with correct filesize.
frame=  552 fps= 12 q=33.0 Lsize=    5261kB time=00:00:45.91 bitrate= 938.6kbits/s speed=0.992x    
  • Does anyone know how to stream in real-time?

dhruv shah

Posted 2018-12-10T10:40:43.480

Reputation: 1

Are you sure, that the original stream has more fps? – Eugen Rieck – 2018-12-10T11:00:02.220

yes, you can see it running on this link https://www.skylinewebcams.com/en/webcam/malta/malta/traffic/traffic-cam2.html. The ffmpeg show it as 12 fps, which is abysmal

– dhruv shah – 2018-12-10T11:40:09.807

Answers

0

This dynamically generated HLS stream uses a JS-based DRM system: Only as long as the page is open and sends heartbeats, will the m3u8 be refreshed (and thus the stream play). If these heartbeats stop, the m3u8 file will become static and thus the FPS count will decrease and decrease over time.

I assume this scheme is employed to make it harder to restream the image.

Eugen Rieck

Posted 2018-12-10T10:40:43.480

Reputation: 15 128

I agree with you, but the only caveat is that in vlc, the stream plays endlessly. – dhruv shah – 2018-12-10T14:42:26.097

As long as the webpage is open ... close it and VLC stops as well – Eugen Rieck – 2018-12-10T21:33:04.817

I went back and tried. VLC is showing the stream even after a couple of hours of webpage being closed. Also my objective is not for this stream to run through ffmpeg throughout the day. I just want it to run for 1 hour. – dhruv shah – 2018-12-11T07:16:23.400

-1

This works perfect with cheap buffalo webcam(UVC) streaming HLS. And check on any local VLC(could be your PC's VLC).

  • Make [one] directory in order to put m3u8 file and ts files in advance to run this bash script
#!/bin/bash
HTTPDIR=/localhost #(might be /var/www/.....)
cd $HTTPDIR
sudo ffmpeg -f alsa -thread_queue_size 3524 -i hw:1 -i /dev/video0 -video_size 1280x720 -f rtsp -input_format YUY2 -video_size 1280x720 -vf fps=100 -vcodec libx264 -video_track_timescale 100 -subq 6 -me_range 16 -b:v 2500k -g 24 -c:a aac -ab 1840 -bufsize 512k -f hls -hls_time 7 -hls_list_size 8 -hls_allow_cache 0 -hls_segment_filename $HTTPDIR/one/stream_%d.ts -hls_flags delete_segments $HTTPDIR/oen/playlist.m3u8

This also works like charm without options of -video_track_timescale 100 -subq 6 -me_range 16

If you set -ab 1840(audio bitrate) too low like 124 then you get choppy sound.

Check your webcam's -video_size and -input_format, by typing ffprobe /dev/video0.

Then put the same to ffmpeg comannd.

All done. Hope this helps everyone anoyed by ffmpeg thing !!(OvOY

user1143870

Posted 2018-12-10T10:40:43.480

Reputation: 1