HydrogenAudio

Hydrogenaudio Forum => General Audio => Topic started by: FLX90 on 2018-10-16 12:46:45

Title: Downsampling Vinyl-Rips to CD
Post by: FLX90 on 2018-10-16 12:46:45
Hello,

I have some 192 kHz / 24 bit Vinyl-Rips in FLAC and want them to downsample to 44.1 kHz / 16 bit for my iPhone.

I would like to do that with FFmpeg + SoX.

So is that line correct?

Code: [Select]
ffmpeg -i input.flac -af aresample=resampler=soxr -acodec alac -ar 44100 -sample_fmt s16p output.m4a

I read about dither with downsampling.
But that is done with SoX by default?

Best regards,
Felix
Title: Re: Downsampling Vinyl-Rips to CD
Post by: dragut on 2018-10-16 13:35:27
Code works.

I didn't find that SoX do dithering by default.
https://ffmpeg.org/ffmpeg-resampler.html

I am using this one (swr):
Code: [Select]
ffmpeg -i "input.wav" -af aresample=resampler=swr ^
-acodec alac -ac 2 -ar 44100 -sample_fmt s16p output.alac
Title: Re: Downsampling Vinyl-Rips to CD
Post by: FLX90 on 2018-10-16 14:20:28
From http://sox.sourceforge.net/sox.html:
Code: [Select]
Specifically, by default, SoX automatically adds TPDF dither when the output bit-depth is less than 24 and any of the following are true

What do you do with -ac 2?
And why you convert to alac? Isn't it m4a?

Title: Re: Downsampling Vinyl-Rips to CD
Post by: Rollin on 2018-10-16 15:50:17
Specifically, by default, SoX automatically adds TPDF dither when the output bit-depth is less than 24 and any of the following are true
This is true for SoX commandline tool. But you aren't using it.

If you use ffmpeg, it will NOT dither by default. You need to set dither manually.
-af "aresample=44100:resampler=soxr:precision=33:osf=s16:dither_method=shibata" (if using this command you also can ommit -ar 44100 -sample_fmt s16p)
More dither methods are available, see https://ffmpeg.org/ffmpeg-resampler.html
Title: Re: Downsampling Vinyl-Rips to CD
Post by: dragut on 2018-10-16 19:39:43
From http://sox.sourceforge.net/sox.html:
Code: [Select]
Specifically, by default, SoX automatically adds TPDF dither when the output bit-depth is less than 24 and any of the following are true

What do you do with -ac 2?
And why you convert to alac? Isn't it m4a?

You read Rollin :))

And, as he also mentioned, you can omit ac 2 and some other stuffs... ac 2 (stereo) is my simple bug: I like to write everything. In your case, without ac 2. FFMPEG will guess that it is stereo and will do well too. But it will write in the log some info about all of that...
Title: Re: Downsampling Vinyl-Rips to CD
Post by: FLX90 on 2018-10-17 07:19:34
Thank you for the answers.
My command looks like this now:

Code: [Select]
ffmpeg -i input.flac -af "aresample=44100:resampler=soxr:precision=33:osf=s16:dither_method=shibata" -acodec alac output.m4a

Still two questions:

1. dither_method: Why shibata? What are advantages and disadvantages of the others?
2. precision: What does it do? More precisions means bigger file size? And according to FFmpeg Resampler Documentation a value of 28 gives SoX’s ’Very High Quality’, so 28 is max or not? Why a value of 33?

Title: Re: Downsampling Vinyl-Rips to CD
Post by: Rollin on 2018-10-17 15:44:27
dither_method: Why shibata? What are advantages and disadvantages of the others?
shibata moves dither noise from most audible range to high frequencies. You can see difference between dither/noise shaping algorithms here - http://sox.sourceforge.net/SoX/NoiseShaping

precision: What does it do? More precisions means bigger file size? And according to FFmpeg Resampler Documentation a value of 28 gives SoX’s ’Very High Quality’, so 28 is max or not? Why a value of 33?
Quality of resampling algorithm. It not affects file size directly. 28 is not max. 33 is max. But, yes, 33 is overkill.

Also, notice, that sometimes resampling can result in audible clicks between tracks - https://hydrogenaud.io/index.php/topic,114960.msg947760.html#msg947760 I don't know if this can be avoided with ffmpeg, but this can be avoided with foobar2000.
Title: Re: Downsampling Vinyl-Rips to CD
Post by: FLX90 on 2018-10-17 19:18:03
Okay, thank you for the explanation.

So here I have my to batch-files. For CD to ALAC only, without resampling and for Vinyl 24 Bit to 16 Bit.

16 Bit:
Code: [Select]
FOR %%A IN (*.flac) DO ffmpeg -i "%%A" -map_metadata -1 -acodec alac "%%A.m4a" 2>> ffmpeg.log

24 Bit:
Code: [Select]
FOR %%A IN (*.flac) DO ffmpeg -i "%%A" -map_metadata -1 -af "aresample=44100:resampler=soxr:precision=33:osf=s16:dither_method=shibata" -acodec alac "%%A.m4a" 2>> ffmpeg.log

(-map_metadata -1 because I want to clean tags completly with TuneUp.)

