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

RTSP: FFmpeg convert to RTMP, the HLS TS file size is too short. #4027

Closed timfengzi closed 2 months ago

timfengzi commented 2 months ago

Describe the bug The TS files generated by the HLS recording feature of SRS 6.0 are only 1 KB in size.

Version Desribe your SRS Server version here. SRS6.0.113

Screenshots image

Additional context Log srs.log

Configuration

listen 1935;
max_connections 3000;
daemon off;
srs_log_tank file;

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

http_api {
    enabled on;
    listen 1985;
}

rtc_server {
    enabled on;
    listen 8000; # UDP port
    # @see https://ossrs.net/lts/zh-cn/docs/v4/doc/webrtc#config-candidate
    candidate $CANDIDATE;
}

srt_server {
    enabled on;
    listen 10080; # UDP port
    maxbw 1000000000;
    connect_timeout 4000;
    latency 20;
    peerlatency 20;
    recvlatency 20;
}

vhost __defaultVhost__ {
    rtc {
        enabled on;
        # @see https://ossrs.net/lts/zh-cn/docs/v4/doc/webrtc#rtmp-to-rtc
        rtmp_to_rtc on;
        # @see https://ossrs.net/lts/zh-cn/docs/v4/doc/webrtc#rtc-to-rtmp
        rtc_to_rtmp on;
    }
    http_remux {
        enabled on;
        mount [vhost]/[app]/[stream].flv;
    }
    hls {
        enabled on;
        hls_ts_file [app]/[stream]/[seq]-[timestamp].ts;
        hls_m3u8_file [app]/[stream]/[stream].m3u8;
    }
    http_hooks {
        enabled         on;
        on_publish      http://127.0.0.1:7071/controller/srs/onPublish;
        on_unpublish      http://127.0.0.1:7071/controller/srs/onUnPublish;
        on_hls             http://127.0.0.1:7071/controller/srs/onHls;
        on_play            http://127.0.0.1:7071/controller/srs/onPlay;
        on_stop             http://127.0.0.1:7071/controller/srs/onStop;
    }
}

TRANS_BY_GPT4

timfengzi commented 2 months ago

The entire SRS program will crash, rendering all pages inaccessible.

TRANS_BY_GPT4

winlinvip commented 2 months ago

It is a bug about converting RTSP to RTMP, there is a log "duration":1.23:

[2024-04-15 22:12:17.076][INFO][1537][41559egi] 45B video sh, codec(7, profile=Main, level=5.1, 3200x1800, 0kbps, 0.0fps, 0.0s)
[2024-04-15 22:12:17.077][INFO][1537][41559egi] 7B audio sh, codec(10, profile=LC, 1channels, 0kbps, 8000HZ), flv(16bits, 2channels, 44100HZ)
[2024-04-15 22:12:18.271][INFO][1537][41559egi] time diff to large=1293, next out=7072, new pkt=1440, set to new pkt

[2024-04-15 22:13:23.287][WARN][1537][41559egi][62] ignore task failed code=1018(StConnect)(ST connect server failed) : callback on_hls http://127.0.0.1:7071/controller/srs/onHls : http: post http://127.0.0.1:7071/controller/srs/onHls with {"server_id":"vid-4249b16","service_id":"0ta99422","action":"on_hls","client_id":"41559egi","ip":"127.0.0.1","vhost":"__defaultVhost__","app":"live","tcUrl":"rtmp://127.0.0.1:1935/live","stream":"3144002875-1360-49","param":"?ipc_id=3144002875-1360-49&id=492",
"duration":1.23,"cwd":"/","file":"./objs/nginx/html/live/3144002875-1360-49/2-1713190361081.ts","url":"live/3144002875-1360-49/2-1713190361081.ts","m3u8":"./objs/nginx/html/live/3144002875-1360-49/3144002875-1360-49.m3u8","m3u8_url":"live/3144002875-1360-49/3144002875-1360-49.m3u8","seq_no":2,"stream_url":"/live/3144002875-1360-49","stream_id":"vid-b933772"}, status=28671, res= : http: client post : http: connect server : http: tcp connect http 127.0.0.1:7071 to=30000ms, rto=30000ms : tcp: connect 127.0.0.1:7071 to=30000ms : connect to 127.0.0.1:7071

I think it's related to your stream content. Could you describe how to reproduce this issue? What's your RTSP client? Which browser did you use?

timfengzi commented 2 months ago

The network camera is utilizing FFmpeg to pull an RTSP stream and then convert it to an RTMP stream for broadcasting, using the SRS (Simple Real-time Server) on a Windows platform.

TRANS_BY_GPT4

winlinvip commented 2 months ago

Please use TCP for RTSP, do not use UDP, as UDP may have issues such as out-of-order packets that could result in incorrect timestamps.

If the issue cannot be resolved, encode the stream once with FFmpeg before pushing it to SRS.

This issue is not related to SRS; it pertains to the RTSP stream.

TRANS_BY_GPT4

timfengzi commented 2 months ago

It is utilizing TCP.

TRANS_BY_GPT4

winlinvip commented 2 months ago

I have mentioned before, this is not an issue with SRS; please seek assistance on the FFmpeg forum.

TRANS_BY_GPT4