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
12.22k stars 1.53k forks source link

OnDemand not kill the ffmpeg process #84

Closed Classsic closed 4 years ago

Classsic commented 4 years ago

Which version are you using?

v0.9.13

Which operating system are you using?

Linux

Describe the problem

I can run successfully the onDemand feature with this section :

paths: ondemand3: runOnDemand: ffmpeg -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -hwaccel_output_format vaapi -rtsp_transport tcp -i 'rtsp://user@Ipcamera/cam/realmonitor?channel=1&subtype=0' -acodec pcm_mulaw -ac 1 -g 10 -vf 'fps=10,scale_vaapi=w=640:h=-2:format=nv12' -c:v h264_vaapi -profile:v 578 -level 30 -bf 0 -b:v 512k -maxrate 512k -rtsp_transport tcp -f rtsp rtsp://localhost:8563/$RTSP_SERVER_PATH

But when close the client, I receive the log:

Metadata: title : Media Server Duration: N/A, start: 0.080000, bitrate: N/A Stream #0:0: Video: h264 (Main), yuv420p(progressive), 960x1080 [SAR 2:1 DAR 16:9], 25 fps, 100 tbr, 90k tbn, 50 tbc Stream #0:1: Audio: pcm_mulaw, 8000 Hz, mono, s16, 64 kb/s Stream mapping: Stream #0:0 -> #0:0 (h264 (native) -> h264 (h264_vaapi)) Stream #0:1 -> #0:1 (pcm_mulaw (native) -> pcm_mulaw (native)) 2020/09/15 22:16:31 [2/0/0] [client 127.0.0.1:44352] connected 2020/09/15 22:16:31 [2/0/0] [client 127.0.0.1:44352] OPTIONS 2020/09/15 22:16:31 [2/0/0] [client 127.0.0.1:44352] ANNOUNCE 2020/09/15 22:16:31 [2/0/0] [client 127.0.0.1:44352] SETUP 2020/09/15 22:16:31 [2/0/0] [client 127.0.0.1:44352] SETUP 2020/09/15 22:16:31 [2/0/0] [client 127.0.0.1:44352] RECORD 2020/09/15 22:16:31 [2/0/0] [client 127.0.0.1:44352] is publishing on path 'ondemand3', 2 tracks via tcp Output #0, rtsp, to 'rtsp://localhost:8563/ondemand3': Metadata: title : Media Server encoder : Lavf57.83.100 Stream #0:0: Video: h264 (h264_vaapi) (Constrained Baseline), vaapi_vld, 640x720 [SAR 2:1 DAR 16:9], q=0-31, 512 kb/s, 10 fps, 90k tbn, 10 tbc Metadata: encoder : Lavc57.107.100 h264_vaapi Stream #0:1: Audio: pcm_mulaw, 8000 Hz, mono, s16, 64 kb/s Metadata: encoder : Lavc57.107.100 pcm_mulaw 2020/09/15 22:16:32 [2/1/0] [client 192.168.8.131:60392] SETUP 2020/09/15 22:16:32 [2/1/0] [client 192.168.8.131:60392] SETUP/A dup=2 drop=0 speed=3.28x 2020/09/15 22:16:33 [2/1/0] [client 192.168.8.131:60392] PLAYN/A dup=2 drop=0 speed=2.16x 2020/09/15 22:16:33 [2/1/0] [client 192.168.8.131:60392] is receiving on path 'ondemand3', 2 tracks via tcp 2020/09/15 22:16:43 [1/1/0] [client 192.168.8.131:60392] disconnected2 drop=0 speed=1.09x 2020/09/15 22:16:47 [1/1/0] [path ondemand3] stopping on demand command (not requested anymore) ^Came= 910 fps= 10 q=-0.0 size=N/A time=00:01:31.43 bitrate=N/A dup=2 drop=0 speed=1.01x

But the ps show the ffmpeg process running, and when try to connect again with the client, stay freeze (without playing anything), so this isn´t work as expected. Please any additional info you need, letme know. Thanks.

aler9 commented 4 years ago

Hello,

  1. try with v0.9.14
  2. the signal used to kill the external commands is SIGINT, maybe it's not enough for ffmpeg, please try each one of the following commands
    killall -INT ffmpeg
    killall -QUIT ffmpeg
    killall -TERM ffmpeg
    killall -9 ffmpeg

and let me know which one of them works.

Classsic commented 4 years ago

