# Handbrake Hands



## Guest (Sep 19, 2020)

Any avid users of Handbrake here? This is the free video processing software that can be used for ripping DVD's, among other things.

Maybe we can share tips and questions here.

I've got my handbrake installation working (Mac and Windows10 versions) and I've installed the covert library that allows handbrake to rip copy protected DVDs (basically all commercial DVDs are copy protected).

I seem to have the hang of it, but I have a question about audio. Some DVD's (notably opera and classical music DVDs) have an uncompressed, 2 channel audio track in addition to the usual dolby digital or DTS compressed audio. Handbrake doesn't seem to have an option to pass this audio through as simple uncompresses PCM audio. Am I missing something?

It also seems peculiar that video data needs to be re-encoded and can't simply be copied, but I guess that's because the original is copy protected/encrypted and the point is to make a video stream that is not encrypted.


----------



## Guest (Sep 21, 2020)

Distilled, my question, does anyone know how to extract uncompressed audio from a DVD with a LPCM track, preferably in the form of a FLAC file?


----------



## SixFootScowl (Oct 17, 2011)

Baron Scarpia said:


> Distilled, my question, does anyone know how to extract uncompressed audio from a DVD with a LPCM track, preferably in the form of a FLAC file?


I know nothing about sound transfer for Handbrake. I wonder if you can use Audacity to rip the files. I know you can load a video to Audacity and then save it as an audio file.

I do use Handbrake to rip DVDs, but occasionally one won't rip on Handbrake, so I turn to Brasero and make a virtual disk (ending .iso) of it to play back. I prefer Handbrake because the file size is way smaller (like 1GB) where a virtual disk is typically 8GB. Of course I can sometimes get the virtual disk to rip down through Handbrake.


----------



## Guest (Sep 21, 2020)

SixFootScowl said:


> I know nothing about sound transfer for Handbrake. I wonder if you can use Audacity to rip the files. I know you can load a video to Audacity and then save it as an audio file.
> 
> I do use Handbrake to rip DVDs, but occasionally one won't rip on Handbrake, so I turn to Brasero and make a virtual disk (ending .iso) of it to play back. I prefer Handbrake because the file size is way smaller (like 1GB) where a virtual disk is typically 8GB. Of course I can sometimes get the virtual disk to rip down through Handbrake.


Thanks, I've used audacity but did not know it could deal with video files. Worth a try.


----------



## SixFootScowl (Oct 17, 2011)

Baron Scarpia said:


> Thanks, I've used audacity but did not know it could deal with video files. Worth a try.


But the question is will it load the file from disk. Or a Brasero ISO file. I have only loaded the .m4v files from Handbrake which would defeat your question.


----------



## Guest (Sep 22, 2020)

I have found a workflow that does what I want. 

1) I use handbrake to rip the DVD to one or more MKV files, which allows me to save the uncompressed, 2 channel LPCM audio track to FLAC (in the MKV container). Audacity won't read MKV files, but it popped up a dialog box recommending FFmpeg. 

2) I use FFmpeg and run a command like "FFmpeg -i file.mkv file.flac" producing an audio only flac file which I can play using Swinsian (the media player I use for audio on my Mac). To get separate flac files for different sections I simply save the individual chapters of the DVD program into separate MKV files.

Anyway, if anyone else is interested in lossless rip of a DVD 2 channel LPCM track, this is one way to do it.


----------



## Kiki (Aug 15, 2018)

Glad you've found a way.

An alternative tool to extract audio tracks *directly* from a DVD video disc is "Swiftrun Free DVD Audio Extractor". Easy to use, but Windows-only.

However, in my experience, Handbrake has been more resilient to non-standard things that some discs were mastered with. (Recently I came across a disc that would play perfectly but Swiftrun could not regconize it at all. Handbrake could, but it did not see the chapters.)

Therefore, similar to what you did, I used Handbrake to convert the disc into a MKV (video quality set to the lowest to speed up the rip). Then I used eac3to to extract the desired audio stream. Then I created a cuesheet to manually re-create the tracks. Rather troublesome.


----------



## Guest (Sep 22, 2020)

That's what I really want, a cue sheet! Now what would be faster, searching the internet for a flakey program to make cue sheets, or writing some sort of script that could generate one from a list of track lengths?


----------



## Kiki (Aug 15, 2018)

There may be some tool that will create a cuesheet from a list of chapters, but I haven't come across one. I also suspect a different ripper may extract the chapters into a file using a different syntax, so I've never thought about writing a re-usable script to do that, even though to be honest I've never really looked into that.

