Page 1 of 1

24-bit music streaming on 16-bit devices

PostPosted: Tue Oct 31, 2017 8:18 pm
by esh
What is the best solution for losslessly streaming from a library with both 24 and 16 bit music to devices limited to 16-bit and 44.1kHz, such as older Android devices?
Is it possible to get ffmpeg to only dither and/or resample (using SoXr) when necessary, or just pass the raw FLAC file through otherwise?

Until now, I have kept both the original and a redbook (16/44.1) transcode around for all my hi-def music, but since I started doing needle drops, and with more and more 24-bit music becoming available for purchase, this is getting out of hand.
I was thinking about writing a script to analyze the media file and pass it through SoXr if bits > 16 or kHz > 44.1 or else just output the raw file to stdout, but that would be a lot of work if ffmpeg can do the same.

Re: 24-bit music streaming on 16-bit devices

PostPosted: Fri Nov 03, 2017 2:09 pm
by jeffgt14
sox %s -b 16 -r 44100 -t flac -

This is what I use. If the file is already 16/44.1 then it won't actually do anything but pass it through. I'm sure you can use ffmpeg in some way too but I prefer SoX for dithering. SoX is a damn good program and it actually dithers on it's own when deemed necessary (going from 24bit to 16bit) so it makes everything easy in that you don't have to worry about running different commands whether the files are 16bit or 24bit. There is no reason you should ever add the dither option into your SoX command unless you actually want to dither when going from, for example, 24/96 to 24/48 or 16/48 to 16/44.1 which would just be silly.

Per :
In most cases, SoX can determine whether the selected processing requires dither and will add it during output formatting if appropriate.
Specifically, by default, SoX automatically adds TPDF dither when the output bit-depth is less than 24 and any of the following are true:
• bit-depth reduction has been specified explicitly using a command-line option
• the output file format supports only bit-depths lower than that of the input file format
• an effect has increased effective bit-depth within the internal processing chain

Essentially as long as you don't call anything out, SoX will do the correct processing. You would have to use the "−D, −−no−dither" flag if you want to prevent SoX from dithering when going from 24 to 16 bits.

Re: 24-bit music streaming on 16-bit devices

PostPosted: Thu Nov 16, 2017 10:51 pm
by esh
Thanks a lot, it works great! I never thought about using SoX directly. I was hoping to avoid ffmpeg in order to keep things simple, so this is brilliant.

Time to free up some disk space by deleting redbook conversions. :)

Re: 24-bit music streaming on 16-bit devices

PostPosted: Fri Mar 09, 2018 7:58 pm
by tom65
I am using Subsonic with Sonos and like it very much. The only bummer is the 24/16 bit issue. The Sox solution does work and i tweaked it into a perl script which checks to see if the source should be transcoded.

The downside of this is that I can no longer seek (fast forward, rewind, etc) within the file since it is now being "transcoded" on the fly. This is true on 16bit/44.1khz files as well since the script is always sitting in the middle. Is there a way to get Subsonic to selectively run the script only on 24 bit and/or sample rates > 48khz?

Here's the script:

Code: Select all
use Audio::FLAC::Header;
use strict;

my $file = $ARGV[0];
my $flac = Audio::FLAC::Header->new($ARGV[0]);
my $info = $flac->info();

my $sample=$info->{"SAMPLERATE"};
my $bits = $info->{"BITSPERSAMPLE"};

if ($bits > 16 || $sample > 48000) {
} else {