Log in

View Full Version : Lower both video fps and audio pitch


VideoBeginner
4th February 2018, 18:06
My collection of MKV files are running video at 25 fps instead of 23.976. Audio, while synced ok, is running at 46.875 fps according to MediaInfo. The audio pitch is too high in correlation with the video's too-high frame rate.

How can I lower the frame rate and drop the pitch--be it one step or a few--hopefully without any quality loss?

Installed, I have:
- Avidemux
- AviSynth (though not particularly familiar with it)
- ffdshow
- ffmpeg
- Handbrake
- HandbrakeCLI
- MKVToolNix
- RipBOT
- VirtualDub
- VirtualDubMod (but these files crash it, so...)



(Multi-level question that i know is possibly not all possible with Avisynth, but I had to post somewhere! It always fascinates me to search online for an answer, see it asked 1,000 times but ansered only 50 times, yet the solution given is not clear enough to me or it "kind of works.")

sneaker_ger
4th February 2018, 18:30
First:
There are some players/filters that can do this on playback. If possible I would just use them as overall it's much less work and zero chance of you messing up the conversions (which often you only find out after you have deleted the original files).
For example it can be done in MPC-HC with (3rd party) reclock filter.


If you do need/want to convert anyways:
Open in AviSynth and change speed. E.g:
v=BlankClip(fps=25)
a=ffaudiosource("source.mkv")
AudioDub(v, a)
AssumeFPS(24000, 1001, true)
ResampleAudio(48000)
Then run through ffmpeg:
ffmpeg -i "script.avs" -b:a 640k "audio.ac3"

Then mux in mkvtoolnix:
mkvmerge -o "output.mkv" --default-duration 0:24000/1001fps --fix-bitstream-timing-information 0:1 --no-audio "source.mkv" "audio.ac3"

If there are subtitles they need to be stretched as well using --sync "[TrackID] (https://mkvtoolnix.download/doc/mkvmerge.html#mkvmerge.track_ids):0,25025/24000" for each track.
https://mkvtoolnix.download/doc/mkvmerge.html

(I theory you could also just apply the stretch to all tracks:
mkvmerge -o "output.mkv" --sync -1:0,25025/24000 --fix-bitstream-timing-information 0:1 --no-audio "source.mkv" "audio.ac3"
I usually prefer to use --default-duration for the video track, though.)

Note: this is just one way to get the job done. There are many others.

tebasuna51
5th February 2018, 11:58
Audio, while synced ok, is running at 46.875 fps according to MediaInfo.

Forget that audio fps 46.875, is not related with video fps or sync.
Is the framerate of AAC audio and you don't need change it, you need change the duration and pitch.

You need enlarge the duration in the ratio 25/(24000/1001) to continue synced with video fps changed from 25 to (24000/1001).

I don't use RipBot but inside there are all the soft than you need (eac3to, ffmpeg, fhgaacenc, mkvtoolnix, avisynth, avs2pipemod,...)

Using AviSynth the sneaker_ger script can do the job, also this one valid for any samplerate:

ffaudiosource("source.mkv")
SSRC(last, (AudioRate()*1001+480)/960).AssumeSampleRate(AudioRate(last))

Using high quality audio sample rate converter by Naoki Shibata SSRC.

manolito
5th February 2018, 16:44
Using high quality audio sample rate converter by Naoki Shibata SSRC.

Just keep in mind that SSRC cannot always be used. When it can't you need to use ResampleAudio instead...

SSRC doesn't work for arbitrary ratios of the samplerate of the source and target clip. The following ratios are allowed (see SSRC.c):

sfrq = samplerate of source clip
dfrq = samplerate of destination clip
frqgcd = gcd(sfrq,dfrq)
fs1 = dfrq * sfrq / frqgcd
Resamping is possible if: (fs1/dfrq == 1) or (fs1/dfrq % 2 == 0) or (fs1/dfrq % 3 == 0)

example for which resampling is possible:
sfrq = 44.1 kHz
dfrq = 48 kHz
frqgcd = gcd(44100,4800) = 300
fs1 / dfrq = sfrq / frqgcd = sfrq / gcd(sfrq,dfrq) = 44100/300 = 147
and 147%3=0 since 47 / 3 = 49 = integer


Cheers
manolito

clsid
5th February 2018, 17:16
MPC-HC options > Playback > Speed step > 4%
If you then click on the "decrease speed" button it will play at 96% speed, which is 24 fps. Not perfect, but close.

For automatic pitch adjustment use:
MPC-HC options > Playback > Output > Internal audio renderer

VideoBeginner
6th February 2018, 18:00
Thanks for the attempts to help, guys. Just to be clear, I am very green when it comes to Avisynth (scripting/coding in general) and will need a little hand holding. It may not even be what I need, but ffmpeg did not seem to have everything. Is it only for changing effects within an editor/player or is running command lines through cmd enough?


First, yes, I absolutely want to save the file rather than use an effect to change the speed. I may pass these files on at some point or go back to them having forgotten what I did before and be back where I started.


Second, when I try running sneaker_ger's script through MPC-HC or Command Prompt, I get this error "Script error: There is no function named 'ffaudiosource'."



(In the meantime, thanks clsid for letting me know the exact setting for MPC-HC speed.)

StainlessS
6th February 2018, 19:37
There is no function named 'ffaudiosource'.

For most things, eg google "Avisynth ffaudiosource" would work and bring you to a suitable page, for in this case FFMPegSource
http://avisynth.nl/index.php/FFmpegSource

FFMpegSource is one of the filters where authors have judged it not fit to post a thread in Avisynth Usage forum (dont know why,
but only seems to exist in Developer forum).

EDIT: A new plugin was recently posted in Devs forum, and no mention in Usage forum, maybe it will die a death as users
remain ignorant of its existence (also, 'News Feeds' that track the New Plugins thread in Usage will not be informed of its existence,
as it was not posted there either).

VideoBeginner
18th February 2018, 09:34
For most things, eg google "Avisynth ffaudiosource" would work and bring you to a suitable page, for in this case FFMPegSource
http://avisynth.nl/index.php/FFmpegSource
... Soooo, I do what now? (I told you... hand holding)

I download ffms2 and move the files into the main Avisynth folder (including files from "x86" directly into that folder) and then the script that sneaker_ger gave should function properly?

(I know that this should not be so difficult, but I'm confused enough that I am unwilling to muddle my way through, hoping for the best.)

burfadel
18th February 2018, 09:47
The correct fps would be 24 fps, 23.976 is fractionally slown down :).