mpv-player / mpv

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

--vf=loop of long video leads to massive memory consumption / leak #8745

Closed twilson90 closed 3 years ago

twilson90 commented 3 years ago

Important Information

Provide following Information:

Reproduction steps

mpv "long-video.mp4" --vf=loop=loop=-1:size=26182

(the size parameter in this case matches the total number of frames in the video, the -1 means loop forever)

Expected behavior

Memory consumption should remain low and more or less static.

Actual behavior

The memory consumption never stops growing for the duration of the looped video. On repeating the loop the memory consumption remains static. After several minutes of running a long 1280x720 video with the loop filter it had consumed all my machine's memory (8gb)

Log file

log.txt

Sample files

https://0x0.st/-A9E.mp4

jeeb commented 3 years ago

That is an FFmpeg filter (http://ffmpeg.org/ffmpeg-filters.html#loop).

See if you can replicate the same issue with just ffmpeg.c. If yes, it's an FFmpeg issue (https://trac.ffmpeg.org), not an mpv issue. What I guess is that the loop filter literally buffers all of that video that it will then loop (which matches the explanation of "on repeating the loop the memory consumption remains static"). If you think of it on video filter level, I don't think there's any other way for it to do the loop.

On a tool level, sure. We have tools on the player level to loop either your playlist or a file: mpv -h=loop

 --loop                           alias for loop-file
 --loop-file                      Choices: no inf yes (or an integer) (0 to 10000) (default: no)
 --loop-playlist                  Choices: no inf yes force (or an integer) (1 to 10000) (default: no)

 --ab-loop-a                      Time (default: no)
 --ab-loop-b                      Time (default: no)
 --ab-loop-count                  Choices: inf (or an integer) (0 to 2147483647) (default: inf)
Akemi commented 3 years ago

see the related issue https://github.com/mpv-player/mpv/issues/8703 why the loop options won't work for this use case. next time you should link that too.

twilson90 commented 3 years ago

I'm aware of all the built in looping functions, this is a very special case where I need the the video track to loop infinitely for the duration of audio. As soon as I looked into it I realised it was an ffmpeg issue, just simply the way the loop filter works. So instead I'm trying ffmpeg's movie filter instead with the looping parameter set to 0, chained to setpts=N/FRAME_RATE/TB to generate valid linear timestamps, and it appears to work much better. No memory problems!