bluenviron / mediamtx

Ready-to-use SRT / WebRTC / RTSP / RTMP / LL-HLS media server and media proxy that allows to read, publish, proxy, record and playback video and audio streams.
MIT License
11.69k stars 1.47k forks source link

RTSP Streaming stops on v1.1.1 | Error : av_interleaved_write_frame(): Broken pipe #2449

Closed jahab closed 9 months ago

jahab commented 11 months ago

Which version are you using?

v1.1.1

Which operating system are you using?

Describe the issue

On the version 1.1.1 whenever I am trying to stream a video to the rtsp server through this command

ffmpeg -re -i 2023-08-09_17-17-49#2.mkv -r 15 -c:v libx265 -preset fast  -b:v 1000k -f rtsp rtsp://192.168.10.17:8554/playback

After streaming for 8 - 10 seconds, I get this error

av_interleaved_write_frame(): Broken pipe00:00:09.69 bitrate=N/A speed=1.02x    
Error writing trailer of rtsp://192.168.10.17:8554/playback: Broken pipe
frame=  153 fps= 15 q=-1.0 Lsize=N/A time=00:00:10.15 bitrate=N/A speed=1.01x    
video:1270kB audio:76kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Conversion failed!

I tried the same again without any encoding with this command. I get the same error.

ffmpeg  -re -i 2023-08-09_17-17-49#2.mkv  -c copy -f rtsp rtsp://192.168.10.17:8555/playback

When I tried the same with version 1.0.1, the stream publishes to server smoothly without any error

Describe how to replicate the issue

  1. start the server

  2. publish a video with ffmpeg -re -i 2023-08-09_17-17-49#2.mkv -r 15 -c:v libx265 -preset fast -b:v 1000k -f rtsp rtsp://192.168.10.17:8554/playback or ffmpeg -re -i 2023-08-09_17-17-49#2.mkv -c copy -f rtsp rtsp://192.168.10.17:8555/playback

  3. read with

Server Logs

2023/10/03 06:36:04 DEB path manager created
2023/10/03 06:36:04 INF [RTSP] listener opened on :8554 (TCP), :8000 (UDP/RTP), :8001 (UDP/RTCP)
2023/10/03 06:36:04 INF [RTMP] listener opened on :1935
2023/10/03 06:36:04 INF [HLS] listener opened on :8888
2023/10/03 06:36:04 INF [WebRTC] listener opened on :8889 (HTTP)
2023/10/03 06:36:04 INF [SRT] listener opened on :8890 (UDP)
2023/10/03 06:36:10 INF shutting down gracefully
2023/10/03 06:36:10 INF [SRT] listener is closing
2023/10/03 06:36:10 INF [WebRTC] listener is closing
2023/10/03 06:36:10 INF [HLS] listener is closing
2023/10/03 06:36:10 INF [RTMP] listener is closing
2023/10/03 06:36:10 INF [RTSP] listener is closing
2023/10/03 06:36:10 DEB path manager is shutting down
2023/10/03 06:36:10 INF waiting for running hooks
2023/10/03 06:36:10 INF MediaMTX v1.1.1
2023/10/03 06:36:10 DEB path manager created
2023/10/03 06:36:10 INF [RTSP] listener opened on :8554 (TCP), :8000 (UDP/RTP), :8001 (UDP/RTCP)
2023/10/03 06:36:10 INF [RTMP] listener opened on :1935
2023/10/03 06:36:10 INF [HLS] listener opened on :8888
2023/10/03 06:36:10 INF [WebRTC] listener opened on :8889 (HTTP)
2023/10/03 06:36:10 INF [SRT] listener opened on :8890 (UDP)
2023/10/03 06:36:18 INF [RTSP] [conn 14.143.47.170:25547] opened
2023/10/03 06:36:18 DEB [RTSP] [conn 14.143.47.170:25547] [c->s] OPTIONS rtsp://192.168.10.17:8554/playback RTSP/1.0
CSeq: 1
User-Agent: Lavf58.29.100

2023/10/03 06:36:18 DEB [RTSP] [conn 14.143.47.170:25547] [s->c] RTSP/1.0 200 OK
CSeq: 1
Public: DESCRIBE, ANNOUNCE, SETUP, PLAY, RECORD, PAUSE, GET_PARAMETER, TEARDOWN
Server: gortsplib

2023/10/03 06:36:18 DEB [RTSP] [conn 14.143.47.170:25547] [c->s] ANNOUNCE rtsp://192.168.10.17:8554/playback RTSP/1.0
CSeq: 2
Content-Length: 504
Content-Type: application/sdp
User-Agent: Lavf58.29.100

v=0
o=- 0 0 IN IP4 127.0.0.1
s=No Name
c=IN IP4 192.168.10.17
t=0 0
a=tool:libavformat 58.29.100
m=video 0 RTP/AVP 96
a=rtpmap:96 H265/90000
a=fmtp:96 sprop-vps=QAEMAf//AWAAAAMAAAMAAAMAAAMAlrwMAAAPoAAA6mFA; sprop-sps=QgEBAWAAAAMAAAMAAAMAAAMAlqADwIAQ5Zb5JMiP5c9MgA==; sprop-pps=RAHgLawJkA==
a=control:streamid=0
m=audio 0 RTP/AVP 97
a=rtpmap:97 MPEG4-GENERIC/48000/2
a=fmtp:97 profile-level-id=1;mode=AAC-hbr;sizelength=13;indexlength=3;indexdeltalength=3; config=1190
a=control:streamid=1

