Syncing audio and video has got to be the most time consuming and somewhat frustrating task when it comes to making videos with decent audio. If you record your voice audio seperate from your camera audio, you know that syncing up the audio and the video in post production can be a pain in the ass. Luckily there's a program which runs under Linux that does this pretty much automatically with very little error.

If you had to do this manually, one way to do this is to extract the audio from the video, and then open both the camera audio and the USB mic audio in audacity and sync them there with the time shifter tool. Then export the newly mapped audio file as a fresh soundtrack and use that in my video, subsequently deleting the camera’s generated audio.

But most video editors let you see the audio waveform of both the camera and the microphone’s audio, so audio syncing can be done directly in the NLE. I don’t think this is as precise as doing it in Audacity because in Audacity I could literally zoom up to within microseconds on the waveform, but it is good enough for a video. But this is also be time consuming and sometimes very slow and frustrating when dealing with large video files.

I decided to search for ways to do this automatically and I found Shenidam

How to install Shenidam

First install Shendiam, as outlined in the Getting Started page.

You may run into some problems like I did. Some of the commands you may have to run to install dependencies are:

sudo apt install libsamplerate
sudo apt install libav-tools
sudo apt install libfftw3-double3
sudo apt install fftw3-dev
sudo apt install libboost-all
sudo apt install libsndfile1-dev
sudo apt install libsamplerate-dev

Some scripts to use Shenidam

Now you need some scripts to automatically sync the audio recorded separately to the video files.

If your camera does not encode audio in the same format that you recorded your external audio with, then Shenidam will silently fail to perform the syncing. For instance, I record my external audio in WAV format with Audacity, but the camera records in AAC format  So I must extract the camera audio, and convert and save in a .WAV container.

So first we must get the audio from the camera video files. I like to organize my files so that the camera and audio files have the same name, except of course that the camera files have the extension .MTS and the audio files from the microphone have the extension .WAV. So for example, if my audio files are 1.WAV, 2.WAV, etc. then my camera files should also be named 1.MTS, 2.MTS, etc.

To do this in DOS, you can use the following script to extract the audio, convert it to WAV format and add the prefix cam-

for /R %i in (*.MTS) DO ffmpeg -i "%i" -vn -c:a pcm_s16le "cam-%~ni.wav"

Or in bash the command is:

for i in *.MTS; do ffmpeg -i $i -vn -c:a pcm_s16le "cam-${i%%.*}.wav"; done

Next, armed with the audio from the microphone and the newly extracted camera audio, the following script will create a new .WAV file with mapped audio that you can use with the video files from your camera.

Here is the for loop that you can use in bash:

for f in cam-*.wav; do shenidam -b ${f#cam-} -i $f -o ${f%%.*}-mapped.wav; done

As an optional step, you can use this bash one-liner to strip the cam- prefix from the mapped audio files. This is just for added ease in finding your files. I would advise not to run this command in the same directory as the one which contains the audio files extracted from the camera.

for x in cam*; do mv $x `echo $x | cut -c 5-`; done

Done! Now you are ready to import the synchronized audio files and the camera files into your NLE for easy editing.

Stay in touch and sign up to Brett Vachon's Newsletter!

© 2019 Brett Vachon - Guitarist and composer
Back to Top