Handling pitch when slowing down music videos

I have been listening to the songs we play as Vedat Minor and trying to upload them on YouTube. As my drums instructor Tunc Durmaz said countless times, I have a tendency to rush. (i.e. play with an accelerating metronome, as opposed to a steady one) So, partially out of not being satisfied with the outcome, and partially wanting Vedat to have a better portfolio on the web, I decided to digitally alter the videos, and change the tempo.

Changing the tempo of a song can simply be achieved by altering the speed of the video, I thought. Then, when I tried it using mencoder to do that, I figured out that slowing down a music video is not that easy. When you try and slow both audio & video down as if you are capturing just a slow motion video, the audio pitch is modified. Depending on the rate at which you slow down the video you may get pretty interesting results, by the way.

I had to either change the pitch after slowing down both audio and video, or separate them before altering the tempo, and then applying a different procedure to the audio, one which preserves pitch. Thankfully, I could find a way to do the former way using mencoder and a few other tools. Basically, you slow the video down, then separate the audio from it. After that you correct the pitch of the audio part, and merge it with a muted video of the slow version.

Let's start with slowing the video down, using the command below.

mencoder -ovc copy -oac mp3lame -speed 0.5 normal.mp4 -o slow.mp4

Here, 0.5 is obviously the ratio. Now, this may cause an error during execution, and pring something similar to the following message, in which case you need to add -srate 8000 option to the command.

Cannot set LAME options, check bitrate/samplerate, some very low bitrates (<32) need lower samplerates (i.e. -srate 8000).

We will then need a mute version of the video, which I took using avconv.

avconv -vn -i slow.mp4 slow.wav

Now comes correcting the pitch. I read about a command line tool called sox could be used, but I didn't want to go through its man page if there was an easier way. After a bit of Googling I downloaded Audacity. It is ridiculously simple to change the pitch using this tool. You open it, open the normal.mp4. Open Change Pitch from the Effect tab, and note the Frequency(Hz) value. (i.e. the one in the input box with the label from) Then, close that file and open slow.wav that you just created. Again using the Effect tab, get to Change Pitch panel, and enter the value you noted as the Frequency(Hz) value. (i.e. the one in the input box with the label to)

Now, get to File > Export and choose a location to export your .wav file, say by naming it slowcorrectpitch.wav. We now got the correct audio, and need only a muted version of the slow video. Hence, by using the following command, we can generate it. Note that the 0.5 in the following command should be exactly same with the ratio you used in the command you used to generate the slow video with the bad audio. (i.e. the first command given in this post)

mencoder -ovc copy -nosound -speed 0.5 normal.mp4 -o slow_no_sound.mp4

Finally, we merge the muted video (i.e. slownosound.mp4) and the audio with the orrect pitch (i.e. slowcorrectpitch.wav).

avconv -i slow_no_sound.mp4 -i slow_correct_pitch.wav -map 0.0 -map 1.0 correct_slow_version.mp4

You can now enjoy our music video with a slower tempo, but with the correct pitch.

One last note on the audio, though. Sometimes the pitch may not be corrected the way you'd like it to. Even though it was working with ratio value 0.9, I faced this issue when I tried the value 0.95 as an alternative. I couldn't fix the pitch even though I tried using sox, the command-line alternative to Audacity I mentioned earlier. But after guessing that issue might be related to the floating point arithmetic, I tried ratio as 0.94 and it worked properly. So, you may want to try the audio after you corrected its pitch, just to save the time of merging the muted video with a bad audio. Then, if it is faulty, you can start over and use a similar, but different ratio.

Hope I can get that inner metronome working, though. As the number of songs and performances we play increases, it becomes more and more disturbing to be off about the actual metronome of the songs.

In case you want to listen to the tunes we play, try listening the playlist I got on Youtube.