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.79k stars 5.28k forks source link

ffmpeg exits after video is played #3843

Closed streamingsystems closed 3 months ago

streamingsystems commented 8 months ago

Describe the bug Hi,

I think I found another issue where ffmpeg is crashing when the video is completed similar to this issue:

https://github.com/ossrs/srs/issues/3803

After a video is played ffmpeg exists with this:

av_interleaved_write_frame(): Broken pipeq=-1.0 size= 36024kB time=00:02:37.73 bitrate=1870.9kbits/s speed= 1x [flv @ 0x7fb3d4106880] Failed to update header with correct duration. [flv @ 0x7fb3d4106880] Failed to update header with correct filesize. [flv @ 0x7fb3d07159c0] Failed to update header with correct duration. [flv @ 0x7fb3d07159c0] Failed to update header with correct filesize. Error writing trailer of rtmp://127.0.0.1:1935/live/map_1: Broken pipe [flv @ 0x7fb3d0714200] Failed to update header with correct duration. [flv @ 0x7fb3d0714200] Failed to update header with correct filesize. Error writing trailer of rtmp://127.0.0.1:1935/live/map_2: Broken pipe [flv @ 0x7fb3d1110fc0] Failed to update header with correct duration. [flv @ 0x7fb3d1110fc0] Failed to update header with correct filesize. Error writing trailer of rtmp://127.0.0.1:1935/live/map_3: Broken pipe frame= 3950 fps= 25 q=-1.0 Lq=-1.0 q=-1.0 q=-1.0 size= 38958kB time=00:02:38.03 bitrate=2019.4kbits/s speed= 1x video:37685kB audio:1236kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.094195% Error closing file rtmp://127.0.0.1:1935/live/map_1: Broken pipe Error closing file rtmp://127.0.0.1:1935/live/map_2: Broken pipe Error closing file rtmp://127.0.0.1:1935/live/map_3: Broken pipe

In issue 3803 it was a problem with ffmpeg but you were able to make a change to the server to work around this issue.

Version Latest To Reproduce

1) Download and extract the the ZIP file that contains 4 videos:

https://www.dropbox.com/scl/fi/q9wlzlafb75obu84e64v0/ffmpeg-map.zip?rlkey=7ahs16533ghdnfvddl51or0z6&dl=0

2) Run this command:

ffmpeg -stream_loop -1 -re -i 1.mp4 -stream_loop -1 -re -i 2.mp4 -stream_loop -1 -re -i 3.mp4 -stream_loop -1 -re -i 4.mp4 -map 0 -c copy -f flv rtmp://127.0.0.1:1935/live/map_0 -map 1 -c copy -f flv rtmp://127.0.0.1:1935/live/map_1 -map 2 -c copy -f flv rtmp://127.0.0.1:1935/live/map_2 -map 3 -c copy -f flv rtmp://127.0.0.1:1935/live/map_3

The video is 2m 38s long, when it reaches the end ffmpeg exits due to "Broken pipe".

Expected behavior

Ffmpeg should start over and loop the video forever.

Screenshots If applicable, add screenshots to help explain your problem.

Additional context Add any other context about the problem here.

winlinvip commented 3 months ago

First of all, this issues is entirely a bug of FFmpeg, not SRS. It fails to handle the EOF event, and leads to the failure of loop ingesting file stream.

Second, you should never rely on FFmpeg for IO handling and error handling, because FFmpeg is too complex to handle all events correctly and without bugs. Therefore, you must manage the FFmpeg, restarting it if it gets stuck or fails to run, like what SRS Stack does.