16 Bit Input:
Code: [Select]
Audio: FLAC (framed) 44100Hz stereo 1411kbps [A: flac, 44100 Hz, stereo, s16]
16 Bit Output
Code: [Select]
Audio: ALAC 44100Hz stereo 1059kbps [A: SoundHandler (alac, 44100 Hz, stereo, s16, 1059 kb/s)]

24 Bit Input:
Code: [Select]
Audio: FLAC (framed) 96000Hz stereo 4608kbps [A: flac, 96000 Hz, stereo, s24]
24 Bit Output
Code: [Select]
Audio: ALAC 44100Hz stereo 811kbps [A: SoundHandler (alac, 44100 Hz, stereo, s16, 811 kb/s)]

Why are the 16 Bit Outputs always much higher bitrate than the 24 Bit Outputs?

From the log-file:
What does the 128 kb/s mean?
Code: [Select]
Stream #0:0: Audio: alac (alac / 0x63616C61), 44100 Hz, stereo, s16p, 128 kb/s

And what is that overhead?
Code: [Select]
overhead: 0.044341%


I will test the files for clicks.
Hopefully there are none.


Thank you for your help.
Title: Re: Downsampling Vinyl-Rips to CD
Post by: dragut on 2018-10-18 12:52:27
Code: [Select]
Why are the 16 Bit Outputs always much higher bitrate than the 24 Bit Outputs?
Hm... what do u talking about? :))
First of all, for all conversions of that type, I am using WAV only. That's much more correct imho. So
4096 is native fixed bitrate for sample rate of 96000Hz 2 channels.
1411 is Red Book standard for CDs (Sample rate 44100 HZ).
FLAC will always decrease bitrate and you should not pay any attention on that. But you DO!
This 1059kbps and this 811kbps  are nocense (imho).
Take out from FLAC your WAV file and do your testing with it and do not write about FLAC but about WAV only. Makes much more sense imho.
Rollin wrote
Code: [Select]
dont know if this can be avoided with ffmpeg
I am using foobar for fast unpacking too but this case I tested with ffmpeg: no clicks, no nothing. Checked full GD Tracks album from Lara Fabian. Usually, for serious down-sampling etc. Adobe Audition is my favorite.
Title: Re: Downsampling Vinyl-Rips to CD
Post by: hintlou on 2018-10-21 12:35:23
Specifically, by default, SoX automatically adds TPDF dither when the output bit-depth is less than 24 and any of the following are true
This is true for SoX commandline tool. But you aren't using it.

If you use ffmpeg, it will NOT dither by default. You need to set dither manually.
-af "aresample=44100:resampler=soxr:precision=33:osf=s16:dither_method=shibata" (if using this command you also can ommit -ar 44100 -sample_fmt s16p)
More dither methods are available, see https://ffmpeg.org/ffmpeg-resampler.html

Which dither_method be used usually for downsampling to 44.1K?
Title: Re: Downsampling Vinyl-Rips to CD
Post by: ziemek.z on 2018-10-21 13:53:46
I think it's much safer, simpler and easier solution to just use SoX CMD instead of FFmpeg CMD.
Title: Re: Downsampling Vinyl-Rips to CD
Post by: hintlou on 2018-10-21 16:33:27
I think it's much safer, simpler and easier solution to just use SoX CMD instead of FFmpeg CMD.
where can i download the lastest version sox.exe....i can't find...
Title: Re: Downsampling Vinyl-Rips to CD
Post by: ziemek.z on 2018-10-21 17:09:58
I think it's much safer, simpler and easier solution to just use SoX CMD instead of FFmpeg CMD.
where can i download the lastest version sox.exe....i can't find...
Here. (https://sourceforge.net/projects/sox/files/sox/14.4.2/) Choose your OS (Windows) and version (32 or 64 bit).
Title: Re: Downsampling Vinyl-Rips to CD
Post by: Wombat on 2018-10-21 17:17:35
A very recent compile can be found here https://audiodigitale.eu/repo/sox/
Title: Re: Downsampling Vinyl-Rips to CD
Post by: ziemek.z on 2018-10-21 17:58:28
A very recent compile can be found here https://audiodigitale.eu/repo/sox/
The most recent compile is on the official site.
Title: Re: Downsampling Vinyl-Rips to CD
Post by: Wombat on 2018-10-21 18:20:32
The most recent compile is on the official site.
14.4.2 from 2015 is at the page you linked. There where changes since regarding DSD support, Ultra for resampling and maybe others in the 2017 compile i link above.

Edit: This is more a compile of the recent Fork done by Mans Rullgard https://github.com/mansr/sox
The same Rullgard does some things at https://sourceforge.net/p/sox/code/ci/master/tree/ and here https://sourceforge.net/p/sox/mailman/message/34464900/
I did my own compile a while back and use it since without any problems.
Title: Re: Downsampling Vinyl-Rips to CD
Post by: mycroft on 2018-10-21 20:32:45
And what is that overhead?
Code: [Select]
overhead: 0.044341%

That is muxing overhead, how much muxing into some format increases size compared to saving into raw.

Also sox is obsolete and abandoned and not much developed these days.
Title: Re: Downsampling Vinyl-Rips to CD
Post by: Kraeved on 2021-04-15 09:23:05
A very recent compile can be found here https://audiodigitale.eu/repo/sox/
Thank you, sir. I like this package is almost static instead of plethora of dlls.