Log in

View Full Version : High quality downsampling 96kHz to 48kHz


tormento
8th June 2022, 12:27
I have this strange anime BD whose jpn audio is 96kHz 24bit 7.1 THD.

What is the best way to dither it down to 48kHz wav?

I have googled a lot and I became even more confused.

Dithering or not? What kind of dithering?

ffmpeg native? sox?

Help. :)

tebasuna51
8th June 2022, 14:57
That conversion (96kHz 24bit -> 48kHz 24bit), only samplerate, don't need be dithered because are far of human ear limits (20 KHz [samplerate 40 KHz] 20 bits) and quantization errors can't be listenen.

jpsdr
8th June 2022, 15:34
Akira ?
This is the only one BD (of movie) i've encoutered with audio more than 48kHz, resulting in an around 15GB audio file size !
... Wait... it was the 5.1 audio on Akira which was with so insane stuff, not the 7.1.
Finaly maybe there is another insane audio anime... ;)

Edit
My mistake, Akira is 5.1 24bit 192kHz ! :D

tormento
8th June 2022, 21:21
Akira
Ghost in the shell – Solid state society
Audio #1
ID : 4352 (0x1100)
Menu ID : 1 (0x1)
Format : MLP FBA / AC-3
Format/Info : Meridian Lossless Packing
Format settings : Dolby Surround EX
Muxing mode : Stream extension
Codec ID : 131
Duration : 1 h 48 min
Bit rate mode : Variable / Constant
Bit rate : 640 kb/s
Maximum bit rate : 6 756 kb/s
Channel(s) : 8 channels / 6 channels
Channel layout : L R C LFE Ls Rs Lb Rb
Sampling rate : 96.0 kHz / 48.0 kHz
Frame rate : 31.250 FPS (1536 SPF)
Compression mode : Lossless
Stream size : 498 MiB
Language : Japanese
Service kind : Complete Main
bsid : 6
Dialog Normalization : -31
Dialog Normalization : -31 dB
compr : -0.28
compr : -0.28 dB
acmod : 7
lfeon : 1
dialnorm_Average : -31
dialnorm_Average : -31 dB
dialnorm_Minimum : -31
dialnorm_Minimum : -31 dB
dialnorm_Maximum : -31
dialnorm_Maximum : -31 dB
dialnorm_Count : 1339
compr_Average : -4.24
compr_Average : -4.24 dB
compr_Minimum : -8.89
compr_Minimum : -8.89 dB
compr_Maximum : -0.56
compr_Maximum : -0.56 dB
compr_Count : 433
format_identifier : AC-3
Source : 00005.m2ts

FranceBB
8th June 2022, 22:37
Question for Tebasuna: what would ResampleAudio() do in this scenario?

Assuming that I can't use SSRC 'cause 96000Hz ain't supported, suppose that I do the following:

video=LWLibavVideoSource("Ghost in the shell.m2ts")
audio=LWLibavAudioSource("Ghost in the shell.m2ts", stream_index=1)
AudioDub(video, audio)
ResampleAudio(48000)


how is it going to resample the 96000Hz source? What does ResampleAudio() do in this scenario to achieve the 96kHz -> 48kHz conversion?
The reason why I'm asking this is that I've been using this function for years and years, trusting the Avisynth implementation, to perform any kind of conversion (aside from 44 kHz <-> 48 kHz which I perform with SSRC() ) but in the wiki it doesn't say much http://avisynth.nl/index.php/ResampleAudio

