ossrs / srs

SRS is a simple, high-efficiency, real-time video server supporting RTMP, WebRTC, HLS, HTTP-FLV, SRT, MPEG-DASH, and GB28181.
https://ossrs.io
MIT License
24.86k stars 5.29k forks source link

when broadcast is turned off, FFMPEG does not terminate #3799

Closed furkanKotic closed 8 months ago

furkanKotic commented 10 months ago

Description

When I turn off the broadcast, only a client watching with the local ip remains. In my opinion, when the OBS broadcast is turned off, FFMPEG does not terminate and remains as a local viewer.

  1. SRS Version: v5.0-b4

  2. SRS Log:

2023-09-12 07:30:30.166][INFO][567287][16ve4vjd] <- EPB time=9529, msgs=34, okbps=0,0,0, ikbps=0,0,0
[2023-09-12 07:30:32.649][INFO][567287][72lcz3v5] Hybrid cpu=1.00%,361MB, cid=14,1, timer=62,0,0, clock=0,46,1,1,1,0,0,0,0, free=1, objs=(pkt:0,raw:0,fua:0,msg:139,oth:0,buf:0)
[2023-09-12 07:30:33.075][INFO][567287][83690131] Process: cpu=2.00%,361MB, threads=2
[2023-09-12 07:30:35.672][INFO][567287][92kwmzp1] -> PLA time=14500913, msgs=27, okbps=0,0,0, ikbps=0,0,0, mw=350/8
[2023-09-12 07:30:36.530][ERROR][567287][16ve4vjd][4] edge push get server control message failed. err=code=1007(SocketRead)(Socket read data failed) : recv interlaced message : read basic header : basic header requires 1 bytes : read bytes : read
thread [567287][16ve4vjd]: recv_message() [./src/protocol/srs_protocol_rtmp_stack.cpp:341][errno=4]
thread [567287][16ve4vjd]: recv_interlaced_message() [./src/protocol/srs_protocol_rtmp_stack.cpp:792][errno=4]
thread [567287][16ve4vjd]: read_basic_header() [./src/protocol/srs_protocol_rtmp_stack.cpp:887][errno=4]
thread [567287][16ve4vjd]: grow() [./src/protocol/srs_protocol_stream.cpp:162][errno=4]
thread [567287][16ve4vjd]: read() [./src/protocol/srs_protocol_st.cpp:566][errno=4](Interrupted system call)
[2023-09-12 07:30:36.530][INFO][567287][16ve4vjd] edge change from 200 to state 0 (init).
[2023-09-12 07:30:36.530][INFO][567287][16ve4vjd] TCP: before dispose resource(RtmpConn)(0x61200025fe40), conns=3, zombies=0, ign=0, inz=0, ind=0
[2023-09-12 07:30:36.530][WARN][567287][16ve4vjd][104] client disconnect peer. ret=1007
[2023-09-12 07:30:36.530][INFO][567287][6n21y12c] TCP: clear zombies=1 resources, conns=3, removing=0, unsubs=0
[2023-09-12 07:30:36.530][INFO][567287][16ve4vjd] TCP: disposing #0 resource(RtmpConn)(0x61200025fe40), conns=3, disposing=1, zombies=0
[2023-09-12 07:30:37.212][INFO][567287][y2g20663] <- EPB time=12027, msgs=0, okbps=0,0,0, ikbps=0,0,0
[2023-09-12 07:30:37.649][INFO][567287][72lcz3v5] Hybrid cpu=1.00%,363MB, cid=22,1, timer=62,0,0, clock=0,44,4,1,0,0,0,0,0, free=1, objs=(pkt:0,raw:0,fua:0,msg:432,oth:0,buf:0)
[2023-09-12 07:30:38.080][INFO][567287][83690131] Process: cpu=1.00%,363MB, threads=2
[2023-09-12 07:30:41.174][WARN][567287][nl76905b][62] EdgeIngester: Ignore error, code=1011(SocketTimeout)(Socket io timeout) : recv message : recv interlaced message : read basic header : basic header requires 1 bytes : read bytes : timeout 5000 ms
thread [567287][nl76905b]: ingest() [./src/app/srs_app_edge.cpp:619][errno=62]
thread [567287][nl76905b]: recv_message() [./src/protocol/srs_protocol_rtmp_stack.cpp:341][errno=62]
thread [567287][nl76905b]: recv_interlaced_message() [./src/protocol/srs_protocol_rtmp_stack.cpp:792][errno=62]
thread [567287][nl76905b]: read_basic_header() [./src/protocol/srs_protocol_rtmp_stack.cpp:887][errno=62]
thread [567287][nl76905b]: grow() [./src/protocol/srs_protocol_stream.cpp:162][errno=62]
thread [567287][nl76905b]: read() [./src/protocol/srs_protocol_st.cpp:559][errno=62]
[2023-09-12 07:30:42.650][INFO][567287][72lcz3v5] Hybrid cpu=1.00%,363MB, cid=22,1, timer=62,0,0, clock=0,44,4,1,0,0,0,0,0, free=1, objs=(pkt:0,raw:0,fua:0,msg:432,oth:0,buf:0)
[2023-09-12 07:30:43.085][INFO][567287][83690131] Process: cpu=0.00%,363MB, threads=2
[2023-09-12 07:30:44.176][INFO][567287][nl76905b] complex handshake success.
[2023-09-12 07:30:44.177][INFO][567287][nl76905b] protocol in.buffer=0, in.ack=0, out.ack=0, in.chunk=128, out.chunk=128
[2023-09-12 07:30:44.177][INFO][567287][nl76905b] connected, version=5.0.178.0, ip=10.0.0.2, pid=489820, id=0, dsu=1
[2023-09-12 07:30:44.177][INFO][567287][nl76905b] edge-pull publish url rtmp://10.0.0.2:1935/live/19059, stream=19059 as 19059
[2023-09-12 07:30:44.178][INFO][567287][nl76905b] got metadata, width=1280, height=720, vcodec=7, acodec=10
[2023-09-12 07:30:44.179][WARN][567287][nl76905b][11] AUDIO: Timestamp 13540=>0, may need mix_correct.
[2023-09-12 07:30:44.179][INFO][567287][nl76905b] 7B audio sh, codec(10, profile=LC, 2channels, 0kbps, 48000HZ), flv(16bits, 2channels, 44100HZ)
[2023-09-12 07:30:44.179][INFO][567287][nl76905b] 48B video sh,  codec(7, profile=High, level=3.1, 1280x720, 0kbps, 0.0fps, 0.0s)
[2023-09-12 07:30:47.651][INFO][567287][72lcz3v5] Hybrid cpu=1.00%,366MB, cid=22,1, timer=62,0,0, clock=0,44,4,1,0,0,0,0,0, free=1, objs=(pkt:0,raw:0,fua:0,msg:432,oth:0,buf:0)
[2023-09-12 07:30:48.090][INFO][567287][83690131] Process: cpu=1.00%,366MB, threads=2
[2023-09-12 07:30:49.529][WARN][567287][nl76905b][62] EdgeIngester: Ignore error, code=1011(SocketTimeout)(Socket io timeout) : recv message : recv interlaced message : read basic header : basic header requires 1 bytes : read bytes : timeout 5000 ms
thread [567287][nl76905b]: ingest() [./src/app/srs_app_edge.cpp:619][errno=62]
thread [567287][nl76905b]: recv_message() [./src/protocol/srs_protocol_rtmp_stack.cpp:341][errno=62]
thread [567287][nl76905b]: recv_interlaced_message() [./src/protocol/srs_protocol_rtmp_stack.cpp:792][errno=62]
thread [567287][nl76905b]: read_basic_header() [./src/protocol/srs_protocol_rtmp_stack.cpp:887][errno=62]
thread [567287][nl76905b]: grow() [./src/protocol/srs_protocol_stream.cpp:162][errno=62]
thread [567287][nl76905b]: read() [./src/protocol/srs_protocol_st.cpp:559][errno=62]
[2023-09-12 07:30:49.734][INFO][567287][y2g20663] <- EPB time=24539, msgs=0, okbps=0,0,0, ikbps=0,0,0
[2023-09-12 07:30:50.188][ERROR][567287][y2g20663][4] edge push get server control message failed. err=code=1007(SocketRead)(Socket read data failed) : recv interlaced message : read basic header : basic header requires 1 bytes : read bytes : read
thread [567287][y2g20663]: recv_message() [./src/protocol/srs_protocol_rtmp_stack.cpp:341][errno=4]
thread [567287][y2g20663]: recv_interlaced_message() [./src/protocol/srs_protocol_rtmp_stack.cpp:792][errno=4]
thread [567287][y2g20663]: read_basic_header() [./src/protocol/srs_protocol_rtmp_stack.cpp:887][errno=4]
thread [567287][y2g20663]: grow() [./src/protocol/srs_protocol_stream.cpp:162][errno=4]
thread [567287][y2g20663]: read() [./src/protocol/srs_protocol_st.cpp:566][errno=4](Interrupted system call)
[2023-09-12 07:30:50.202][INFO][567287][y2g20663] edge change from 200 to state 0 (init).
[2023-09-12 07:30:50.202][INFO][567287][y2g20663] TCP: before dispose resource(RtmpConn)(0x6120003790c0), conns=2, zombies=0, ign=0, inz=0, ind=0
[2023-09-12 07:30:50.203][ERROR][567287][y2g20663][4] serve error code=1011(SocketTimeout)(Socket io timeout) : service cycle : rtmp: stream service : rtmp: publish timeout 5000ms, nb_msgs=1402
thread [567287][y2g20663]: do_cycle() [./src/app/srs_app_rtmp_conn.cpp:262][errno=4]
thread [567287][y2g20663]: service_cycle() [./src/app/srs_app_rtmp_conn.cpp:456][errno=4]
thread [567287][y2g20663]: do_publishing() [./src/app/srs_app_rtmp_conn.cpp:1035][errno=62](Interrupted system call)
[2023-09-12 07:30:50.203][INFO][567287][6n21y12c] TCP: clear zombies=1 resources, conns=2, removing=0, unsubs=0
[2023-09-12 07:30:50.203][INFO][567287][y2g20663] TCP: disposing #0 resource(RtmpConn)(0x6120003790c0), conns=2, disposing=1, zombies=0
[2023-09-12 07:30:52.532][INFO][567287][nl76905b] complex handshake success.
[2023-09-12 07:30:52.533][INFO][567287][nl76905b] protocol in.buffer=0, in.ack=0, out.ack=0, in.chunk=128, out.chunk=128
[2023-09-12 07:30:52.533][INFO][567287][nl76905b] connected, version=5.0.178.0, ip=10.0.0.2, pid=489820, id=0, dsu=1
[2023-09-12 07:30:52.534][INFO][567287][nl76905b] edge-pull publish url rtmp://10.0.0.2:1935/live/19059, stream=19059 as 19059
[2023-09-12 07:30:52.651][INFO][567287][72lcz3v5] Hybrid cpu=0.00%,358MB, cid=12,1, timer=62,0,0, clock=0,48,1,0,1,0,0,0,0, free=1, objs=(pkt:0,raw:0,fua:0,msg:171,oth:0,buf:0)
[2023-09-12 07:30:53.095][INFO][567287][83690131] Process: cpu=0.00%,358MB, threads=2
  1. SRS Config:
