mpv --of=rtsp | rtsp streaming way to fast
Closed this issue · 4 comments
mpv Information
mpv 0.37.0 Copyright © 2000-2023 mpv/MPlayer/mplayer2 projects
libplacebo version: v6.338.2
FFmpeg version: 6.1.1-3ubuntu5
FFmpeg library versions:
libavutil 58.29.100
libavcodec 60.31.102
libavformat 60.16.100
libswscale 7.5.100
libavfilter 9.12.100
libswresample 4.12.100
Other Information
- Linux version: Ubuntu 24.04 LTS
- Kernel Version: 6.8.0-48-generic
- GPU Model: Advanced Micro Devices, Inc. [AMD/ATI] Cezanne [Radeon Vega Series / Radeon Vega Mobile Series]
- Mesa/GPU Driver Version: OpenGL version string: 4.6 (Compatibility Profile) Mesa 24.0.9-0ubuntu0.2
- Window Manager and Version: wayland 1.34-1
- Source mpv:
- Introduced in version:
Reproduction Steps
I want to stream to my rtsp server by this command:
mpv in.mkv --ovc=mpeg4 --of=rtsp --o=rtsp://192.168.0.83:8554/mystream
in.mkv includes following stream:
Stream #0:0(ger): Video: h264 (High), yuv420p(tv, bt470bg/unknown/unknown, progressive), 1920x1080 [SAR 1:1 DAR 16:9], 25 fps, 25 tbr, 1k tbn (default)
which has 25fps
Expected Behavior
Stream it to rtsp server with correct fps, in this case with 25fps
Actual Behavior
It is streaming as fast as it can encode it, in this case with around 100fps
Log File
Sample Files
it happens with any video file
I carefully read all instruction and confirm that I did the following:
- I tested with the latest mpv version to validate that the issue is not already fixed.
- I provided all required information including system and mpv version.
- I produced the log file with the exact same set of files, parameters, and conditions used in "Reproduction Steps", with the addition of
--log-file=output.txt
. - I produced the log file while the behaviors described in "Actual Behavior" were actively observed.
- I attached the full, untruncated log file.
- I attached the backtrace in the case of a crash.
This is not a bug. Encoding does not have a "realtime" mode.
Consider using ffmpeg instead.
I managed to do this with:
--vf-add="realtime"
and it works as it should.
@efschu That's very interesting:
https://ffmpeg.org/ffmpeg-filters.html#realtime_002c-arealtime
Slow down filtering to match real time approximately.
These filters will pause the filtering for a variable amount of time to match the output rate with the input timestamps. They are similar to the
-re
option to ffmpeg.They accept the following options:
- limit: Time limit for the pauses. Any pause longer than that will be considered a timestamp discontinuity and reset the timer. Default is 2 seconds.
- speed: Speed factor for processing. The value must be a float larger than zero. Values larger than 1.0 will result in faster than realtime processing, smaller will slow processing down. The limit is automatically adapted accordingly. Default is 1.0.
Not sure how stable that is though. It sounds like it may be implemented in a similar way as -re
. Would be worth investigating ffmpeg source to see how -re
aka -readrate 1
is implemented. If it actually inserts this filter, then they are equivalent.
But another solution is this:
mkfifo /tmp/mpv-pipe
mpv --o=/tmp/mpv-pipe --of=nut --ovc=rawvideo --oac=pcm_s16le
ffmpeg -hide_banner -re -f nut -i /tmp/mpv-pipe <your encoding options>
The correct command I am using with working fps is:
mpv --hwdec=yes --vf-add="realtime" --ovc=libx264 --ovcopts="preset=fast" --ovcopts="qp=18" --ovcopts="bf=0" --of=rtsp --audio-samplerate=44100 --o=rtsp://192.168.0.83:8554/mystream --vf-add="realtime" --vf=vapoursynth="script.vpy" --vf-add="realtime" --input-ipc-server=mpvsocket --framedrop=decoder+vo --idle
I dunno why I had to add --vf-add="realtime"
multiple times, but I have some videos where this was the only working command so far.
So no need to pipe a video around, mpv can do all what is needed.