Last active
February 29, 2024 23:22
-
-
Save loshlee/32c9aca2fa45e241c652fc810772bca1 to your computer and use it in GitHub Desktop.
Mac AppleScript sources for passing options to and executing 'two-pass-transcode.rb' by Lisa Melton (https://github.com/lisamelton/more-video-transcoding).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## This AppleScript can be used to create a macOS application to pass options to and execute Lisa Melton's video transcoding Ruby script (two-pass-transcode.rb). | |
## It is configured with additional constructs for detelecine, aggressive cropping, and converting output to .mp4. | |
## (See https://github.com/lisamelton/more-video-transcoding) | |
use AppleScript version "2.5" | |
use scripting additions | |
property temppath : "/private/tmp/" | |
property tmpfile : "/tmp/execme.command" | |
on open the_items | |
my handbrake_transcode(the_items) | |
end open | |
on handbrake_transcode(the_items) | |
set theshellscript to "" | |
repeat with the_item in the_items | |
set the_item to the_item as alias | |
try | |
tell application "Finder" | |
set sost to (container of the_item) as string | |
end tell | |
set pos_filepath to POSIX path of sost | |
end try | |
set this_filepath to (the_item as text) | |
if last character of this_filepath is ":" then | |
tell me to set it_is_a_folder to true | |
else | |
set it_is_a_folder to false | |
end if | |
set thesourcename to (name of (info for the_item)) | |
set namepart to (name extension of (info for the_item)) | |
set the_source_file to POSIX path of this_filepath | |
set newname to replace_chars(thesourcename, namepart, "detelecine.mp4") | |
set the_output_file to replace_chars(newname, "detelecine.mp4", "mkv") | |
set endFile to replace_chars(the_output_file, "mkv", "mp4") | |
try | |
set theshellscript to the theshellscript & "cd" & space & pos_filepath & ";two-pass-transcode.rb --ac3-surround -x detelecine -x rate=23.976 -x cfr -x crop-mode=auto" & space & (quoted form of the_source_file) & ";ffmpeg -i" & space & (quoted form of (pos_filepath & the_output_file)) & space & "-c copy" & space & (quoted form of (pos_filepath & endFile)) & ";rm -rf" & space & (quoted form of (pos_filepath & the_output_file)) & ";/bin/echo'" & space & " | |
========================== | |
" & newname & space & "FINISHED! | |
========================== | |
';" | |
on error onerr | |
activate | |
display dialog onerr | |
end try | |
end repeat | |
set theshellscript to theshellscript & "sleep 2;mv" & space & (quoted form of tmpfile) & space & (quoted form of (POSIX path of (path to trash))) | |
do shell script "echo " & quoted form of theshellscript & " > " & tmpfile | |
repeat | |
do shell script "chmod +x " & tmpfile | |
do shell script "open -a Terminal.app" & space & tmpfile | |
exit repeat | |
end repeat | |
end handbrake_transcode | |
on replace_chars(this_text, _bad, _good) | |
set AppleScript's text item delimiters to the _bad | |
set the item_list to every text item of this_text | |
set AppleScript's text item delimiters to the _good as text | |
set this_text to the item_list as text | |
set AppleScript's text item delimiters to "" | |
return this_text | |
end replace_chars | |
on run | |
set the_items to ((choose file) as list) | |
handbrake_transcode(the_items) | |
end run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## This AppleScript can be used to create a macOS application to pass options to and execute Lisa Melton's video transcoding Ruby script (two-pass-transcode.rb). | |
## (https://github.com/lisamelton/more-video-transcoding) | |
use AppleScript version "2.5" | |
use scripting additions | |
property temppath : "/private/tmp/" | |
property tmpfile : "/tmp/execme.command" | |
on open the_items | |
my handbrake_transcode(the_items) | |
end open | |
on handbrake_transcode(the_items) | |
set theshellscript to "" | |
repeat with the_item in the_items | |
set the_item to the_item as alias | |
try | |
tell application "Finder" | |
set sost to (container of the_item) as string | |
end tell | |
set pos_filepath to POSIX path of sost | |
end try | |
set this_filepath to (the_item as text) | |
if last character of this_filepath is ":" then | |
tell me to set it_is_a_folder to true | |
else | |
set it_is_a_folder to false | |
end if | |
set thesourcename to (name of (info for the_item)) | |
set namepart to (name extension of (info for the_item)) | |
set the_source_file to POSIX path of this_filepath | |
set newname to replace_chars(thesourcename, namepart, "mkv") | |
try | |
set theshellscript to the theshellscript & "cd" & space & pos_filepath & ";two-pass-transcode.rb" & space & (quoted form of the_source_file) & ";/bin/echo'" & space & " | |
========================== | |
" & newname & space & "FINISHED! | |
========================== | |
';" | |
on error onerr | |
activate | |
display dialog onerr | |
end try | |
end repeat | |
set theshellscript to theshellscript & "sleep 2;mv" & space & (quoted form of tmpfile) & space & (quoted form of (POSIX path of (path to trash))) | |
do shell script "echo " & quoted form of theshellscript & " > " & tmpfile | |
repeat | |
do shell script "chmod +x " & tmpfile | |
do shell script "open -a Terminal.app" & space & tmpfile | |
exit repeat | |
end repeat | |
end handbrake_transcode | |
on replace_chars(this_text, _bad, _good) | |
set AppleScript's text item delimiters to the _bad | |
set the item_list to every text item of this_text | |
set AppleScript's text item delimiters to the _good as text | |
set this_text to the item_list as text | |
set AppleScript's text item delimiters to "" | |
return this_text | |
end replace_chars | |
on run | |
set the_items to ((choose file) as list) | |
handbrake_transcode(the_items) | |
end run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's the comment promised in the previous comment pertaining specifically to the file named "two-pass-detelecine-aggr-crop-mp4-out.applescript".
When saved as an AppleScript or AppleScript application, the file named "two-pass-detelecine-aggr-crop-mp4-out.applescript" provides a method to incorporate the suggestions offered by @lisamelton at more-video-transcoding to meet my specific transcoding needs when using
two-pass-transcode.rb
on my Mac. Most video sources for the content I transcode are generated by an add-on hardware capture device called the Hauppauge HDPVR 2. This device is not compatible with video sources for which copying is prohibited through HDCP.I find that the highest quality output from the device is normally received in telecine format, so my transcode process requires IVTC (or "detelecine"), as incorporated into this AppleScript.
Please refer to my previous comment for general information about using both AppleScripts.
This AppleScript includes an ffmpeg construct for removing and replacing the default
.mkv
output oftwo-pass-transcode.rb
with.mpv
output. This construct can be removed by deleting";ffmpeg -i" & space & (quoted form of (pos_filepath & the_output_file)) & space & "-c copy" & space & (quoted form of (pos_filepath & endFile)) & ";rm -rf" & space & (quoted form of (pos_filepath & the_output_file)) &
from the AppleScript.