k4yt3x / video2x

A lossless video/GIF/image upscaler achieved with waifu2x, Anime4K, SRMD and RealSR. Started in Hack the Valley II, 2018.
https://video2x.org
GNU Affero General Public License v3.0
8.88k stars 907 forks source link

Video slowly getting out of sync (slower) than audio and subtitles #1132

Open arximboldi opened 4 days ago

arximboldi commented 4 days ago

This is the input (don't judge me):

image

The generated video slowly gets out of sync (it plays slower than the subtitles and audio, which are in sync relative to eachother).

Not sure what's going on...

arximboldi commented 4 days ago

Ok, so here is what video2x thinks is the number of frames: 40321

But nb_read_frames=41076...

ffprobe '[HR] Bible Black - Episode 1 [073E8ABB].mkv' -select_streams v:0 -count_frames -show_entries stream=nb_read_frames 

This would explain the difference... we are feeding less frames, and ffmpeg is stretching the content to fit the audio length, causing the delay...

arximboldi commented 4 days ago

I'm working on a fix...

arximboldi commented 4 days ago

Ok, so that was not the issue. I've changed the code to use the frame cound calculated by ffprobe... now it generates a video that is longer than the original one. Something's off... why is it reading more frames than it should? Is it interpolating and generating extra frames? Or maybe the frame rate information is wrong? Or is it variable frame rate?

arximboldi commented 3 days ago

I found a solution, that also fixes #780 ... I'll make a PR soon.