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

When streaming at a very low frame rate, the video recorded by the DVR is sped up. So, a 30-minute recording is compressed into just 40 seconds. #3829

Closed wangborong12345 closed 8 months ago

wangborong12345 commented 9 months ago

Describe the bug When streaming at a lower frame rate and enabling DVR recording, the recorded video is sped up. Even though the recording lasted for about 30 minutes, the final recorded flv file is only around 40 seconds long. Also, the video content plays at a faster speed.

Version I'm running it using DOCKER, and the version of SRS I'm using is "v5.0.60".

To Reproduce Here's the configuration file:


listen              1935;
max_connections     1000;

srs_log_tank        console;
daemon              off;
http_api {
    enabled         on;
    listen          1985;
    crossdomain     on;
    raw_api {
        enabled on;
        allow_reload on;
    }
}
http_server {
    enabled         on;
    listen          8080;
    dir             ./objs/nginx/html;
}
rtc_server {
    enabled on;
    protocol tcp;
    #listen 8000; # UDP port
    # @see https://github.com/ossrs/srs/wiki/v4_CN_WebRTC#config-candidate
    candidate myip;
    tcp {
        enabled on;
        listen 8001;
    }
}

# See https://github.com/ossrs/srs/issues/1147
srt_server {
    enabled on;
    listen 10080; # UDP port
    maxbw 1000000000;
    connect_timeout 4000;
    latency 20;
    peerlatency 20;
    recvlatency 20;
}

include containers/data/config/srs.server.conf;

vhost __defaultVhost__ {
    http_remux {
        enabled     on;
        mount       [vhost]/[app]/[stream].flv;
    }
    rtc {
        enabled     on;
        nack on;
        twcc on;
        stun_timeout 30;
        dtls_role passive;
        # @see https://github.com/ossrs/srs/wiki/v4_CN_WebRTC#rtmp-to-rtc
        rtmp_to_rtc on;
        keep_bframe off;
        # @see https://github.com/ossrs/srs/wiki/v4_CN_WebRTC#rtc-to-rtmp
        rtc_to_rtmp on;
        pli_for_rtmp 6.0;
    }
    srt {
        enabled     on;
        srt_to_rtmp on;
    }

    dvr {
        enabled             on;
        dvr_apply all;
        dvr_path            ./dvrdata/[stream]/[2006]/[01]/[02]/[timestamp].flv;
        dvr_plan            segment;
        dvr_duration        60;
        dvr_wait_keyframe   on;
    }

    # For backend server to verify client.
    http_hooks {
        enabled         on;
        on_publish      http://myip/srs/hook/on_publish;
    }

    include containers/data/config/srs.vhost.conf;
}

Here's my Docker command:

docker rm -f srs 2>/dev/null &&
touch containers/data/config/srs.server.conf containers/data/config/srs.vhost.conf &&
echo "TODO: FIXME: Remove it after SRS supports empty config file." &&
if [[ ! -s containers/data/config/srs.server.conf ]]; then echo '# OK' > containers/data/config/srs.server.conf; fi &&
if [[ ! -s containers/data/config/srs.vhost.conf ]]; then echo '# OK' > containers/data/config/srs.vhost.conf; fi &&
docker run --name srs --rm -it \
    -v $(pwd)/containers/data/config:/usr/local/srs/containers/data/config \
    -v $(pwd)/containers/conf/srs.release-mac.conf:/usr/local/srs/conf/srs.conf \
    -v $(pwd)/containers/objs/nginx:/usr/local/srs/objs/nginx \
    -v $(pwd)/dvrdata:/usr/local/srs/dvrdata \
    -p 1935:1935/tcp -p 1985:1985/tcp -p 8080:8080/tcp -p 8000:8000/udp -p 8001:8001/tcp -p 10080:10080/udp \
    -e SRS_RTC_SERVER_PROTOCOL=tcp \
    -e SRS_RTC_SERVER_TCP_LISTEN=8001 \
    -e SRS_RTC_SERVER_TCP_ENABLED=on \
    -e SRS_VHOST_RTC_RTC_TO_RTMP=on \
    -e CANDIDATE="myip" \
    -e SRS_HTTP_API_CROSSDOMAIN=on \
    -e SRS_VHOST_DVR_DVR_PLAN=segment \
    -e SRS_VHOST_DVR_DVR_PATH=./dvrdata/[stream]/[2006]/[01]/[02]/[timestamp].flv \
    -e SRS_VHOST_DVR_DVR_DURATION=60 \
    -e SRS_VHOST_DVR_DVR_WAIT_KEYFRAME=on \
    -e SRS_VHOST_DVR_TIME_JITTER=on \
    -d registry.cn-hangzhou.aliyuncs.com/ossrs/srs:v5.0.60 ./objs/srs  -c conf/srs.conf

ffmpeg streaming command

ffmpeg -f dshow -framerate 2 -i "video=my device" -c:v libx264 -x264-params bframes=0 -profile:v baseline -b:v 100k -s 1280x720 -preset veryfast -tune zerolatency -pix_fmt yuv420p -f flv myurl

Expected behavior I think the length of my stream should match the duration of the video file, and it should play at normal speed (without the player speeding it up). Also, regarding the DVR's "dvr_duration" setting, it seems like it's the duration the video file reaches before it stops, not the recording duration, right?

Screenshots Here's a screenshot of when the recording started. image Here's a screenshot of when the recording ended. image

It started at 9.41 and ended at 10.15, but the recorded video is only 41 seconds long.

Additional context Add any other context about the problem here.

TRANS_BY_GPT4

wangborong12345 commented 8 months ago

I tried again to record to a local file using ffmpeg. ffmpeg -f dshow -framerate 2 -i "video=my device" -c:v libx264 -x264-params bframes=0 -profile:v baseline -b:v 100k -s 1280x720 -preset veryfast -tune zerolatency -pix_fmt yuv420p -f flv out.flv The duration of the video is normal.

TRANS_BY_GPT4

wangborong12345 commented 8 months ago

see https://ossrs.net/lts/zh-cn/docs/v5/doc/time-jitter