Hi, I try killall -INT ffmpeg and it works, kill all ffmpeg process. But when try to test on rtsp-server V9.0.14 ,don't works: While clients connect: root@xp-V530S-07ICB:~# pstree 22551 -a

rtsp-simple-ser /root/rtsp/rtsp-simple-server.yml
  ├─sh -cffmpeg -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -hwaccel_output_format vaapi -rtsp_transport tcp -i 'rtsp://admin:xxx@192.168.8.111/cam/realmonito
  │   └─ffmpeg -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -hwaccel_output_format vaapi -rtsp_transport tcp -i...
  │       └─13*[{ffmpeg}]
  └─5*[{rtsp-simple-ser}] 

After clients disconects:

rtsp-simple-ser /root/rtsp/rtsp-simple-server.yml
  ├─sh -cffmpeg -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -hwaccel_output_format vaapi -rtsp_transport tcp -i 'rtsp://admin:otus2018@192.168.8.111/cam/realmonito
  │   └─ffmpeg -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -hwaccel_output_format vaapi -rtsp_transport tcp -i...
  │       └─13*[{ffmpeg}]
  └─6*[{rtsp-simple-ser}]

and the logs of rtsp-server:

  Metadata:
    title           : Media Server
    encoder         : Lavf57.83.100
    Stream #0:0: Video: h264 (h264_vaapi) (Constrained Baseline), vaapi_vld, 640x360 [SAR 1:1 DAR 16:9], q=0-31, 512 kb/s, 5 fps, 90k tbn, 5 tbc
    Metadata:
      encoder         : Lavc57.107.100 h264_vaapi
2020/09/19 16:46:16 [2/1/0] [client 192.168.8.131:55672] SETUP
2020/09/19 16:46:16 [2/1/0] [client 192.168.8.131:55672] PLAYN/A speed=3.35x
2020/09/19 16:46:16 [2/1/0] [client 192.168.8.131:55672] is receiving on path 'ondemand', 1 track via tcp
2020/09/19 16:46:46 [2/1/1] [client 192.168.8.131:55672] OPTIONS speed=1.05x
2020/09/19 16:47:16 [2/1/1] [client 192.168.8.131:55672] OPTIONS speed=1.02x
2020/09/19 16:47:46 [2/1/1] [client 192.168.8.131:55672] OPTIONS speed=1.02x
2020/09/19 16:48:16 [2/1/1] [client 192.168.8.131:55672] OPTIONS speed=1.01x
2020/09/19 16:48:34 [1/1/0] [client 192.168.8.131:55672] disconnectedd=1.01x
2020/09/19 16:48:39 [1/1/0] [path ondemand] stopping on demand command (not requested anymore)
frame=  979 fps=5.0 q=-0.0 Lsize=N/A time=00:03:15.60 bitrate=N/A speed=1.01x

There is a way to check if effectively send the signal to the child process Id?

aler9 commented 4 years ago

Hello, i think you deployed the previous version, since starting from v0.9.14 there isn't a shell between the server and external commands, so ps should be

rtsp-simple-ser /root/rtsp/rtsp-simple-server.yml
  ├─ffmpeg -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -hwaccel_output_format vaapi -rtsp_transport tcp -i...

not

rtsp-simple-ser /root/rtsp/rtsp-simple-server.yml
  ├─sh -cffmpeg -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -hwaccel_output_format vaapi -rtsp_transport tcp -i 'rtsp://admin:xxx@192.168.8.111/cam/realmonito
  │   └─ffmpeg -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -hwaccel_output_format vaapi -rtsp_transport tcp -i...

maybe this doesn't solve the problem, but please try with the latest version. Thanks.

Classsic commented 4 years ago

Hi, this version works ok,thanks. Now the problem is the source get timeout, the ffmpeg process go into: root 1470 0.0 0.0 0 0 ? Z 20:37 0:00 [ffmpeg] <defunct> And never recovery to normal state. How is the correct way to keep up running the ffmpeg process, even the source get timeout?

aler9 commented 4 years ago

Hello, i usually wrap a command into a 'while true; do... done', in this way

paths:
  ondemand3:
    runOnDemand: sh -c 'while true; do ffmpeg ... -f rtsp rtsp://localhost:8563/$RTSP_SERVER_PATH; sleep 5; done'

i know that commands are starting to get complicated, and i'll try to integrate more and more functionalities directly inside the server (for instance, i could add an option to automatically restart a command without the wrapper)

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