icon robot josef

Audio stuff, unsorted

Pitch shifting and time stretching with FFmpeg

The relevant audio filters in ffmpeg for this matter are

· asetrate and aresample this filter adjusts the sample rate; altering the sample rate will stretch or shrink the audio, thereby changing the pitch and length of the audio.

· atempo this filter adjusts the tempo of the audio; altering the tempo will change the length of the audio, without changing the pitch.

Transcodes are usually between PAL, NTSC and 24fps material.
Therefore, one needs conversion factors

The audio filters work with seven decimal digits of precision (float32).

Let’s create an audio file for testing purposes, 440 Hz, 1000 seconds long, with a sampling rate of 48kHz:

ffmpeg -f lavfi -i "sine=f=440:r=48000" -t 1000 1000.440.wav

The resulting file has a run time of 00:16:40.000.

Now, let’s assume this audio file is from a PAL source and has been sped up from an original cinematographic source and the pitch is correct, so all you want is an audio track with that longer run time but no pitch correction, this will do:

ffmpeg -i 1000.440.wav -af "atempo=24/25" 1042.440.wav

The resulting file has a run time of 00:17:21.663 with no change in pitch.

In case the same file has an unnatural pitch due to incorrect speeding up, you want to correct that too:

ffmpeg -i 1000.440.wav -af "asetrate=48000*0.96, aresample=48000" 1042.422.wav

The resulting file has a slowed down run time of 00:17:21.663, and the high pitch is corrected.

You may want to correct for a bad pitch without changing the run time:

ffmpeg -i 1000.440.wav -af "atempo=25/24, asetrate=48000*0.96, aresample=48000" 1000.422.wav

The resulting file has a run time of 00:16:40.000, and the high pitch is corrected.

It may be confusiong which filter with which calues does what, so I wrote me a little script that helps me doing things right.

via
via

Extracting AC3 from TrueHD

eac3to input.thd+ac3 output.ac3 -core

via