Since I don't often rip DVDs, I've always created the cuesheet in a text editor, and then copied & pasted the timings into it. 

Alternatively, I suppose one could load the chapter list into a text editor, and then use find & replace (which works better with regular expression) or a keystoke macro to turn the chapter list into a cuesheet, but it's still a very manual exercise.

But then copying/pasting the timings does not really take that much time. One could have finished the job while pondering about how to do it elegantly. But that's me. Your mileage will vary of course.


----------



## Guest (Sep 23, 2020)

I wasn't thinking of writing anything so ambitious as automatically converting chapters in a video file to a cue sheet. Just something where I could give it a list of entry times, and it would spit it into a cue sheet with front-matter and formatting added. Probably would be worth it if I had at least 10 to use it on. Probably I'm about at the threshold.


----------



## Kiki (Aug 15, 2018)

OK out of curiosity I did a script... I didn't test it much. I stopped when it was able to produce a correct cuesheet from timestamps that I had recently worked on. Use it at your own risk. Feel free to debug/modify/crucify it though.

Put the chapter timestamps to be written into a cuesheet in a file "chapterlist.txt", like this -

```
00:00:00
02:12:53
07:40:09
13:03:94
15:34:19
19:14:65
24:02:44
28:29:70
33:32:01
34:22:06
38:14:29
39:10:81
43:56:13
47:58:20
52:54:50
58:16:49
62:36:88
63:45:55
69:18:82
```
Create a Windows batch file "Convert chapter list into cuesheet.bat" with the following content -

```
@echo off
REM chapter markers timing format in chapterlist.txt = hm:ss:ms
REM no transformation of chapter markers format is required
setlocal EnableDelayedExpansion
echo FILE ".flac" WAVE> cuesheet.cue
set /a tracknumber=1
for /f "tokens=*" %%i in (chapterlist.txt) do (
    REM for the tracknumber string, add leading '0' if the number is single-digit
    REM don't touch tracknumber, since adding a leading '0' will make stupid Windows think it is octal and screw up the loop count
    if !tracknumber! lss 10 (set tracknumberstring=0!tracknumber!) else (set tracknumberstring=!tracknumber!)
    REM write the next track in cuesheet
    echo   TRACK !tracknumberstring! AUDIO>> cuesheet.cue
    echo     TITLE "">> cuesheet.cue
    echo     INDEX 01 %%i>> cuesheet.cue
    REM inc loop count
    set /a tracknumber+=1 
)
```
Run it at the Windows Command Prompt and it will read the "chapterlist.txt" and create a "cuesheet.cue" with the timestamps and incremental track numbers, like this -

```
FILE ".flac" WAVE
  TRACK 01 AUDIO
    TITLE ""
    INDEX 01 00:00:00
  TRACK 02 AUDIO
    TITLE ""
    INDEX 01 02:12:53
  TRACK 03 AUDIO
    TITLE ""
    INDEX 01 07:40:09
  TRACK 04 AUDIO
    TITLE ""
    INDEX 01 13:03:94
  TRACK 05 AUDIO
    TITLE ""
    INDEX 01 15:34:19
  TRACK 06 AUDIO
    TITLE ""
    INDEX 01 19:14:65
  TRACK 07 AUDIO
    TITLE ""
    INDEX 01 24:02:44
  TRACK 08 AUDIO
    TITLE ""
    INDEX 01 28:29:70
  TRACK 09 AUDIO
    TITLE ""
    INDEX 01 33:32:01
  TRACK 10 AUDIO
    TITLE ""
    INDEX 01 34:22:06
  TRACK 11 AUDIO
    TITLE ""
    INDEX 01 38:14:29
  TRACK 12 AUDIO
    TITLE ""
    INDEX 01 39:10:81
  TRACK 13 AUDIO
    TITLE ""
    INDEX 01 43:56:13
  TRACK 14 AUDIO
    TITLE ""
    INDEX 01 47:58:20
  TRACK 15 AUDIO
    TITLE ""
    INDEX 01 52:54:50
  TRACK 16 AUDIO
    TITLE ""
    INDEX 01 58:16:49
  TRACK 17 AUDIO
    TITLE ""
    INDEX 01 62:36:88
  TRACK 18 AUDIO
    TITLE ""
    INDEX 01 63:45:55
  TRACK 19 AUDIO
    TITLE ""
    INDEX 01 69:18:82
```
H O W E V E R . . .

