alopatindev / sync-audio-tracks

Audio tracks synchronization command-line tool for video editors that don't support it
Apache License 2.0
61 stars 9 forks source link

Does this work with files both out of sync and in different speeds #6

Closed Leseratte10 closed 2 years ago

Leseratte10 commented 2 years ago

I haven't tried these scripts so far, but they look pretty interesting. What I'm planning to use this for is to mix together multiple copies of a movie - like taking some audio streams from an online source, some audio streams from a BluRay, some from a PAL DVD and some from an NTSC DVD, and mix them all into a full MKV with the best quality and as many different languages / audio streams as possible.

In addition to being out of sync (DVD might have more or less empty / black frames at the beginning of the video and silence in the beginning of the audio), this usually also means the speed of the audio tracks is wrong. One movie source might be 24 fps, one might be 23.976 fps, the other might be 25 fps. So I would need to speed up or slow down all the audio files to one common "speed" - usually the speed of the video source the final file is going to contain.

Are these scripts able to handle this as well? I can see a "guess-speedup.sh" file, but that looks like a standalone file and is not executed when running the "sync-audio-tracks.sh" file mentioned in the readme. How would I go about syncronizing multiple audio tracks if they are both A) out of sync and B) in different speeds? Can the sync-audio-tracks script handle two audio files having different speeds?

Do I just run sync-audio-tracks first to align the audio tracks, then run guess-speedup afterwards? Would that even work properly or would the files be out of sync again after I fix the speedup?

alopatindev commented 2 years ago

Thanks for interesting question, it bothers me for a long time. Currently it doesn't work with audios with wrong speed and/or skipped frames.

guess-speedup.py is an attempt to find speedup multiplier for very simple case (it won't help if speed is variable and/or there are skipped frames/scenes). You may try to manually run it, apply the speedup and then sync the audios (but don't expect very much):

ffmpeg -i good.wav -filter:a "atempo=$(./guess-speedup.py good.wav bad.wav)" good_spedup.wav
./sync-audio-tracks.sh good_spedup.wav bad.wav out.wav 900

Something like that. Currently guess-speedup.py works on POSIX-compatible OSes.

I recommend to avoid applying atempo or similar filters to audios that definitely don't need any speedup/slowdown, as it's potentially destructive operation.