mpv-player / mpv

🎥 Command line video player
https://mpv.io
Other
28.57k stars 2.92k forks source link

Live streams falls behind #4892

Open ghost opened 7 years ago

ghost commented 7 years ago

mpv version and platform

mpv 0.26.0 (C) 2000-2017 mpv/MPlayer/mplayer2 projects
 built on UNKNOWN
ffmpeg library versions:
   libavutil       55.58.100
   libavcodec      57.89.100
   libavformat     57.71.100
   libswscale      4.6.100
   libavfilter     6.82.100
   libswresample   2.7.100
ffmpeg version: 3.3.4

Debian GNU/Linux stable-updates (sid)

Reproduction steps

mpv --no-cache --keep-open --hwdec=vdpau --hwdec-codecs=all --vo=vdpau rtsp://my-nvr.local:7447/xxxxxxxxxxxxxxxxxxxxxxxxx_2

I can provide live rtsp URL but I would rather not (it is my security camera facing fence gate)

Expected behavior

I have specified --no-cache option so I expect to have real-time video stream

Actual behavior

Log

http://sprunge.us/MhYJ

ghost commented 7 years ago

There are 2 caches, try --cache-secs=0 --demuxer-readahead-secs=0 to disable the packet cache (I think).

Generally mpv has no logic to catch up in live streams.

ghost commented 7 years ago

Thanks for quick answer, it disables cache but it still does not catch up. For example when I pause, wait few seconds and hit play again it does not catch-up. It continues like if the cache was still there even when it says zero.

ghost commented 7 years ago

That's most likely just buffered across network or server.

ghost commented 7 years ago

I did not know that could be happening. And I can not change settings of the server because it is bundled in the NVR software. Do you have any suggestion how could I achieve real time streaming? I saw that mpv has some sort of scripting, so maybe script for catch-up behavior?

dreness commented 7 years ago

Can you seek forward to catch up? If so, you could work around this by making an input command to un-pause and seek forward. Maybe a fancier version is a lua script that periodically tries to seek forward.

ghost commented 7 years ago

I can skip ahead. But unfortunately I have no idea on how to make this plugin/script.

dreness commented 7 years ago

@PSSGCSim One method would be to use a tiny bit of lua that executes some code at recurring intervals; the function add_periodic_timer would do it. See the add_periodic_timer example on https://github.com/mpv-player/mpv/blob/master/DOCS/man/lua.rst. Instead of calling 'print' within your periodic timer as in the example, you'd instead execute a command to seek forward, probably via mp.command - here's a script that shows a simple mp.command usage: https://github.com/mpv-player/mpv/blob/f1436658647aceb7ea58e595439fa6dd5c2cdb97/TOOLS/lua/ao-null-reload.lua#L7 The commands usable by mp.command are the same things you can assign to key binds via input.conf. If you're not familiar with input.conf or lua, you'll likely want to read up a bit first. The lua.rst doc is a good primer for lua scripts, and the command interface section of the mpv documentation describes all the the actions (commands) that can be triggered by various sources like key binds, lua calls to mp.command, notification / observer handlers, etc.

Of course, seeking forward means you will miss some stuff (whatever you seek past). A more delicate and advanced solution might be to slightly increase the playback speed if you (or rather, your periodically invoked function) notice that you're sufficiently behind realtime, and then bring it back to 1.0 as you approach realtime. This would require some tinkering to get right, but would be a good exercise.

rgaufman commented 5 years ago

I'm trying:

DISPLAY=:0 mpv --no-cache --keep-open --hwdec=vdpau --hwdec-codecs=all --vo=vdpau --cache-secs=0 --demuxer-readahead-secs=0 rtsp://127.0.0.1:10105/proxyStream

And I'm seeing like a 5 second delay :( - any ideas?

sodu-parisev commented 5 years ago

the same here, 5 seconds delay

alexballas commented 4 years ago

try mpv --no-cache --untimed

markg85 commented 4 years ago

I had this very same issue and got it solved with mixing the examples in this thread. mpv <source> --cache-secs=0 --demuxer-readahead-secs=0 --untimed

Is what i needed. --no-cache didn't seem to matter. Which has a bit of irony. I want to disable all caching and have to use functions that are not named as such. The function that should disable all caching (--no-cache) is not doing what you'd expect.

ghost commented 4 years ago

Neither is --cache-secs=0 etc. --untimed just plays video as fast as possible.

markg85 commented 4 years ago

Neither is --cache-secs=0 etc. --untimed just plays video as fast as possible.

I just tried it again and i really need all 3 of these commands to make it work properly. The video in this case is a live (from smartphone) cam stream over http.

ghost commented 4 years ago

You probably want --cache-pause=no, which is the thing that actually disables waiting until part of the cache is filled. --profile=low-latency might be useful too.

steve-o commented 3 years ago

MPV is missing a --video-sync=external type option to ffplay's -sync ext. The FFMPEG code speeds up the clock when buffer grows (presumably the demuxer), and slows down when it drains.

https://github.com/FFmpeg/FFmpeg/blob/master/fftools/ffplay.c#L93

https://github.com/FFmpeg/FFmpeg/blob/master/fftools/ffplay.c#L1458

https://github.com/FFmpeg/FFmpeg/blob/master/fftools/ffplay.c#L1575