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
11.84k stars 1.49k forks source link

Recorded video is slower 3x-10x than streaming one #3461

Closed onorua closed 3 months ago

onorua commented 3 months ago

Which version are you using?

v1.8.2-27-g42724987

Which operating system are you using?

Describe the issue

config for recording:

  # Record streams to disk.
  record: yes
  # Path of recording segments.
  # Extension is added automatically.
  # Available variables are %path (path name), %Y %m %d %H %M %S %f %s (time in strftime format)
  recordPath: ./recordings/%path/%Y-%m-%d_%H-%M-%S-%f
  # Format of recorded segments.
  # Available formats are "fmp4" (fragmented MP4) and "mpegts" (MPEG-TS).
  recordFormat: fmp4
  # fMP4 segments are concatenation of small MP4 files (parts), each with this duration.
  # MPEG-TS segments are concatenation of 188-bytes packets, flushed to disk with this period.
  # When a system failure occurs, the last part gets lost.
  # Therefore, the part duration is equal to the RPO (recovery point objective).
  recordPartDuration: 1s
  # Minimum duration of each segment.
  recordSegmentDuration: 10m
  # Delete segments after this timespan.
  # Set to 0s to disable automatic deletion.
  recordDeleteAfter: 0s

According to the recordSegmentDuration: 10m new file should be created every 10 minutes. In fact new file created every ~3 minutes:

-rw-r--r-- 1 root root  37380737 Jun 12 18:56 2024-06-12_18-53-09-669902.mp4
-rw-r--r-- 1 root root  37553051 Jun 12 18:59 2024-06-12_18-56-29-339693.mp4
-rw-r--r-- 1 root root  37385706 Jun 12 19:03 2024-06-12_18-59-48-849732.mp4
-rw-r--r-- 1 root root  37396771 Jun 12 19:06 2024-06-12_19-03-08-000495.mp4
-rw-r--r-- 1 root root  37531342 Jun 12 19:09 2024-06-12_19-06-28-429795.mp4
-rw-r--r-- 1 root root  37340709 Jun 12 19:13 2024-06-12_19-09-46-560372.mp4
-rw-r--r-- 1 root root  37528050 Jun 12 19:16 2024-06-12_19-13-04-710220.mp4
-rw-r--r-- 1 root root  37437132 Jun 12 19:19 2024-06-12_19-16-22-910126.mp4
-rw-r--r-- 1 root root  37544076 Jun 12 19:22 2024-06-12_19-19-40-519848.mp4
-rw-r--r-- 1 root root  37358610 Jun 12 19:26 2024-06-12_19-22-58-720533.mp4

During realtime stream that I can see from WebRTC client - the video showed in normal speed. But the recorded one is like 3-4 times slower than it should be. In fact, the recorded file that created every 3 minutes, in VLC has 10 minutes length.

Describe how to replicate the issue

  1. enable recording
  2. start the server
  3. gst-launch-1.0 -v videotestsrc ! clockoverlay ! videoconvert ! x264enc tune=zerolatency bitrate=500 speed-preset=ultrafast key-int-max=30 ! mpegtsmux alignment=1 ! srtsink wait-for-connection=false sync=false enable-last-sample=true "uri=srt://{serverIP}:8890?mode=caller&streamid=publish:room502&udp-mss=1200"
  4. check WebRTC - it should be fine.
  5. Check recorded file with VLC or any MPEG4 player - it shows 3-10x slower than original video.

Did you attach the server logs?

no

Did you attach a network dump?

no, but I have attached video file with configuration to write segment every minute.

https://github.com/bluenviron/mediamtx/assets/407040/d81f5a33-745b-4959-81db-f27faa2708af

aler9 commented 3 months ago

Hello, thanks for providing detailed instructions on how to replicate the issue, however, this happens because you set the sync flag to false:

gst-launch-1.0 -v videotestsrc ! clockoverlay !  videoconvert ! x264enc tune=zerolatency bitrate=500 speed-preset=ultrafast key-int-max=30  ! mpegtsmux alignment=1  ! srtsink wait-for-connection=false sync=false enable-last-sample=true  "uri=srt://{serverIP}:8890?mode=caller&streamid=publish:room502&udp-mss=1200"

With sync=false, video frames are not sent in real time, but as soon as they are generated, and since the generation speed on your machine is greater than the clock time, you are sending 10 minutes of video in 3 minutes, resulting in 10 minutes-files generated every 3 minutes, as expected.

We never supported streaming non-realtime video, even though there are some clients that allow it.

Is there something i'm missing here?

onorua commented 3 months ago

Thank you, you are right, I've added is-live=1 to my videotestsrc and it is working as expected now. We are considering mediamtx for our realtime event. The sync=false option introduced by me to avoid client side delays during comparison of media servers. Hence I needed to have "full speed". Obviously I was wrong :)