Better Handle 96 kHz and 192 kHz Sample Rates

Archive of historical feature requests.
Please use the GitHub link above to report issues.
Forum rules
*******************************
Please be aware we are now using GitHub for issue tracking and feature requests.
- This section of the forum is now closed to new topics.

*******************************
Post Reply
baldrick77
Posts: 7
Joined: Mon Mar 20, 2017 3:39 pm

Better Handle 96 kHz and 192 kHz Sample Rates

Post by baldrick77 »

Please describe what you would like to see added to HandBrake:
Better support for source audio with 96 kHz and 192 kHz sample rates

Why would you like to see this added:
Source audio with 96 kHz and 192 kHz sample rates are common in LPCM sources on both DVD and Blu Ray. Handbrake does not support LPCM passthrough, and lossless quality is important to me. The 24-bit FLAC encoder is capable of handling input at this resolution (other encoders may not) but Handbrake will not encode audio with a sample rate in excess of 48 kHz, per hb_audio_rates[] array in Handbrake/libhb/common.c

The (simplified) current behavior of Handbrake is to silently downsample these tracks to the closest sample rate that does not exceed the input sample rate, per hb_audio_samplerate_find_closest() in Handbrake/libhb/common.c

Sample logs, using a DVD source with a 24-bit, two channel, 96 kHZ LPCM audio track (24*2*96000 = 4608000):

Code: Select all

Correct identification of input track at scan time:
[11:22:25] scan: audio 0xa0bd: LPCM, rate=96000Hz, bitrate=4608000 English (LPCM) (2.0 ch)

And at decode time:
[11:22:27]  * audio track 1
[11:22:27]    + decoder: English (LPCM) (2.0 ch) (track 1, id 0xa0bd)
[11:22:27]      + bitrate: 4608 kbps, samplerate: 96000 Hz
[11:22:27]    + mixdown: Stereo

But encode step is using a lower sample rate:
[11:22:27]    + encoder: FLAC 24-bit (libavcodec)
[11:22:27]      + samplerate: 48000 Hz
[11:22:27]      + compression level: 5.00
Please consider adding these two elements to hb_audio_rates[] and adjusting hb_audio_samplerate_xxx() functions in Handbrake/libhb/common.c so that audio with these sample rates can be used by those encoders that can support them, without breaking those encoders that cannot.

Code: Select all

    { { "96",   96000, }, NULL, 1, },
    { { "192",     192000, }, NULL, 1, },
What version of HandBrake are you currently running:
1.0.3 and nightlies as needed

What operating system and version and you currently running (e.g. OSX 10.11, Windows 7, Ubuntu 14):
Both OSX 10.12 and Windows 10
Deleted User 13735

Re: Better Handle 96 kHz and 192 kHz Sample Rates

Post by Deleted User 13735 »

The explanation I got many moons back is that HB, as one of its core principals, aims to compress everything. Multichannel pcm is VERY large; other than that, the logistical problem of passing pcm audio to h264 and h265 is that many media players won't recognize it. Been there, done that.
baldrick77
Posts: 7
Joined: Mon Mar 20, 2017 3:39 pm

Re: Better Handle 96 kHz and 192 kHz Sample Rates

Post by baldrick77 »

musicvid wrote: Tue Mar 21, 2017 12:53 am The explanation I got many moons back is that HB, as a core principal, aims to compress everything. Multichannel pcm is VERY large; other than that, the logistical problem of passing pcm audio to h264 and h265 is that many media players won't recognize it. Been there, done that.
I have no feelings either way on if Handbrake should be modified to write uncompressed LPCM audio to the output container. I personally would not ever use that feature but can understand why others might.

I agree that an uncompressed 2-channel 24-bit LPCM source at 96 kHz uses approximately 4.6MB/s, multi-channel LPCM sources or 192 kHz sample rates use even more, and that losslessly compressing them with FLAC or similar codecs results in storage savings with no loss of information.

