-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Audio and video are out of sync for longer duration shots #25
Comments
A possible solution could be to get the real duration of the frames to convert (300 frames / 25 fps = 12 seconds) and get the difference. Using the difference, some sort of algorithm could be created to speed up the video using the video filter tag.
|
From Linux goesZen:
Coupled with your concerns on average FPS shifting and some frames not being shot at all, we can assume that the recorded
Of course, I am not a certified mathematician, as I only used the two cases in example to formalize the algorithm. Props to my friends, Henry and CK for giving me tips on the algorithm! Do not know C# in depth either, so could not send a pull request. As a note, you might want to add this as something optional until all users have no issues. |
edit: I see now you are using ffmpeg.exe and not libffmpeg. My advice may not apply I solved this in my toy x264 wrapper by using a 1/1000 timebase (milliseconds) and timestamping the frames instead of assuming a fixed FPS. So I expect frames on PTS 0, 33, 67, 100, 133, 167, 200, but if I have a slowdown then I might get 0, 33, 100, 133, etc., and the decoder / player will compensate for that. (As opposed to a fixed 30 FPS which would have timebase 1/30 and PTS 0, 1, 2, 3, 4, etc.) This works whether the video is fast, slow, or completely inconsistent. Since you guys are using ffmpeg, it is probably the same style of API as I used (x264 into FFmpeg). WebM is already Matroska-based, and this trick works for both MP4 and Matroska containers. The only catch is, this might cause VLC to report the video as "1000 FPS", but it will still play fine because there is only 30 / 60 FPS in reality. For ffmpeg.exe, you may be able to run a monotonic counter and just write the previous frame to disk twice when you detect that you've dropped a frame. It's a bit of a waste but it will keep the timing in line. |
Due to the nature of average FPS shifting and some frames not being shot at all, the video is a little shorter than the audio with some sections of video moving slower than others. The audio or video needs to be shrunken or expanded to match eachother. This can be done in FFmpeg but requires tweaking per recording.
Perhaps there are FFmpeg arguments that could automatically lengthen (or shrink) the video length to match audio duration.
For those that require spot-on audio to match their video, I would suggest to use different recording software.
The text was updated successfully, but these errors were encountered: