Skip to content

Conversation

@rikhuijzer
Copy link
Collaborator

@rikhuijzer rikhuijzer commented Mar 7, 2025

This problem might have been there since the start, but I only noticed it with a longer video. With longer videos, subtitles generated with whisper were going out of sync. The problem was that mp3 files were shorter than the original mp4 files due to encoding differences.

Closes #24.

@rikhuijzer rikhuijzer changed the title Fix video and audio going out of sync for longer videos Fix video and audio going out of sync Mar 7, 2025
@rikhuijzer rikhuijzer merged commit 8e47ea3 into main Mar 7, 2025
3 checks passed
@rikhuijzer rikhuijzer deleted the rh/duration-fix branch March 7, 2025 18:16
rikhuijzer added a commit that referenced this pull request Mar 12, 2025
Fixes #34.

This seems to work great. CI running times are halved and when
generating subtitles on a video that has 20 slides and takes multiple
minutes all subtitles remain in sync for the duration of the video
(related to #25) 🚀.

This is an example of the command that the code generates:

```sh
$ ffmpeg \
    -i _out/audio/1.wav \
    -loop 1 -framerate 1 -t "00:00:04.93" -i _out/image/1.png \
    -i _out/audio/2.wav \
    -loop 1 -framerate 1 -t "00:00:07.48" -i _out/image/2.png \
    -filter_complex \
    "
    [1:v]scale=-1:1080,format=yuv420p[v0]; \
    [3:v]scale=-1:1080,format=yuv420p[v1]; \
    [v0][0:a][v1][2:a] concat=n=2:v=1:a=1 [outv] [outa] \
    " \
    -map "[outv]" -r 30 -map "[outa]" -tune stillimage \
    -c:a opus \
    -strict -2 \
    -shortest \
    -movflags \
    +faststart \
    _out/out.mp4 
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use mkv during build

2 participants