The reason for the request is that LPCM audio is routinely found in source material at sample rates higher than 48 kHz, especially music sources. The FLAC encoder (and probably others--I haven't researched in detail) is fully capable of encoding these higher sample rates, but the hard-coded limitation in the specified array prevents it. The current behavior of Handbrake forces these audio streams to be downsampled to half or quarter the sample rate of the source.
Deleted User 13735

Re: Better Handle 96 kHz and 192 kHz Sample Rates

Post by Deleted User 13735 »

No, it uses approximately 4.6 Mbps; that is Megabits, not Megabytes. If we were encoding 1080p h264, that might account for about 1/3 of the total file size, something arguably worth looking at.

Compressed formats including AAC can work at lower sample rates for a few good reasons, perhaps the biggest being that the Nyquist frequency is lower. That said, your rationale for exposing higher sample rates for FLAC is sound and I support it.

When you're older, you won't miss the audio (AND harmonic distortion, AND quantization noise) that occurs between 15 and 22kHz nearly as much. Just saying...
baldrick77
Posts: 7
Joined: Mon Mar 20, 2017 3:39 pm

Re: Better Handle 96 kHz and 192 kHz Sample Rates

Post by baldrick77 »

I knew as soon as I hit submit that I should have put that in Mb...

I primarily use Handbrake as an archival tool, with goals of creating fairly decent quality video at original source resolution, and no modification to the original audio. My usual video workflow is 1080p H264 @ RF 22 for BD sources and 480p H264 @ RF 20 for DVD sources, both to MKV containers. These typically give me well under 5 Mbps and 1.5 Mbps for the video stream, respectively, unless the source is super noisy. The NLMeans denoise filter has been a blessing. For AC3 and DTS audio (~95% of my source material), I just pass it through. LPCM I re-encode to FLAC at the appropriate bit depth.

I would agree that storing an audio stream at 4.6 Mbps, or even whatever it comes out as after FLAC, alongside video at these bitrates is perhaps overkill and that the extra information captured at these sample rates is unlikely to be missed at the point of hearing. That said, the sources I have with the higher sample rates are almost all music, and I just don't like destroying source material when putting it to an archive. I certainly don't claim to be able to hear the difference. :)
Deleted User 13735

Re: Better Handle 96 kHz and 192 kHz Sample Rates

Post by Deleted User 13735 »

Spoken like a true audiophile. But Handbrake's encoders, both audio and video, in normal use, are anything but archival. Yes they store well and play well, but your only real archives are the rips from physical media, and you can play those as often as you like.

Quality and small files are an oxymoron if you are building an archive; and big drives are dirt cheap right now.

I record 36 channels of 24/96 at each of my live shows, but the satisfaction comes from knowing that no one but me will know the audio is compressed in the mix.
User avatar
BradleyS
Moderator
Posts: 1860
Joined: Thu Aug 09, 2007 12:16 pm

Re: Better Handle 96 kHz and 192 kHz Sample Rates

Post by BradleyS »

I hope at some point we can add LPCM passthrough and support for higher sample rates. The latter will require more than simply adding 96 & 192 because of compatibility concerns, but I have some ideas how to handle that down the line.

These aren't very high priority issues at the moment, but you may want to follow on GitHub:
https://github.com/HandBrake/HandBrake/issues/483
https://github.com/HandBrake/HandBrake/issues/659
FrostByte
Novice
Posts: 61
Joined: Sat Dec 12, 2015 7:16 pm

Re: Better Handle 96 kHz and 192 kHz Sample Rates

Post by FrostByte »

BradleyS wrote: Sun Mar 26, 2017 7:15 pm I hope at some point we can add LPCM passthrough

These aren't very high priority issues at the moment, but you may want to follow on GitHub:
https://github.com/HandBrake/HandBrake/issues/483
Thank you for considering, will help me so I also don't have to keep remuxing LPCM back in afterward
FB
baldrick77
Posts: 7
Joined: Mon Mar 20, 2017 3:39 pm

Re: Better Handle 96 kHz and 192 kHz Sample Rates

Post by baldrick77 »

BradleyS wrote: Sun Mar 26, 2017 7:15 pm I hope at some point we can add LPCM passthrough and support for higher sample rates. The latter will require more than simply adding 96 & 192 because of compatibility concerns, but I have some ideas how to handle that down the line.
I appreciate the consideration of the higher sample rates and can understand the need to carefully make changes. If there was a UI element to control the sample rate, with intelligently chosen values (since some encoders can't support certain values in the first place) and defaults (to address the compatibility concerns you rightly bring up), that would be swell.
Post Reply