Slow motion a video with preserved sound pitch and save to file
This guide shows you, on Linux, how to make a slow motion video of an mp4 video (in this case downloaded from Youtube), with the pitch of the sound intact. There is probably a one-line command to do this in mencoder, ffmpeg or vlc, if so please enlighten me. This guide starts with a terse summary, and then continues with a more verbose explanation.
Summary
You need:
- mencoder (part of mplayer)
- ffmpeg
- sox
All are open source and freely downloadable.
Assume the video is called "normal.mp4", that should be made into a slow motion video called "slomo.mp4", with the pitch intact so we do not get those grovelling noises.
First to slow down the video to half speed, use mencoder, part of mplayer:
mencoder -ovc copy -oac mp3lame -speed 0.5 normal.mp4 -o slow.mp4
Extract the sound with ffmpeg:
ffmpeg -vn -i slow.mp4 slow.wav
You may now discard the slow.mp4 file.
Pitch it up:
sox slow.wav slow_but_pitched_up.wav pitch 1200
Make a slow version of normal.mp4 with no sound:
mencoder -ovc copy -nosound -speed 0.5 normal.mp4 -o slow_no_sound.mp4
You can put sound and video together with with mencoder:
mencoder -ovc copy -audiofile slow_but_pitched_up.wav -oac faac slownosound.mp4 -o slomo.mp4
or use ffmpeg:
ffmpeg -i slownosound.mp4 -i slow_but_pitched_up.wav -map 0.0 -map 1.0 slomo.asf
(the sound needs to be compressed above, methinks)
If you can make an mp4 file instead of an asf file, so much better. On my machine it complained about not having the correct codec for sound; I am still looking into that.
Slow motion an mp4 video on Ubuntu Linux 9.10
--longer explanation and screenshots --
If you watch a video in vlc, you can slow it down, the sound is slower but stays at the original pitch, which is neat. I was unable to find a "Ok, good, now play through this and save it to a file" setting in vlc, so below is the road i treaded to finally convert a video file into a slow motion video file, with pitch intact.
We have two video processing tools at our disposal: ffmpeg and mencoder. ffmpeg does not have a slow-down option so we cannot use it for slowing down the video, instead we need to use mencoder. First to slow down the video to half speed, use mencoder, part of mplayer:
mencoder -ovc copy -oac mp3lame -speed 0.5 normal.mp4 -o slow.mp4
This will slow the video down to half speed, but unfortunately it also speeds down the sound. Mplayer has a switch for affecting the pitch but mencoder does not pick it up.
The -speed flag above indicates the speed, with 0.5 being half speed.
So far I have been unable to make mencode preserve the pitch (i.e pitch shift it back), but sox can pitch shift. However it only operates on sound files. So, the sound of the mp4 file needs to be separated out, then sox can operate on it, then we combine the sound and video again.
Separating out the sound
On my Ubuntu 9.10 I hade to install "libavcodec-extra" to get it to work. The command is like this:
ffmpeg -vn -i slow.mp4 slow.wav
Now sox can operate on it. AFAICT sox should be able to read mp3 too, but not on my machine, despite library installations and hand waving.
Pitching up the sound
Now sox can pitch it up
sox slow.wav slow_but_pitched_up.wav pitch 1200
Sox is special in that it wants the input and output files first, and then after them, the command line arguments. Sox has a flag called "pitch" pitch takes among other things a percentage value, where 100 is one semitone, and hence 1200 is an octave. We want an octave shift since we slowed down the the video to 50%, and an octave is a doubling of frequency (pitch).
Combining slow motion video and pitched up sound
Make a slow version of normal.mp4 with no sound:
mencoder -ovc copy -nosound -speed 0.5 normal.mp4 -o slow_no_sound.mp4
You can now put sound and video together with with mencoder:
mencoder -ovc copy -audiofile slow_but_pitched_up.wav -oac faac slownosound.mp4 -o slomo.mp4
There is some problem with that file though since ffmpeg reports:
Seems stream 0 codec frame rate differs from container frame rate: 29.97 (30000/1001) -> 14.99 (15000/1001)
It plays fine in vlc, though
You can use ffmpeg like so:
ffmpeg -i slownosound.mp4 -i slow_but_pitched_up.wav -map 0.0 -map 1.0 slomo.asf
If you can make an mp4 file instead of an asf file, so much better. On my machine it complained about not having the correct codecs with ffmpeg.
Combining video and sound with vlc
If yu would prefer to put sound and video together with vlc instead of mencoder or ffmpeg, here is how to do it:
vlc has a gui for combining sound and video for different files. First, for it to work I had to produce a slow version of the video with no sound, so rerun the command from the beginning of the guide, but make a video file with no sound:
mencoder -ovc copy -nosound -speed 0.5 normal.mp4 -o slow_no_sound.mp4
Then the GUI in vlc can combine them. Start vlc and choose "Convert/Save" from the "File" menu:
In the dialogue, select your slow motion file with no sound. Tick "Show more options", "Play another media synchronously" and click "Browse" to add extra media, and select the sound file there.
Click "Converts/Save" in the above dialog, and you get the below dialog:
Here you have to experiment a little to select a profile that uses codecs that
- you have on your system
- vlc realises you have on the system
Happy slow motioning!
There is this command in vlc, I wonder if it could be used for something:
--audio-time-stretch, --no-audio-time-stretch Enable time streching audio (default enabled) This allows to play audio at lower or higher speed withoutaffecting the audio pitch (default enabled)