2023/10/03 06:36:18 INF [RTSP] [session 132bbc39] created by 14.143.47.170:25547
2023/10/03 06:36:18 DEB [path playback] created
2023/10/03 06:36:18 DEB [RTSP] [conn 14.143.47.170:25547] [s->c] RTSP/1.0 200 OK
CSeq: 2
Server: gortsplib

2023/10/03 06:36:18 DEB [RTSP] [conn 14.143.47.170:25547] [c->s] SETUP rtsp://192.168.10.17:8554/playback/streamid=0 RTSP/1.0
CSeq: 3
Transport: RTP/AVP/UDP;unicast;client_port=24268-24269;mode=record
User-Agent: Lavf58.29.100

2023/10/03 06:36:18 DEB [RTSP] [conn 14.143.47.170:25547] [s->c] RTSP/1.0 200 OK
CSeq: 3
Server: gortsplib
Session: de2a6d049c38489bb1a19a72964e1331
Transport: RTP/AVP;unicast;client_port=24268-24269;server_port=8000-8001

2023/10/03 06:36:18 DEB [RTSP] [conn 14.143.47.170:25547] [c->s] SETUP rtsp://192.168.10.17:8554/playback/streamid=1 RTSP/1.0
CSeq: 4
Session: de2a6d049c38489bb1a19a72964e1331
Transport: RTP/AVP/UDP;unicast;client_port=24270-24271;mode=record
User-Agent: Lavf58.29.100

2023/10/03 06:36:18 DEB [RTSP] [conn 14.143.47.170:25547] [s->c] RTSP/1.0 200 OK
CSeq: 4
Server: gortsplib
Session: de2a6d049c38489bb1a19a72964e1331
Transport: RTP/AVP;unicast;client_port=24270-24271;server_port=8000-8001

2023/10/03 06:36:18 DEB [RTSP] [conn 14.143.47.170:25547] [c->s] RECORD rtsp://192.168.10.17:8554/playback RTSP/1.0
CSeq: 5
Range: npt=0.000-
Session: de2a6d049c38489bb1a19a72964e1331
User-Agent: Lavf58.29.100

2023/10/03 06:36:18 INF [RTSP] [session 132bbc39] is publishing to path 'playback', 2 tracks (H265, MPEG-4 Audio)
2023/10/03 06:36:18 DEB [RTSP] [conn 14.143.47.170:25547] [s->c] RTSP/1.0 200 OK
CSeq: 5
Server: gortsplib
Session: de2a6d049c38489bb1a19a72964e1331

2023/10/03 06:36:28 INF [RTSP] [conn 14.143.47.170:25547] closed: terminated
2023/10/03 06:36:28 INF [RTSP] [session 132bbc39] destroyed: session timed out
2023/10/03 06:36:28 DEB [path playback] destroyed: not in use

Client Logs

ffmpeg version 4.2.7-0ubuntu0.1 Copyright (c) 2000-2022 the FFmpeg developers
  built with gcc 9 (Ubuntu 9.4.0-1ubuntu1~20.04.1)
  configuration: --prefix=/usr --extra-version=0ubuntu0.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
Input #0, matroska,webm, from '2023-08-09_17-17-49#2.mkv':
  Metadata:
    encoder         : GStreamer matroskamux version 1.16.2
    creation_time   : 2023-08-09T11:47:50.000000Z
  Duration: N/A, start: 0.000000, bitrate: N/A
    Stream #0:0(eng): Video: hevc (Main), yuv420p(tv), 1920x1080, SAR 1:1 DAR 16:9, 15.17 fps, 25 tbr, 1k tbn, 15 tbc (default)
    Metadata:
      title           : Video
    Stream #0:1(eng): Audio: aac (LC), 48000 Hz, stereo, fltp (default)
    Metadata:
      title           : Audio
Stream mapping:
  Stream #0:0 -> #0:0 (hevc (native) -> hevc (libx265))
  Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
