PaulleDemon / tkVideoPlayer

Video player for tkinter.
MIT License
83 stars 25 forks source link

Improved TkVideoPlayer #27

Open Akascape opened 1 year ago

Akascape commented 1 year ago

Use this version if you want any of the following feature:

vguttmann commented 1 year ago

Have you also taken care of audio? As far as I'm aware, the base library doesn't play audio as of yet.

Akascape commented 1 year ago

@vguttmann The problem is with syncing audio video together without any delay. Issue already raised here : https://github.com/PaulleDemon/tkVideoPlayer/issues/2

But I guess we can add it, maybe in future I will try...

Akascape commented 8 months ago

@vguttmann I tried adding audio, but it doesn't sync properly with all video. https://github.com/Akascape/tkVideoPlayer

PaulleDemon commented 8 months ago

@Akascape have you tried using multiple threads? like a separate thread for Audio. Check this StackOverflow answer I wrote a while back. Also, is this branch up-to-date with the current release? I am pretty busy these days so I may not be able to contribute. If you make it work let me know, I'll look into it and merge.

Akascape commented 8 months ago

@PaulleDemon I am not using a different thread, I used container.decode(video=0, audio=0) method which yields both video and audio frames simultaneously. And it works perfectly with a video where the frames are ordered according to PTS (presentation time). While most of the videos with different codecs are not ordered like this and causes stuttering issue when played simultaneously.

I have asked the question here: https://stackoverflow.com/questions/78095616/syncing-audio-video-in-pyav-decoding

But someone said that it is not necessary for a file to have the frames in presentation order. We must sync them separately.

I also tried adding another thread for container.decode(audio=0) but again there is a sync issue as the video frames are not always shown in their respective pts. We have just used the sleep delay method which doesn't work for multiple framerates.

The audio frame decoding is realtime but video frame is not. Maybe we should find a way to display the video frames according to their pts to avoid sync delays.

So for now, it works well with some video files. I am still working on this.

Akascape commented 8 months ago

@PaulleDemon Fixed the audio issue, I used the buffering method which just store (10-30) frames per loop and show them according to audio pts, which is also realtime. but don't know if there will be any issue with files having variable frame rate Whenever you get time, test the implementation: https://github.com/Akascape/tkVideoPlayer/blob/master/tkVideoPlayer/tkvideoplayer.py

PaulleDemon commented 8 months ago

@Akascape Good to know you figured it out. I would still require some more people to test it out. Can you create a new pull request titled "added sound" or something so people can come test it out?

Also, I see one commit stating fixed memory leak, what memory leak is that about? Is it upgrading to pyav 11 or something?

Akascape commented 8 months ago

@PaulleDemon I found that there is a memory leak if the stream is not closed before loading a new file. It's simple, just add stream.close() to fix it.