ffplayout / ffplayout

Rust and ffmpeg based playout
https://ffplayout.github.io
GNU General Public License v3.0
475 stars 94 forks source link

Live ingest does not work in HLS mode #549

Closed JunioCalu closed 6 months ago

JunioCalu commented 8 months ago

Describe the bug

The live ingest function is not working when HLS mode is enabled, and I receive the sole error [out#0/flv @ 0x560600731240] Error muxing a packet. The live ingest function operates in stream mode; during a series of exhaustive tests in stream mode, I encountered some error results which can be summarized below and are expanded upon right after. I have also attached the complete log file and the ffplayout configuration file.

Errors in stream mode:

"Conversion failed!" "Encoder write error: broken pipe" "Out of source loop" "Error submitting a packet to the muxer: Broken pipe" "timestamp discontinuity (stream id=257): -119071589, new offset= 8687972311" Queue input is backward in time

Command line used to test the live ingest function in HLS mode and in stream mode:

ffmpeg -re -i filler.mp4 -vcodec libx264 -x264-params keyint=50:min-keyint=25:scenecut=-1 -acodec aac -ar 44100 -b:a 128k -crf 23 -preset superfast -tune zerolatency -profile:v Main -level 3.1 -f flv rtmp://127.0.0.1:1942/live/stream

Error log from the command line test:

ffmpeg version n6.1.1 Copyright (c) 2000-2023 the FFmpeg developers
  built with gcc 13.2.1 (GCC) 20230801
  configuration: --prefix=/usr --disable-debug --disable-static --disable-stripping --enable-amf --enable-avisynth --enable-cuda-llvm --enable-lto --enable-fontconfig --enable-frei0r --enable-gmp --enable-gnutls --enable-gpl --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libdav1d --enable-libdrm --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libharfbuzz --enable-libiec61883 --enable-libjack --enable-libjxl --enable-libmodplug --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libplacebo --enable-libpulse --enable-librav1e --enable-librsvg --enable-librubberband --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libsvtav1 --enable-libtheora --enable-libv4l2 --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpl --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxml2 --enable-libxvid --enable-libzimg --enable-nvdec --enable-nvenc --enable-opencl --enable-opengl --enable-shared --enable-vapoursynth --enable-version3 --enable-libzmq --enable-parser=h264 --enable-parser=aac --enable-vulkan
  libavutil      58. 29.100 / 58. 29.100
  libavcodec     60. 31.102 / 60. 31.102
  libavformat    60. 16.100 / 60. 16.100
  libavdevice    60.  3.100 / 60.  3.100
  libavfilter     9. 12.100 /  9. 12.100
  libswscale      7.  5.100 /  7.  5.100
  libswresample   4. 12.100 /  4. 12.100
  libpostproc    57.  3.100 / 57.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'filler.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf59.16.100
  Duration: 00:01:59.07, start: 0.000000, bitrate: 426 kb/s
  Stream #0:0[0x1](und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 640x480 [SAR 1:1 DAR 4:3], 290 kb/s, 29.97 fps, 29.97 tbr, 30k tbn (default)
    Metadata:
      handler_name    : ISO Media file produced by Google Inc.
      vendor_id       : [0][0][0][0]
  Stream #0:1[0x2](und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 127 kb/s (default)
    Metadata:
      handler_name    : ISO Media file produced by Google Inc.
      vendor_id       : [0][0][0][0]
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
  Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
[libx264 @ 0x55c58b6b7f40] using SAR=1/1
[libx264 @ 0x55c58b6b7f40] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0x55c58b6b7f40] profile Main, level 3.1, 4:2:0, 8-bit
[libx264 @ 0x55c58b6b7f40] 264 - core 164 r3108 31e19f9 - H.264/MPEG-4 AVC codec - Copyleft 2003-2023 - http://www.videolan.org/x264.html - options: cabac=1 ref=1 deblock=1:0:0 analyse=0x1:0x1 me=dia subme=1 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=1 keyint=50 keyint_min=25 scenecut=0 intra_refresh=0 rc=crf mbtree=0 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, flv, to 'rtmp://127.0.0.1:1942/live/stream':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf60.16.100
  Stream #0:0(und): Video: h264 ([7][0][0][0] / 0x0007), yuv420p(tv, bt709, progressive), 640x480 [SAR 1:1 DAR 4:3], q=2-31, 29.97 fps, 1k tbn (default)
    Metadata:
      handler_name    : ISO Media file produced by Google Inc.
      vendor_id       : [0][0][0][0]
      encoder         : Lavc60.31.102 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
  Stream #0:1(und): Audio: aac (LC) ([10][0][0][0] / 0x000A), 44100 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      handler_name    : ISO Media file produced by Google Inc.
      vendor_id       : [0][0][0][0]
      encoder         : Lavc60.31.102 aac
