I recorded some old VHS tapes to digitize them to video movies and burn them on DVDs. Sadly the audio had a shift or drift of around one and a half second over the one hour video. Here a small solution to fix this problem with the help of Kdenlive and FFmpeg.
My example is a
ffmpeg -i record.mp4 -vn audio.wav
The extracted audio should be available as
We can easily detect the audio drift by importing
audio.wav into Kdenlive via drag and drop.
On the screenshot above is visible that
audio.wav have different length. My Kdenlive has shows the
length in hours, minutes, seconds and at the end a twenty-fifth of a second.
I can calculate for both file the amount of 1/25 seconds with the following
formular. Please note that
s/25 is something like a variable
for a twenty-fifth of a second.
(((60 * h) + m) * 60 + s) * 25 + s/25
|file||calculation||result in s/25|
We can calculate the speedup for the audio with
for example. The only important thing is that the calculator has enough
digits, cause the result will be very close to
important is that we divide the amount of s/25 from
by the amount of s/25 from
python Python 2.7.13 (default, Jan 19 2017, 14:48:08) [GCC 6.3.0 20170118] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> 68831.0 / 68852.0 0.9996949979666531
We strech the
audio.wav file with the following command and the
factor from above. The command will write the result to the file
ffmpeg -i audio.wav -filter:a atempo="0.9996949979666531" audio_streched.wav
Afterwards we import
audio_streched.wav into Kdenlive via drag
and drop and delete
audio.wav. Video and audio should have now
the same length.
record.mp4 source to Video channel and click in
the menu item Clip on Split Audio.
Afterwards click in the menu item Timeline on Ungroup Clips
and delete the audio channel. There should be just a muted video channel
now. Drag the
audio_streched.wav source into the Audio
We can now render the video with the streched audio to an
file with the button Render.