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.41k stars 1.45k forks source link

Can 'runOnDemandRestart: yes' respawn ffmpeg process after ffmpeg process was killed? #1893

Closed napat1412 closed 1 year ago

napat1412 commented 1 year ago

Which version are you using?

v0.23.3

Which operating system are you using?

Describe the issue

I need rtsp proxy: runOnDemand which use ffmpeg. But my cctv network is poor connection. ffmpeg often terminate. I use kill -9 cmd for simulation the termination of ffmpeg.

My mediamtx.yml:

...
<Same as mediamtx.yml>
...
paths:
  hik:
    runOnDemand: ffmpeg -rtsp_transport tcp -i rtsp://<RTSP_URL>/  -c copy -f rtsp rtsp://localhost:$RTSP_PORT/$RTSP_PATH
    runOnDemandRestart: yes
    runOnDemandStartTimeout: 10s
    runOnDemandCloseAfter: 10s

I think 'runOnDemandRestart: yes' will respawn ffmpeg proccess to restream video. But it is not respawn ffmpeg process. What is my mistake? or Is there other way to do something like that?

Describe how to replicate the issue

  1. [ok] start the server
  2. [ok] read with: ffplay -rtsp_transport tcp rtsp://10.0.10.19:8554/hik
  3. [ok] wait for ffplay render video
  4. [ok] kill -9 [pid-ffmpeg]
  5. no ffmpef process respawn
  6. [failed] ffplay stop render video

Did you attach the server logs?

yes The logs is copied after i run kill -9 [pid-ffmpeg]

2023/06/01 10:51:06 INF [RTSP] [conn 127.0.0.1:35178] closed (EOF)peed=1.05x
2023/06/01 10:51:06 INF [path hik] runOnDemand command exited with code -1
ffmpeg version 4.4.2-0ubuntu0.22.04.1 Copyright (c) 2000-2021 the FFmpeg developers
  built with gcc 11 (Ubuntu 11.2.0-19ubuntu1)
  configuration: --prefix=/usr --extra-version=0ubuntu0.22.04.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gn
u --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-gnutls --enable-ladspa
 --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcod
ec2 --enable-libdav1d --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgm
e --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --e
nable-libopus --enable-libpulse --enable-librabbitmq --enable-librubberband --enable-libshine --enable-libsnappy --ena
ble-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidst
ab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lib
zimg --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enab
le-sdl2 --enable-pocketsphinx --enable-librsvg --enable-libmfx --enable-libdc1394 --enable-libdrm --enable-libiec61883
 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
  libavutil      56. 70.100 / 56. 70.100
  libavcodec     58.134.100 / 58.134.100
  libavformat    58. 76.100 / 58. 76.100
  libavdevice    58. 13.100 / 58. 13.100
  libavfilter     7.110.100 /  7.110.100
  libswscale      5.  9.100 /  5.  9.100
  libswresample   3.  9.100 /  3.  9.100
  libpostproc    55.  9.100 / 55.  9.100
2023/06/01 10:51:16 INF [path hik] runOnDemand command stopped
2023/06/01 10:51:16 INF [RTSP] [session bb23058c] destroyed (session timed out)
2023/06/01 10:51:16 INF [RTSP] [conn 10.0.10.1:53040] closed (terminated)
2023/06/01 10:51:16 INF [RTSP] [session 88a96fe7] destroyed (terminated)
Input #0, rtsp, from 'rtsp://10.128.128.37:554/Streaming/Channels/101/':
  Metadata:
    title           : Media Presentation
  Duration: N/A, start: 0.413244, bitrate: N/A
  Stream #0:0: Video: h264 (High), yuvj420p(pc, bt709, progressive), 1280x720, 15 fps, 25 tbr, 90k tbn, 30 tbc
2023/06/01 10:51:16 INF [RTSP] [conn 127.0.0.1:41554] opened
Could not write header for output file #0 (incorrect codec parameters ?): Immediate exit requested
Error initializing output stream 0:0 --
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
    Last message repeated 1 times
Exiting normally, received signal 2.
2023/06/01 10:51:16 INF [RTSP] [conn 127.0.0.1:41554] closed (EOF)

Did you attach a network dump?

no

aler9 commented 1 year ago

Hello, thanks for reporting the issue, i can confirm that runOnDemandRestart: yes doesn't work and i developed a fix. Please test this nightly release and let me know if the fix works:

[link removed]

aler9 commented 1 year ago

added in v0.23.6

github-actions[bot] commented 8 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.