Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

bob5731

macrumors regular
Original poster
Jun 27, 2008
120
1
How to telling Terminal to run and display the output in Terminal.
If I do the code like but Terminal will not open.

Code:
tell application "Terminal"
    do shell script HANDBRAKE & " -i 'x264 Unparse: vbv-maxrate=25000:level=4.0:vbv-bufsize=31250' -i " & DISC & "/VIDEO_TS -o " & DEST & DVD & ".mp4" & "&" --loose-anamorphic --keep-display-aspect -e x264 -q 17 -b 1800 -r 29.97"
end tell

tell application "Terminal"

activate

do shell script HANDBRAKE & " -i 'x264 Unparse: vbv-maxrate=25000:level=4.0:vbv-bufsize=31250' -i " & DISC & "/VIDEO_TS -o " & DEST & DVD & ".mp4" & "&"

end tell

Code:
-- Tell the script where to send the Movies while ripping
set DEST to "/Users/bob/Movies/video"

-- Just some necessary variables to make the disc eject
set VOL to "/Volumes/"
set DISC to VOL & DVD

(*
set EXPORT to "dvdbackup -i " & DISC & "-I >> " & DEST & DISC & ".txt"
*)

-- Tell the script where your HandBrakeCLI executable file is.
set HANDBRAKE to "/applications/HandBrakeCLI"

activate application "Terminal"
tell application "Terminal"
    do script HANDBRAKE & " -i 'x264 Unparse: vbv-maxrate=25000:level=4.0:vbv-bufsize=31250' -i " & DISC & "/VIDEO_TS -o " & DEST & DVD & ".mp4" & "&" --loose-anamorphic --keep-display-aspect -e x264 -q 17 -b 1800 -r 29.97"
end tell

-- Eject the DVD after the rip.
tell application "Finder"
    do shell script "drutil eject"
end tell

say DVD & "has been converted. Please give me another disc to rip."
(*
tell application "System Events" to keystroke "w" using {command down}
quit application "Terminal"
*)

Last login: Tue Jan 16 14:55:03 on ttys000

iMac:~ bob$ /applications/HandBrakeCLI -i 'x264 Unparse: vbv-maxrate=25000:level=4.0:vbv-bufsize=31250' -i /Volumes//VIDEO_TS -o /Users/bob/Movies/video.mp4&

[1] 5529

iMac:~ bob$ [14:55:49] hb_init: starting libhb thread

[14:55:49] thread 700000081000 started ("libhb")

HandBrake 1.0.7 (2017040900) - Darwin x86_64 - https://handbrake.fr

2 CPUs detected

Opening /Volumes//VIDEO_TS...

[14:55:49] CPU: Intel(R) Core(TM)2 Duo CPU T7700 @ 2.40GHz

[14:55:49] - logical processor count: 2

[14:55:49] hb_scan: path=/Volumes//VIDEO_TS, title_index=1

disc.c:274: failed opening UDF image /Volumes//VIDEO_TS

disc.c:352: error opening file BDMV/index.bdmv

disc.c:352: error opening file BDMV/BACKUP/index.bdmv

[14:55:49] bd: not a bd - trying as a stream/file instead

libdvdnav: Using dvdnav version 5.0.1

libdvdread: Can't stat /Volumes//VIDEO_TS

No such file or directory

libdvdread: Could not open /Volumes//VIDEO_TS

libdvdnav: vm: failed to open/read the DVD

[14:55:49] dvd: not a dvd - trying as a stream/file instead

[14:55:49] hb_stream_open: open /Volumes//VIDEO_TS failed

[14:55:49] scan: unrecognized file type

[14:55:49] libhb: scan thread found 0 valid title(s)

No title found.


HandBrake has exited.
 
Last edited:
I didn't run your code and didn't dig to much into your code, but the output shows two slashes at '/Volumes//VIDEO_TS' and that the script doesn't find the files. I guess you wanted '/Volumes/DVD/VIDEO_TS' as the path. I've seen other scripts around that utilise '/Volumes/*/VIDEO_TS' as the search path. Check out what is working better for you.
The quirked path is probably coming from 'set DISC to VOL & DVD'? DVD seems to me like an undefined variable and not a string. Define the variable DVD, like you did with VOL or try 'set DISC to VOL & "DVD"' or 'set DISC to VOL & "*"' (without the single quotes) and see what happens.
 
