VideoPlayerFFMPEG buffer issues

I struggled with VideoPlayerFFMPEG quite a lot recently.

Upon posting this issue, I found a solution which I’d like to share.

Faulty setup (on macOS with M1 chip):

val videoPlayer = VideoPlayerFFMPEG.fromFile("path/to/myVideo.mp4")
videoPlayer.ended.listen { videoPlayer.restart() }

extend {

Command line output:

error? -35
error? -35
error? -35
error? -35
error? -35
error? -35

(keeps spamming each frame)
Eventually, the replay stops and stays on the last image. Also the spam changes to:

 WARN [Thread-4(decoder)] o.o.f.Decoder                   ↘ video queue is almost full. [video queue: 49, audio queue: 0]

A few seconds later, the app crashes with:

├─ kotlin.concurrent.Threads.thread.thread.{ }.run(Thread.kt:30)
├─ ...
↑ queue overflow: 42 43 (Error) 

By deafult, the mode parameter of fromFile is on PlayMode.BOTH (for video + audio).
As I was interested in video only and audio was introducing heavy lag, I changed the mode to PlayMode.VIDEO. The frames were available in time again, and the frame queue was cleared fast enough to not overflow and crash.

1 Like

On that topic, I found the classes VideoStatistics and VideoPlayerConfiguration that are related to VideoPlayerFFMPEG.

Those could be data classes.
One benefit: They could be used in their “canonic” string representation. I found that to be useful during debugging this issue.

This way, you could use them like this:

// "VideoStatistics(videoFrameQueueSize=50, ...)"
1 Like

Thank you for sharing your discoveries! I have also in the past resorted to VIDEO only mode.

I guess we need to do some check why it’s not playing as smooth as it should, why sound causes issues, and avoid repeating the same message over and over. I like that in the console in browsers it can say indicate that the message was printed multiple times.