Perhaps a better clarification of lines 1179 onward would help users https://github.com/AviSynth/AviSynthPlus/blob/master/avs_core/core/audio.cpp
Then of course from line 1326 onwards it goes to assembly and I lose any clue about what is actually doing (although I'm sure you, Ferenc, Jean Philippe and others can).

StainlessS
8th June 2022, 23:58
JFYI,
IanB said some years back that ResampleAudio() had been re-written to be very nearly as good as SSRC(),
any articles saying SSRC() is much better, is well outdated.

FranceBB
9th June 2022, 09:21
ResampleAudio() had been re-written to be very nearly as good as SSRC(),
any articles saying SSRC() is much better, is well outdated.

Ah, sweet, thanks, I didn't know that.
That's great!

StainlessS
9th June 2022, 09:54
Further to my prev post,

I just did a D9 search for "SSRC" by user IanB [posts not threads], and looked at the very first/earliest [date order] link from June 2005
(I dont really think this is the same link [EDIT: post] that I was referencing, but it is pertinent - I did not look at any other links)

https://forum.doom9.org/showthread.php?p=672122#post672122


As you are finding out the other part to this problem is audio sync.SSRC() give very high quality conversion between 2 audio sample rates but is limited to rates that have a limited rational relationship. ResampleAudio() does not have this restriction, but prior to Avisynth 2.5.6 the code had a slight creeping error in the calculations which caused distortion in the result. The 2.5.6 version now is quite close to SSRC() in quality. Timestretch() by the nature of the algorithm used causes noticable distortion in the result, generally use it for speech only, never for high quality music.

IanB
EDIT: I provided the link above for anybody that does not know that the little blue arrow following IanB name is also a link.

tebasuna51
9th June 2022, 18:05
Ghost in the shell – Solid state society
Format : MLP FBA / AC-3
Channel layout : L R C LFE Ls Rs Lb Rb
Sampling rate : 96.0 kHz

If you want recode that track to EAC3 with TotalCode Studio

ffmpeg -i "00005.m2ts" -map 0:1 -filter_complex "aresample=48000,pan=7.1|c0=c0|c1=c1|c2=c2|c3=c3|c4=c6|c5=c7|c6=c4|c7=c5" -rf64 auto -acodec pcm_s24le "7.1_Channels_R.wav"

Change the samplerate to the half is a easy process and don't need a sophisticated software, or dither, to convert after the output to a lossy encode.

tebasuna51
9th June 2022, 18:26
Of course you can use SSRC (https://www.videohelp.com/software/SSRC), instead aresample=48000, with

ssrc --rate 48000 "7.1_Channels_R96.wav" "7.1_Channels_R48.wav"

Or AviSynth:

LWLibavAudioSource("00005.m2ts", stream_index=1)
ConvertAudioToFloat()
SSRC(48000)
a=ConvertAudioTo24bit()
flrc = GetChannel(a, 1, 2, 3 ,4)
blr = GetChannel(a, 5, 6)
slr = GetChannel(a, 7, 8)
MergeChannels(flrc, slr, blr)

Balling
10th June 2022, 02:42
The best resampler is still the sox resampler that can be used with ffmpeg when compiled with sox with the use of ffmpeg -i my-48000.wav -af aresample=resampler=soxr -ar 44100 my-44100.wav

https://trac.ffmpeg.org/wiki/FFmpeg%20and%20the%20SoX%20Resampler

tebasuna51
10th June 2022, 09:24
I don't know what is the best.

There are a comparative here (http://src.infinitewave.ca/)

And here free software (https://ccrma.stanford.edu/~jos/resample/Free_Resampling_Software.html) to resample.

Sox can be used with ffmpeg (libsoxr included in BtbN-builds and in gyan.dev_full-builds) like Balling say or with the SoX package (http://sox.sourceforge.net/)

SSRC can be used also with eac3to, than also can use r8brain.

Not included in comparative but see also a more updated ReSampler (https://github.com/jniemann66/ReSampler)

FranceBB
10th June 2022, 12:37
Well I guess I'll stick with Avisynth anyway just for the ease of use.
After all, I'm already indexing the video and/or trimming it etc, so having everything in one place makes sense, especially now that StainlessS showed me that ResampleAudio() is just as good as SSRC() ever since Ian re-wrote it. :D

richardpl
11th June 2022, 09:55
The best resampler is still the sox resampler that can be used with ffmpeg when compiled with sox with the use of ffmpeg -i my-48000.wav -af aresample=resampler=soxr -ar 44100 my-44100.wav

https://trac.ffmpeg.org/wiki/FFmpeg%20and%20the%20SoX%20Resampler

Not correct at all, when using correct non-default parameters, aresample beats soxr.

Brazil2
11th June 2022, 10:31
when using correct non-default parameters, aresample beats soxr.
How so ? In which domain exactly ?
Reminder: http://src.infinitewave.ca

richardpl
11th June 2022, 11:48
That web page never provide input files to reproduce results.

Also as already said, aresample filter defaults are set for performance not for quality.

Brazil2
11th June 2022, 13:05
Sorry but you don't answer the question.
when using correct non-default parameters, aresample beats soxr.
In which cases your claim is true ? Using which parameters ?
Please give examples and evidences.

tebasuna51
12th June 2022, 12:39
I read the Resampler-Options (https://ffmpeg.org/ffmpeg-resampler.html#toc-Resampler-Options), in ffmpeg docs, and the parameters not related with downmix, remap, async, soxr are:
filter_size For swr only, set resampling filter size, default value is 32.
phase_shift For swr only, set resampling phase shift, default value is 10, and must be in the interval [0,30].
linear_interp Use linear interpolation when enabled (the default). Disable it if you want to preserve speed instead of quality when exact_rational fails.
exact_rational For swr only, when enabled, try to use exact phase_count based on input and output sample rate. However, if it is larger than 1 << phase_shift, the phase_count will be 1 << phase_shift as fallback. Default is enabled.
cutoff Set cutoff frequency (swr: 6dB point; soxr: 0dB point) ratio; must be a float value between 0 and 1. Default value is 0.97 with swr, and 0.91 with soxr (which, with a sample-rate of 44100, preserves the entire audio band to 20kHz).
filter_type For swr only, select resampling filter type. This only affects resampling operations. It accepts the following values:
'cubic' select cubic
'blackman_nuttall' select Blackman Nuttall windowed sinc
'kaiser' select Kaiser windowed sinc
kaiser_beta For swr only, set Kaiser window beta value. Must be a double float value in the interval [2,16], default value is 9.

What parameters we need change to improve the quality in the resample 96000 -> 48000?

Balling
12th June 2022, 19:20
Not correct at all, when using correct non-default parameters, aresample beats soxr.

Well, yes, you and mkver and others wrote some stuff for it, maybe you should have updated wiki on trac with all those options, like you do for all the video [filters] options. Still, there were some issues with it recently in mpv, pull request is here https://github.com/mpv-player/mpv/pull/9990 that reverts https://github.com/mpv-player/mpv/commit/04257417542212c72e74a26d3b96c4fead51578f because of

>but the patch is stuck in limbo

What patch, LOL?

SeeMoreDigital
13th June 2022, 16:50
Personally...

I still use a very old program called Wavewizard (https://forum.doom9.org/showthread.php?t=95265) ;)

StainlessS
13th June 2022, 22:24
A lot of the [EDIT: wavewizardv0.54b] links [all of them I think] in SeeMoreDigital linked 1st post are dead,
PoisonDeathRay post here near end of that thread is good,
https://forum.doom9.org/showthread.php?p=1552424#post1552424
the post following it by ReinerSchweinlin is also good.

PDR direct Link:- http://www.mediafire.com/file/6i161jp52fyj92m/wavewizardv0.54b.zip/file
RS direct Link:- http://www.hardware-test.de/doom9/wavewizardv0.54b.rar