But I can get it work with
do shell script HANDBRAKE & " -i 'x264 Unparse: vbv-maxrate=25000:level=4.0:vbv-bufsize=31250' -i " & DISC & "/VIDEO_TS -o " & DEST & DVD & ".mp4" & "&" --loose-anamorphic --keep-display-aspect -e x264 -q 17 -b 1800 -r 29.97"
[doublepost=1516382832][/doublepost]I got something to work. But It only makes a video that is not the full movie.


Code:
-- Find the title of the DVD
set DVD to do shell script "mount | grep read-only | awk -F' ' '{print $3}' | awk -F'/' '{print $3}'"
 
-- Tell the script where to send the Movies while ripping
set DEST to "/Users/bob/Movies/video"
 
-- Just some necessary variables to make the disc eject
set VOL to "/Volumes/"
set DISC to VOL & DVD
 
(*
set EXPORT to "dvdbackup -i " & DISC & "-I >> " & DEST & DISC & ".txt"
*)
 
-- Tell the script where your HandBrakeCLI executable file is.
set HANDBRAKE to "/applications/HandBrakeCLI"
 
activate application "Terminal"
tell application "Terminal"
  do script HANDBRAKE & " -i 'x264 Unparse: vbv-maxrate=25000:level=4.0:vbv-bufsize=31250' -i " & DISC & "/VIDEO_TS -o " & DEST & DVD & ".mp4" & "&" --loose-anamorphic --keep-display-aspect -e x264 -q 17 -b 1800 -r 29.97"
  activate
end tell
 
-- Eject the DVD after the rip.
tell application "Finder"
  do shell script "drutil eject"
  say DVD & "has been converted. Please give me another disc to rip."
end tell
 
--tell application "System Events" to keystroke "w" using {command down}
--quit application "Terminal"
 
I'm not experienced in using the HandbrakeCLI, but it seems that the problem is within the do shell script line.

From the HandBrakeCLI Documentation:
Code:
-t, --title <number> Select a title to encode (0 to scan all titles only, default: 1)
As you're not setting -t or --title switch like -t 0, your script probably uses the default value for -t that is 1 and thus only scans for the first title.

I guess, the first of the two input -i switches should probably be a -x switch.
Code:
-x, --encopts <string> Specify advanced encoding options in the same style as mencoder (all encoders except theora): option1=value1:option2=value2

First try to set the -t switch to 0. Then try to exchange the first -i switch with a -x switch and see what happens.

In examples from the handbrake docs, they are setting the input first, then the output, then the options, but the docs are also telling us, the options should reside before the input switch. Maybe it doesn't matter at all where you define the options, but it also could be that there are options for input and output that needs to be at the right place.

IMO, sometimes it's much easier typing the shell script directly into Terminal with all variables written as values for testing purposes. Then, if you think it's working like expect, assemble the script with variable definitions inside the AppleScript's do shell script part. Quoting in AppleScript can be a bit tricky sometimes, too.
 
Now it does not work on all movies.

How do I make it wait for new movie?
 
Here is a little more detailed Guide for HandbrakeCLI at scribd.
In my last post I asked to set the -t flag. After reading the guide at scribd, I guess that you don't want the -t flag. Please try deleting -t 0 from your script as -t 0 seems to only scan and not to encode. (See bottom line, too)
There is the --min-duration flag, that defaults to 10 seconds. If there are shorter clips less than 10 seconds, set it to something like --min-duration 1.
Sometimes it could help to set the --no-dvdnav flag to use libdvdread, instead of libdvdnav.
If that doesn't help, you could activate verbose level 1 with the -v flag and post the Terminal output and the AppleScript you're using at the moment.
I can't see something like a wait function, but it seems to be possible making a queue. Just use your do shell script with -t 1, then -t 2 and so on. If you make a loop and put the value into an incrementing variable, it should encode all files.
 
