Unnecessary Downsampling of 96 kHz and 192 kHz Sources

Archive of historical bug reports.
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

Unnecessary Downsampling of 96 kHz and 192 kHz Sources

Post by baldrick77 »

Please describe the problem in as much detail as possible:
Handbrake downsamples input audio with sample rates in excess of 48 kHz even when the selected encoder is able to handle a higher sample rate. If the selected encoder can support the sample rate of the input (and that sample rate is a predictable, well-known, common value) it should be passed through as-is, not downsampled.

Source audio with 96 kHz and 192 kHz sample rates are extremely common in LPCM sources on both DVD and Blu Ray. Handbrake does not pass-through LPCM, so the audio stream has to be converted. The 24-bit FLAC encoder is capable of handling input at this resolution but Handbrake does not pass through the value determined by the scan, instead falling back to the hard-coded maximum value 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

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. At minimum, Handbrake should allow them to be passed through to the FLAC 24-bit encoder.

Code: Select all

    { { "96",   96000, }, NULL, 1, },
    { { "192",     192000, }, NULL, 1, },
What are the steps to reproduce this problem:
Select source with LPCM audio and sample rate in excess of 48 kHz. Most 24-bit LPCM sources will have this.
Select 24-bit FLAC encoder and start the job.
Observe that scan and decode steps correctly describe sample rate of input audio
Observe that encode step states that audio will be sampled at 48 kHz

What version of HandBrake you are running:
1.0.3 and nightlies as needed

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

Where did you download HandBrake from? handbrake.fr or somewhere else?
handbrake.fr

If there was any error, exception or crash report displayed, please copy it and paste it here:
No error, just not expected behavior, as these sample rates are fully supported by FLAC.

Please include the scan or encode log:

Log snippet, 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
Last edited by baldrick77 on Mon Mar 20, 2017 6:11 pm, edited 1 time in total.
Woodstock
Veteran User
Posts: 4614
Joined: Tue Aug 27, 2013 6:39 am

Re: Unnecessary Downsampling of 96 kHz and 192 kHz Sources

Post by Woodstock »

baldrick77 wrote: Mon Mar 20, 2017 4:59 pmNo container can store LPCM, but MKV can store FLAC.
Not to take away from your report, but... MKV files definitely can handle LPCM audio; About a third of the BDs I rip with MakeMKV contain 24-bit LPCM audio.
baldrick77
Posts: 7
Joined: Mon Mar 20, 2017 3:39 pm

Re: Unnecessary Downsampling of 96 kHz and 192 kHz Sources

Post by baldrick77 »

Woodstock wrote: Mon Mar 20, 2017 5:51 pm
baldrick77 wrote: Mon Mar 20, 2017 4:59 pmNo container can store LPCM, but MKV can store FLAC.
Not to take away from your report, but... MKV files definitely can handle LPCM audio; About a third of the BDs I rip with MakeMKV contain 24-bit LPCM audio.
Fair enough. Thanks for the clarification. Handbrake does not now and has never passed through LPCM, which I assumed was for a good reason.
Deleted User 13735

Re: Unnecessary Downsampling of 96 kHz and 192 kHz Sources

Post by Deleted User 13735 »

Delete by user.
FrostByte
Novice
Posts: 61
Joined: Sat Dec 12, 2015 7:16 pm

Re: Unnecessary Downsampling of 96 kHz and 192 kHz Sources

Post by FrostByte »

Would be nice if HB could pass PCM. I have a lot of older Criterion movies and I usually have to go back to my original mkv from Makemkv and remux any PCM back in.
Deleted User 11865

Re: Unnecessary Downsampling of 96 kHz and 192 kHz Sources

Post by Deleted User 11865 »

We should add those samplerates eventually. Not sure about PCM passthru, but since it has no bitstream metadata (unlike Dolby and DTS codecs), FLAC works just fine to re-encode PCM.
baldrick77
Posts: 7
Joined: Mon Mar 20, 2017 3:39 pm

Re: Unnecessary Downsampling of 96 kHz and 192 kHz Sources

Post by baldrick77 »

Rodeo wrote: Tue Mar 21, 2017 2:29 am We should add those samplerates eventually. Not sure about PCM passthru, but since it has no bitstream metadata (unlike Dolby and DTS codecs), FLAC works just fine to re-encode PCM.
FLAC works wonderfully within Handbrake for re-encoding LPCM with no loss of information (I'm very stingy on space...), and as long as the source sample rate does not exceed 48 kHz, I get the results I expect. But when it exceeds this value, severely downsampled audio is generated and I have to fall back to other tools to extract the LPCM source audio, convert it to FLAC, and then mux it with the video stream from Handbrake.

I realize why the 48 kHz sample rate limit is there historically and why arbitrary values for that field make no sense. I'm happy to take a look at this in more detail if someone can point me to the right places in the codebase. I only found the obvious one noted in the report :)
FrostByte
Novice
Posts: 61
Joined: Sat Dec 12, 2015 7:16 pm

Re: Unnecessary Downsampling of 96 kHz and 192 kHz Sources

Post by FrostByte »

Rodeo wrote: Tue Mar 21, 2017 2:29 am We should add those samplerates eventually. Not sure about PCM passthru, but since it has no bitstream metadata (unlike Dolby and DTS codecs), FLAC works just fine to re-encode PCM.
My issue with FLAC is that it may be great for HTPC, but a lot of even the newest 2017 TVs don't support streaming FLAC within MKV which means Smart apps running on them (such as Plex and Emby) have to request the server transcode FLAC every time you play them. My Samsung is one of those, but it does PCM which is probably because that's what you see on DVD/BD discs. I can just keep remuxing it back in after encode though.

Thanks

Sorry for the derailment.
Post Reply