frame=    0 fps=0.0 q=20.0 size=       0kB time=00:00:00.06 bitrate=  55.4kbits/s spframe=   26 fps=0.0 q=23.0 size=      59kB time=00:00:00.95 bitrate= 510.1kbits/s spframe=   42 fps= 41 q=21.0 size=     139kB time=00:00:01.46 bitrate= 776.9kbits/s spframe=   58 fps= 38 q=19.0 size=     211kB time=00:00:01.99 bitrate= 864.8kbits/s spframe=   73 fps= 36 q=19.0 size=     250kB time=00:00:02.50 bitrate= 815.3kbits/s sp[vost#0:0/libx264 @ 0x55c58b6708c0] Error submitting a packet to the muxer: Connection reset by peer
[out#0/flv @ 0x55c58b644c40] Error muxing a packet
[flv @ 0x55c58b700ec0] Failed to update header with correct duration.
[flv @ 0x55c58b700ec0] Failed to update header with correct filesize.
[out#0/flv @ 0x55c58b644c40] Error writing trailer: Connection reset by peer
[out#0/flv @ 0x55c58b644c40] Error closing file: Broken pipe
[out#0/flv @ 0x55c58b644c40] video:241kB audio:41kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.250304%
frame=   87 fps= 34 q=19.0 Lsize=     282kB time=00:00:03.01 bitrate= 766.4kbits/s speed=1.18x    
[libx264 @ 0x55c58b6b7f40] frame I:2     Avg QP:10.85  size: 13342
[libx264 @ 0x55c58b6b7f40] frame P:86    Avg QP:16.00  size:  2569
[libx264 @ 0x55c58b6b7f40] mb I  I16..4: 55.4%  0.0% 44.6%
[libx264 @ 0x55c58b6b7f40] mb P  I16..4:  8.8%  0.0%  5.3%  P16..4: 36.8%  0.0%  0.0%  0.0%  0.0%    skip:49.1%
[libx264 @ 0x55c58b6b7f40] coded y,uvDC,uvAC intra: 24.8% 24.9% 7.7% inter: 11.1% 8.7% 0.2%
[libx264 @ 0x55c58b6b7f40] i16 v,h,dc,p: 49% 32% 13%  5%
[libx264 @ 0x55c58b6b7f40] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 27% 36% 21%  3%  3%  2%  4%  1%  3%
[libx264 @ 0x55c58b6b7f40] i8c dc,h,v,p: 72% 17%  8%  3%
[libx264 @ 0x55c58b6b7f40] Weighted P-Frames: Y:30.2% UV:0.0%
[libx264 @ 0x55c58b6b7f40] kb/s:674.73
[aac @ 0x55c58b6ed9c0] Qavg: 10574.479
Conversion failed!

Expanded error log for ffplayout stream mode:

[2024-02-27 22:56:55.72096] [ INFO] [Encoder] Conversion failed!
[2024-02-27 22:56:55.73320] [ERROR] Encoder write error: broken pipe
[2024-02-27 22:56:55.73624] [ERROR] [Decoder] [vost#0:0/mpeg2video @ 0x55a62a837d80] Error submitting a packet to the muxer: Broken pipe
[2024-02-27 22:56:55.73644] [ERROR] [Decoder] [out#0/mpegts @ 0x55a62a836f40] Error muxing a packet
[2024-02-27 22:56:55.73672] [DEBUG] Out of source loop
[2024-02-27 22:56:55.80040] [ERROR] [Decoder] [out#0/mpegts @ 0x55a62a836f40] Error writing trailer: Broken pipe
[2024-02-27 22:56:55.80071] [ERROR] [Decoder] [out#0/mpegts @ 0x55a62a836f40] Error closing file: Broken pipe
[2024-02-27 22:56:55.80090] [ INFO] [Decoder] [out#0/mpegts @ 0x55a62a836f40] video:6715kB audio:298kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.135638%
[2024-02-27 22:58:57.35605] [ INFO] [Encoder]       encoder         : Lavc60.31.102 aac
[2024-02-27 22:58:58.51969] [ERROR] [Encoder] [vost#0:0/libx264 @ 0x55d104f3b840] Error submitting a packet to the muxer: Broken pipe
[2024-02-27 22:58:58.52068] [ERROR] [Encoder] [out#0/flv @ 0x55d104f3adc0] Error muxing a packet
[2024-02-27 22:58:59.14248] [ WARN] [Encoder] [flv @ 0x55d104f3aec0] Failed to update header with correct duration.
[2024-02-27 22:58:59.14333] [ WARN] [Encoder] [flv @ 0x55d104f3aec0] Failed to update header with correct filesize.
[2024-02-27 22:58:59.14358] [ERROR] [Encoder] [out#0/flv @ 0x55d104f3adc0] Error writing trailer: Broken pipe
[2024-02-27 22:58:59.14384] [ERROR] [Encoder] [out#0/flv @ 0x55d104f3adc0] Error closing file: Broken pipe
[2024-02-27 22:58:59.14401] [ INFO] [Encoder] [out#0/flv @ 0x55d104f3adc0] video:72kB audio:13kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
[2024-02-27 22:58:59.14413] [ INFO] [Encoder] frame=    9 fps=4.9 q=-1.0 Lsize=      60kB time=00:00:00.90 bitrate= 540.9kbits/s speed=0.489x    

[2024-02-27 22:58:59.17132] [ INFO] [Encoder] Conversion failed!
[2024-02-27 22:58:59.19092] [ERROR] Encoder write error: broken pipe
[2024-02-27 22:58:59.19129] [DEBUG] Out of source loop
[2024-02-27 22:58:59.19259] [ERROR] [Decoder] [vost#0:0/mpeg2video @ 0x561b057bdd80] Error submitting a packet to the muxer: Broken pipe
[2024-02-27 22:58:59.19282] [ERROR] [Decoder] [out#0/mpegts @ 0x561b057bcf40] Error muxing a packet
[2024-02-27 22:58:59.23552] [ERROR] [Decoder] [out#0/mpegts @ 0x561b057bcf40] Error writing trailer: Broken pipe
[2024-02-27 22:58:59.23573] [ERROR] [Decoder] [out#0/mpegts @ 0x561b057bcf40] Error closing file: Broken pipe
[2024-02-27 22:58:59.23586] [ INFO] [Decoder] [out#0/mpegts @ 0x561b057bcf40] video:6434kB audio:284kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.591013%
[2024-02-27 22:58:59.23598] [ INFO] [Decoder] frame=   26 fps=9.9 q=1.6 Lsize=    6757kB time=00:00:01.34 bitrate=41013.1kbits/s speed=0.514x    
[2024-02-27 22:58:59.25806] [ INFO] [Decoder] Conversion failed!
[2024-02-27 22:59:00.19384] [DEBUG] Stop all child processes
[2024-02-27 22:59:00.21436] [ INFO] Playout done...
[2024-02-27 23:12:25.85344] [ WARN] [Encoder] [aist#0:1/s302m @ 0x560b316b3e40] timestamp discontinuity (stream id=257): -50645167, new offset= 752823789
[2024-02-27 23:12:25.85500] [ WARN] [Encoder] [vist#0:0/mpeg2video @ 0x560b316b3cc0] timestamp discontinuity (stream id=256): -194833, new offset= 753018622
[2024-02-27 23:12:29.06340] [ INFO] Switch from playlist to live ingest
[2024-02-27 23:12:29.19978] [ WARN] [Encoder] [aist#0:1/s302m @ 0x560b316b3e40] timestamp discontinuity (stream id=257): -2430167, new offset= 755448789
[2024-02-27 23:12:29.23987] [ WARN] [Encoder] [aac @ 0x560b316be000] Queue input is backward in time

Desktop/Server/Software (please complete the following information):

Config Settings:

Logging:

jb-alvarado commented 8 months ago

According to your config you mixing HLS mode with streaming rtmp output. That is not supported.

JunioCalu commented 8 months ago

According to your config you mixing HLS mode with streaming rtmp output. That is not supported.

HLS mode works in combination with RTMP and live ingest when the HLS mode's ffplayout command line is executed directly in some command terminal. I conducted the following test:

  1. I copied the pure command line from HLS mode from the ffplayout log;
  2. I stopped the ffplayout process execution service (ffplayout.service);
  3. And I pasted the ffmpeg command line used by the ffplayout process, directly into the terminal;
  4. Then I opened another terminal window and used another ffmpeg command line to stream to the ingestion server started in the previous window.
  5. The ingestion server started from the terminal worked without errors.

ffmpeg command line used by the ffplayout process:

ffmpeg -hide_banner -nostats -v level+info -f live_flv -listen 1 -i rtmp://0.0.0.0:1942/live/stream -filter_complex "[0:v:0]fps=25,scale=1280:720,setdar=dar=1.778,zmq=b=tcp\\\\://'127.0.0.1\\:46410',drawtext@dyntext=text='',fade=in:st=0:d=0.5,null[v];movie=/usr/share/ffplayout/logo.png:loop=0,setpts=N/(FRAME_RATE*TB),format=rgba,colorchannelmixer=aa=0.7[l];[v][l]overlay=W-w-12:12:shortest=1[vout0];[0:a:0]anull,afade=in:st=0:d=0.5[aout0]" -map "[vout0]" -map "[aout0]" -c:v libx264 -crf 23 -x264-params keyint=50:min-keyint=25:scenecut=-1 -maxrate 6000k -bufsize 9600k -preset superfast -profile:v Main -level 3.1 -c:a aac -ar 44100 -b:a 128k -f flv rtmp://127.0.0.1/154c0b46-4b72-4387-b140-71f2f8dc48c8.stream

ffmpeg command line to stream to the ingestion server started:

ffmpeg -re -i filler.mp4 -vcodec libx264 -x264-params keyint=50:min-keyint=25:scenecut=-1 -acodec aac -ar 44100 -b:a 128k -crf 23 -preset superfast -tune zerolatency -profile:v Main -level 3.1 -f flv rtmp://127.0.0.1:1942/live/stream