Zend certified PHP/Magento developer

Connection reset when streaming rtmp from ffmpeg to nginx

I’m trying to stream video file to nginx rtmp server with ffmpeg, I’ve posted the exact commands/configuration i’ve used, but i get Connection reset by peer/Broken pipe errors from ffmpeg
I’m running this on 6.6.20+rpt-rpi-v8 #1 SMP PREEMPT Debian 1:6.6.20-1+rpt1 (2024-03-07) aarch64 GNU/Linux

I hope you can help me figure out what it is happening,

Thanks.

nginx.conf

rtmp {
        server {
                listen 1935;
                chunk_size 4096;

                application live {
                        live on;
                        record off;
                }
        }
}

video file

yt-dlp -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/mp4' https://www.youtube.com/watch?v=n-EdUHNK9UI

stream rtmp from ffmpeg to nginx

$ ffmpeg -i 'Setup your own RTMP Server to Receive and Redistribute Live Streaming Video [n-EdUHNK9UI].mp4' -c copy -f mpegts rtmp://127.0.0.1/live/stream -loglevel debug
ffmpeg version 5.1.4-0+rpt3+deb12u1 Copyright (c) 2000-2023 the FFmpeg developers
built with gcc 12 (Debian 12.2.0-14)
configuration: --prefix=/usr --extra-version=0+rpt3+deb12u1 --toolchain=hardened --incdir=/usr/include/aarch64-linux-gnu --enable-gpl --disable-stripping --disable-mmal --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libglslang --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librabbitmq --enable-librist --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libsvtav1 --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzimg --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sand --enable-sdl2 --disable-sndio --enable-libjxl --enable-neon --enable-v4l2-request --enable-libudev --enable-epoxy --libdir=/usr/lib/aarch64-linux-gnu --arch=arm64 --enable-pocketsphinx --enable-librsvg --enable-libdc1394 --enable-libdrm --enable-vout-drm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-libplacebo --enable-librav1e --enable-shared
libavutil      57. 28.100 / 57. 28.100
libavcodec     59. 37.100 / 59. 37.100
libavformat    59. 27.100 / 59. 27.100
libavdevice    59.  7.100 / 59.  7.100
libavfilter     8. 44.100 /  8. 44.100
libswscale      6.  7.100 /  6.  7.100
libswresample   4.  7.100 /  4.  7.100
libpostproc    56.  6.100 / 56.  6.100
Splitting the commandline.
Reading option '-i' ... matched as input url with argument 'Setup your own RTMP Server to Receive and Redistribute Live Streaming Video [n-EdUHNK9UI].mp4'.
Reading option '-c' ... matched as option 'c' (codec name) with argument 'copy'.
Reading option '-f' ... matched as option 'f' (force format) with argument 'mpegts'.
Reading option 'rtmp://127.0.0.1/live/stream' ... matched as output url.
Reading option '-loglevel' ... matched as option 'loglevel' (set logging level) with argument 'debug'.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option loglevel (set logging level) with argument debug.
Successfully parsed a group of options.
Parsing a group of options: input url Setup your own RTMP Server to Receive and Redistribute Live Streaming Video [n-EdUHNK9UI].mp4.
Successfully parsed a group of options.
Opening an input file: Setup your own RTMP Server to Receive and Redistribute Live Streaming Video [n-EdUHNK9UI].mp4.
[NULL @ 0x55636d6600] Opening 'Setup your own RTMP Server to Receive and Redistribute Live Streaming Video [n-EdUHNK9UI].mp4' for reading
[file @ 0x556369c400] Setting default whitelist 'file,crypto,data'
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x55636d6600] Format mov,mp4,m4a,3gp,3g2,mj2 probed with size=2048 and score=100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x55636d6600] ISO: File Type Major Brand: isom
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x55636d6600] Unknown dref type 0x206c7275 size 12
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x55636d6600] Processing st: 0, edit list 0 - media time: 1001, duration: 35791770
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x55636d6600] Offset DTS by 1001 to make first pts zero.
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x55636d6600] Setting codecpar->delay to 1 for stream st: 0
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x55636d6600] Unknown dref type 0x206c7275 size 12
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x55636d6600] Processing st: 1, edit list 0 - media time: 0, duration: 52616195
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x55636d6600] Before avformat_find_stream_info() pos: 1158184 bytes read:1178820 seeks:0 nb_streams:2
[h264 @ 0x55636d7070] nal_unit_type: 7(SPS), nal_ref_idc: 3
[h264 @ 0x55636d7070] nal_unit_type: 8(PPS), nal_ref_idc: 3
[h264 @ 0x55636d7070] nal_unit_type: 7(SPS), nal_ref_idc: 3
[h264 @ 0x55636d7070] nal_unit_type: 8(PPS), nal_ref_idc: 3
[h264 @ 0x55636d7070] nal_unit_type: 5(IDR), nal_ref_idc: 1
[h264 @ 0x55636d7070] Format yuv420p chosen by get_format().
[h264 @ 0x55636d7070] Reinit context to 1920x1088, pix_fmt: yuv420p
[h264 @ 0x55636d7070] no picture
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x55636d6600] All info found
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x55636d6600] After avformat_find_stream_info() pos: 1698157 bytes read:1699177 seeks:0 frames:3
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'Setup your own RTMP Server to Receive and Redistribute Live Streaming Video [n-EdUHNK9UI].mp4':
Metadata:
major_brand     : isom
minor_version   : 512
compatible_brands: isomiso2avc1mp41
encoder         : Lavf59.27.100
Duration: 00:19:53.11, start: 0.000000, bitrate: 1193 kb/s
Stream #0:0[0x1](und), 2, 1/30000: Video: h264 (High), 1 reference frame (avc1 / 0x31637661), yuv420p(tv, bt709, progressive, left), 1920x1080 (1920x1088) [SAR 1:1 DAR 16:9], 0/1, 1058 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](eng), 1, 1/44100: 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]
Successfully opened the file.
Parsing a group of options: output url rtmp://127.0.0.1/live/stream.
Applying option c (codec name) with argument copy.
Applying option f (force format) with argument mpegts.
Successfully parsed a group of options.
Opening an output file: rtmp://127.0.0.1/live/stream.
[rtmp @ 0x556369ad20] No default whitelist set
[tcp @ 0x556369aec0] No default whitelist set
[tcp @ 0x556369aec0] Original list of addresses:
[tcp @ 0x556369aec0] Address 127.0.0.1 port 1935
[tcp @ 0x556369aec0] Interleaved list of addresses:
[tcp @ 0x556369aec0] Address 127.0.0.1 port 1935
[tcp @ 0x556369aec0] Starting connection attempt to 127.0.0.1 port 1935
[tcp @ 0x556369aec0] Successfully connected to 127.0.0.1 port 1935
[rtmp @ 0x556369ad20] Handshaking...
[rtmp @ 0x556369ad20] Type answer 3
[rtmp @ 0x556369ad20] Server version 13.14.10.13
[rtmp @ 0x556369ad20] Proto = rtmp, path = /live/stream, app = live, fname = stream
[rtmp @ 0x556369ad20] Window acknowledgement size = 5000000
[rtmp @ 0x556369ad20] Max sent, unacked = 5000000
[rtmp @ 0x556369ad20] New incoming chunk size = 4096
[rtmp @ 0x556369ad20] Releasing stream...
[rtmp @ 0x556369ad20] FCPublish stream...
[rtmp @ 0x556369ad20] Creating stream...
[rtmp @ 0x556369ad20] Sending publish command for 'stream'
Successfully opened the file.
[mpegts @ 0x55638c85c0] service 1 using PCR in pid=256, pcr_period=67ms
[mpegts @ 0x55638c85c0] muxrate VBR, sdt every 500 ms, pat/pmt every 100 ms
Output #0, mpegts, to 'rtmp://127.0.0.1/live/stream':
Metadata:
major_brand     : isom
minor_version   : 512
compatible_brands: isomiso2avc1mp41
encoder         : Lavf59.27.100
Stream #0:0(und), 0, 1/90000: Video: h264 (High), 1 reference frame (avc1 / 0x31637661), yuv420p(tv, bt709, progressive, left), 1920x1080 (0x0) [SAR 1:1 DAR 16:9], 0/1, q=2-31, 1058 kb/s, 29.97 fps, 29.97 tbr, 90k tbn (default)
Metadata:
handler_name    : ISO Media file produced by Google Inc.
vendor_id       : [0][0][0][0]
Stream #0:1(eng), 0, 1/90000: 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 (copy)
Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
cur_dts is invalid st:0 (0) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
cur_dts is invalid st:1 (0) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
Automatically inserted bitstream filter 'h264_mp4toannexb'; args=''
cur_dts is invalid st:1 (0) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
Last message repeated 1 times
av_interleaved_write_frame(): Connection reset by peer
No more output streams to write to, finishing.
Error writing trailer of rtmp://127.0.0.1/live/stream: Connection reset by peer
frame= 1185 fps=0.0 q=-1.0 Lsize=   12769kB time=00:00:39.49 bitrate=2648.4kbits/s speed= 483x
video:11848kB audio:617kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 2.432926%
Input file #0 (Setup your own RTMP Server to Receive and Redistribute Live Streaming Video [n-EdUHNK9UI].mp4):
Input stream #0:0 (video): 1185 packets read (12132837 bytes);
Input stream #0:1 (audio): 1701 packets read (632039 bytes);
Total: 2886 packets (12764876 bytes) demuxed
Output file #0 (rtmp://127.0.0.1/live/stream):
Output stream #0:0 (video): 1185 packets muxed (12132837 bytes);
Output stream #0:1 (audio): 1701 packets muxed (632039 bytes);
Total: 2886 packets (12764876 bytes) muxed
[AVIOContext @ 0x55636dcf70] Statistics: 13075436 bytes written, 0 seeks, 1568 writeouts
[rtmp @ 0x556369ad20] UnPublishing stream...
[rtmp @ 0x556369ad20] Deleting stream...
Error closing file rtmp://127.0.0.1/live/stream: Broken pipe
0 frames successfully decoded, 0 decoding errors
[AVIOContext @ 0x556369c800] Statistics: 13955462 bytes read, 0 seeks
Conversion failed!

nginx access.log

127.0.0.1 [25/Apr/2024:21:24:56 +0100] PUBLISH "live" "stream" "" - 131330 409 "" "FMLE/3.0 (compatible; Lavf59.27" (0s)