x265 [info]: HEVC encoder version 3.2.1+1-b5c86a64bbbe77 bitrate=N/A speed=N/A    
x265 [info]: build info [Linux][GCC 9.3.0][64 bit] 8bit+10bit+12bit
x265 [info]: using cpu capabilities: MMX2 SSE2Fast LZCNT SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
x265 [info]: Main profile, Level-4 (Main tier)
x265 [info]: Thread pool created using 8 threads
x265 [info]: Slices                              : 1
x265 [info]: frame threads / pool features       : 3 / wpp(17 rows)
x265 [info]: Coding QT: max CU size, min CU size : 64 / 8
x265 [info]: Residual QT: max TU size, max depth : 32 / 1 inter / 1 intra
x265 [info]: ME / range / subpel / merge         : hex / 57 / 2 / 2
x265 [info]: Keyframe min / max / scenecut / bias: 15 / 250 / 40 / 5.00
x265 [info]: Lookahead / bframes / badapt        : 15 / 4 / 0
x265 [info]: b-pyramid / weightp / weightb       : 1 / 1 / 0
x265 [info]: References / ref-limit  cu / depth  : 3 / on / on
x265 [info]: AQ: mode / str / qg-size / cu-tree  : 2 / 1.0 / 32 / 1
x265 [info]: Rate Control / qCompress            : ABR-1000 kbps / 0.60
x265 [info]: tools: rd=2 psy-rd=2.00 rskip signhide tmvp fast-intra
x265 [info]: tools: strong-intra-smoothing lslices=6 deblock sao
Output #0, rtsp, to 'rtsp://192.168.10.17:8554/playback':
  Metadata:
    encoder         : Lavf58.29.100
    Stream #0:0(eng): Video: hevc (libx265), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 1000 kb/s, 15 fps, 90k tbn, 15 tbc (default)
    Metadata:
      title           : Video
      encoder         : Lavc58.54.100 libx265
    Side data:
      cpb: bitrate max/min/avg: 0/0/1000000 buffer size: 0 vbv_delay: -1
    Stream #0:1(eng): Audio: aac (LC), 48000 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      title           : Audio
      encoder         : Lavc58.54.100 aac
av_interleaved_write_frame(): Broken pipe00:00:10.53 bitrate=N/A speed=0.996x    
    Last message repeated 1 times
Error writing trailer of rtsp://192.168.10.17:8554/playback: Broken pipe
frame=  153 fps= 14 q=-0.0 Lsize=N/A time=00:00:10.67 bitrate=N/A speed=0.949x    
video:982kB audio:170kB subtitle:0kB other streams:0kB global headers:2kB muxing overhead: unknown
x265 [info]: frame I:      1, Avg QP:31.19  kb/s: 3436.32 
x265 [info]: frame P:     31, Avg QP:21.38  kb/s: 3463.87 
x265 [info]: frame B:    121, Avg QP:27.18  kb/s: 253.98  
x265 [info]: Weighted P-Frames: Y:0.0% UV:0.0%
x265 [info]: consecutive B-frames: 3.1% 3.1% 0.0% 0.0% 93.8% 

encoded 153 frames in 10.67s (14.34 fps), 925.15 kb/s, Avg QP:26.03
[aac @ 0x5649c7831e40] Qavg: 336.523
Conversion failed!

Did you attach the server logs?

yes

Did you attach a network dump?

no

mateothegreat commented 11 months ago

How long are the video(s) you're testing with?

I ask because things start to kick off around 2023/10/03 06:18:00 and the server itself notifies at 2023/10/03 06:36:28 INF [RTSP] [session 132bbc39] destroyed: session timed out.

Before digging any deeper can you try a longer clip to account for processing time you're expecting or tell ffmpeg to loop.

jahab commented 11 months ago

@mateothegreat The video I am using is 15 minutes long. The server starts at 2023/10/03 06:36:04 and starts to receive stream at 2023/10/03 06:36:18

tgcandido commented 11 months ago

i'm having this problem when restreaming an IP camera

tgcandido commented 11 months ago

the error on my side starts getting really frequent (every 2-5 seconds) when I'm restreaming more than 5 cameras. could that be a bottleneck on the mediamtx side? I'm currently using an azure VM as server

jahab commented 11 months ago

@tgcandido I am exactly under the same setup as yours. I am also running the mediamtx server on an azure VM. I have tried to stream with other encoders / videos/ streams as well but I get the same issue. For now I have started using version 1.01 to avoid the error.

tgcandido commented 11 months ago

i will try that version. thank you @jahab

longdq01 commented 10 months ago

Hi, I have same problem with ip camera. Anyone have solution ? thanks

aler9 commented 9 months ago

Hello, it seems that the machine that is hosting the server is unable to receive UDP packets from the machine that is hosting FFmpeg; after exactly 10 seconds, a timeout occurs:

2023/10/03 06:36:18 INF [RTSP] [session 132bbc39] is publishing to path 'playback', 2 tracks (H265, MPEG-4 Audio)
---
2023/10/03 06:36:28 INF [RTSP] [session 132bbc39] destroyed: session timed out

Check that any firewall / NAT in between allows UDP packets.

I've tested publishing from FFmpeg to MediaMTX v1.1.1, and if there's no firewall in between, everything works correctly. This is the command i used:

ffmpeg -re -f lavfi -i testsrc=size=1920x1080:rate=30 -pix_fmt yuv420p -r 15 -c:v libx265 -preset fast  -b:v 1000k -f rtsp rtsp://localhost:8554/playback

Other issues that happen with a frequency different that 10 seconds are unrelated from the original post. If those issues are still present in the latest version, open a dedicated issue.

github-actions[bot] commented 2 months ago

This issue is being locked automatically because it has been closed for more than 6 months. Please open a new issue in case you encounter a similar problem.