Code:
  do script HANDBRAKE & " -i 'x264 Unparse: vbv-maxrate=25000:level=4.0:vbv-bufsize=31250' -i " & DISC & "/VIDEO_TS -o " & DEST & DVD & ".mp4" & "&" --loose-anamorphic --keep-display-aspect -e x264 -q 17 -b 1800 -r 29.97"

I do not know what to use. I have been using what I find on google
I if can get me code to if fix it. I would appreciate it

How do I make it wait for new dvd?
 
Last edited:
I'd try something like this first:
Code:
do shell script HANDBRAKE & " -i " & DISC & "/VIDEO_TS -o " & DEST & DVD &".mp4" & " --loose-anamorphic --keep-display-aspect -e x264 -q 17 -b 1800 -r 29.97 -x x264 Unparse:vbv-maxrate=25000:level=4.0:vbv-bufsize=31250"
As I never used HandbrakeCLI, I don't know if it'll work at all. The part DEST & DVD &".mp4" might probably missing a variable for individual naming of each output file, but maybe HandbrakeCLI has a built-in handling of it. It's also possible, that you need to make the do shell script looping through each title with the -t flag, but maybe that is automatically handled, too.
I'd recommend starting with a stripped down simple version of the script directly executed in Terminal. Try something like:
Code:
/Applications/HandbrakeCLI -i /Volumes/DVD/VIDEO_TS -o /Users/bob/Movies/video.mp4
If it does what you want, try to get more complex, like:
Code:
/Applications/HandbrakeCLI -i /Volumes/DVD/VIDEO_TS -o /Users/bob/Movies/video.mp4 -e x264 -q 17 -b 1800 -r 29.97
until you end up with your final command
Code:
/Applications/HandbrakeCLI -i /Volumes/DVD/VIDEO_TS -o /Users/bob/Movies/video.mp4 --loose-anamorphic --keep-display-aspect -e x264 -q 17 -b 1800 -r 29.97 -x x264 Unparse:vbv-maxrate=25000:level=4.0:vbv-bufsize=31250
If you reach the state, that an error occurs, add a -v flag, like
Code:
/Applications/HandbrakeCLI -i /Volumes/DVD/VIDEO_TS -o /Users/bob/Movies/video.mp4 -v
If you found your solution, incorporate the working command again into the do shell script line, similar to the first example in this post.
 
Last edited:
It will not read dvd

iMac:~ bob$ /Applications/HandbrakeCLI -i Volumes/DVD/VIDEO_TS -o /Users/bob/Movies/video.mp4 -v

[12:00:03] hb_init: starting libhb thread

[12:00:03] thread 700000081000 started ("libhb")

HandBrake 1.0.7 (2017040900) - Darwin x86_64 - https://handbrake.fr

2 CPUs detected

Opening Volumes/DVD/VIDEO_TS...

[12:00:03] CPU: Intel(R) Core(TM)2 Duo CPU T7700 @ 2.40GHz

[12:00:03] - logical processor count: 2

[12:00:03] hb_scan: path=Volumes/DVD/VIDEO_TS, title_index=1

disc.c:274: failed opening UDF image Volumes/DVD/VIDEO_TS

disc.c:352: error opening file BDMV/index.bdmv

disc.c:352: error opening file BDMV/BACKUP/index.bdmv

[12:00:03] bd: not a bd - trying as a stream/file instead

libdvdnav: Using dvdnav version 5.0.1

libdvdread: Can't stat Volumes/DVD/VIDEO_TS

No such file or directory

libdvdread: Could not open Volumes/DVD/VIDEO_TS

libdvdnav: vm: failed to open/read the DVD

[12:00:03] dvd: not a dvd - trying as a stream/file instead

[12:00:03] hb_stream_open: open Volumes/DVD/VIDEO_TS failed

[12:00:03] scan: unrecognized file type

[12:00:03] libhb: scan thread found 0 valid title(s)

No title found.
 
Corrected the paths in my previous post. Instead of typing the part /Volumes/DVD/VIDEO_TS, just drag and drop your VIDEO_TS folder from Finder to Terminal. That ensures the correct path.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.