The timestamp format used in a cuesheet is mmm:ss:ms. (Note: there is no hour stamp; while minute is usually 2- or 3-digit long.)

However, the timestamp format that I could ever extract from a video is hh:mm:ss.mss (Note: the mini second mss has a 3-digit fixed length.)

Therefore "chapterlist.txt" will look like this -

```
00:00:00.000
00:02:12.532
00:07:40.092
00:13:03.949
00:15:34.199
00:19:14.653
00:24:02.441
00:28:29.708
00:33:32.010
00:34:22.060
00:38:14.292
00:39:10.815
00:43:56.133
00:47:58.208
00:52:54.504
00:58:16.493
01:02:36.886
01:03:45.555
01:09:18.821
```
Blimey sugar plum fairy! we need to do some arithmetics in the batch file to transform the video timstamp format into the cuesheet timestamp format! Like this -

```
@echo off
REM chapter list timing format = hh:mm:ss:mss
REM transform it into hm:ss:ms
setlocal EnableDelayedExpansion
echo FILE ".flac" WAVE> cuesheet.cue
set /a tracknumber=1
for /f "tokens=1-3* delims=:." %%a in (chapterlist.txt) do (
    REM for the mm value, nasty workaround to avoid Windows getting confused whether the numbers 08 and 09 are decimal or octal during arithmetic calculation
    set mmplus100=1%%b
    set /a hmplus100=!mmplus100!+60*%%a
    set /a hm=!hmplus100!-100
    REM for the hm value, add leading '0' if the number is single-digit
    if !hm! lss 10 set hm=0!hm!
    REM for the ms value, nasty workaround to avoid Windows getting confused whether the numbers 08 and 09 are decimal or octal during arithmetic calculation
    set mssplus1000=1%%d
    set /a msplus1000=!mssplus1000!/10
    set /a ms=!msplus1000!-100
    REM for the ms value, add leading '0' if the number is single-digit
    if !ms! lss 10 set ms=0!ms!
    REM for the tracknumber string, add leading '0' if the number is single-digit
    REM don't touch tracknumber, since adding a leading '0' will make stupid Windows think it is octal and screw up the loop count
    if !tracknumber! lss 10 (set tracknumberstring=0!tracknumber!) else (set tracknumberstring=!tracknumber!)
    REM write the next track in cuesheet
    echo   TRACK !tracknumberstring! AUDIO>> cuesheet.cue
    echo     TITLE "">> cuesheet.cue
    echo     INDEX 01 !hm!:%%c:!ms!>> cuesheet.cue
    REM inc loop count
    set /a tracknumber+=1 
)
```
The output "cuesheet.cue" should now have the correct timestamp format -

```
FILE ".flac" WAVE
  TRACK 01 AUDIO
    TITLE ""
    INDEX 01 00:00:00
  TRACK 02 AUDIO
    TITLE ""
    INDEX 01 02:12:53
  TRACK 03 AUDIO
    TITLE ""
    INDEX 01 07:40:09
  TRACK 04 AUDIO
    TITLE ""
    INDEX 01 13:03:94
  TRACK 05 AUDIO
    TITLE ""
    INDEX 01 15:34:19
  TRACK 06 AUDIO
    TITLE ""
    INDEX 01 19:14:65
  TRACK 07 AUDIO
    TITLE ""
    INDEX 01 24:02:44
  TRACK 08 AUDIO
    TITLE ""
    INDEX 01 28:29:70
  TRACK 09 AUDIO
    TITLE ""
    INDEX 01 33:32:01
  TRACK 10 AUDIO
    TITLE ""
    INDEX 01 34:22:06
  TRACK 11 AUDIO
    TITLE ""
    INDEX 01 38:14:29
  TRACK 12 AUDIO
    TITLE ""
    INDEX 01 39:10:81
  TRACK 13 AUDIO
    TITLE ""
    INDEX 01 43:56:13
  TRACK 14 AUDIO
    TITLE ""
    INDEX 01 47:58:20
  TRACK 15 AUDIO
    TITLE ""
    INDEX 01 52:54:50
  TRACK 16 AUDIO
    TITLE ""
    INDEX 01 58:16:49
  TRACK 17 AUDIO
    TITLE ""
    INDEX 01 62:36:88
  TRACK 18 AUDIO
    TITLE ""
    INDEX 01 63:45:55
  TRACK 19 AUDIO
    TITLE ""
    INDEX 01 69:18:82
```


----------