listen              1935;
max_connections     1000;
daemon              off;
srs_log_tank        console;

http_server {
    enabled         on;
    listen          8080;
    dir             ./objs/nginx/html;
}

http_api {
    enabled         on;
    listen          6161;
}

vhost __defaultVhost__ {
    cluster {
        mode            remote;
        origin          10.0.0.2:1935;
    }

    transcode {
        enabled     on;
        ffmpeg      ./objs/ffmpeg/bin/ffmpeg;
        engine ff {
            enabled         on; 

            vfilter {
            }

            vcodec          libx264;
            vbitrate        3200;
            vfps            25;
            vwidth          1280;
            vheight         720;
            vthreads        2;
            vprofile        high;
            vpreset         superfast;
            vparams {
                g       60;
                tune    zerolatency;
                vlevel  3.1;
            }

            acodec          aac;
            abitrate        256;
            achannels       2;
            aparams {
            }

            oformat         flv;
            output          rtmp://127.0.0.1:[port]/[app]?vhost=[vhost]/[stream]_[engine];
        }
    }

    http_hooks {
        enabled         on;
        on_publish      *******;
    }
}

Replay

Step 1: I'm streaming using Ffmpeg on SRS. This screenshot is while broadcasting

11

Step 2: When I turn off the broadcast, only a client watching with the local ip remains. In my opinion, when the OBS broadcast is turned off, FFMPEG does not terminate and remains as a local viewer.

22

Expect

Once the broadcast is closed, all FFMPEG broadcasts related to the broadcast must also be terminated.

winlinvip commented 8 months ago

The transcoding feature should not be used on Edge because the stream in Edge is only triggered when playing. It is at this point that the transcoding stream is activated.

For instance, if the original stream is live/livestream, it will only be converted to live/livestream_ff when this stream is being played.

If no one is playing live/livestream, attempting to directly play live/livestream_ff will result in failure.

TRANS_BY_GPT4