Trying to convert this windows bat file into a usable Mac script for a folder that has mp4 in them.
ffmpeg -i -c:v libx264 -preset fast -crf 26 -profile:v baseline -pix_fmt yuv420p -vf scale=3840:2160 -r 30 -c:a copy "…\Converted_To_30fps
Trying to convert this windows bat file into a usable Mac script for a folder that has mp4 in them.
ffmpeg -i -c:v libx264 -preset fast -crf 26 -profile:v baseline -pix_fmt yuv420p -vf scale=3840:2160 -r 30 -c:a copy "…\Converted_To_30fps
Can you give the example of the folder and its path that you want us to use?
/Users/earlmiller/Desktop/JukeBox-FIles has the mp4
/Users/earlmiller/Desktop/JukeBox-FIles/Converted where I want them when converted
Sudo /opt/homebrew/bin/ffmpeg -i /Users/earlmiller/Desktop/JukeBox-FIles/TEST.mp4 -c libx264 -preset fast -crf 26 -profile:v baseline -pix_fmt yuv420p -vf scale=3840:2160 -r 30 -c:a copy /Users/earlmiller/Desktop/JukeBox-FIles/Converted/TEST.mp4
That worked but now the question is how to tell it to do all mp4 files not just the one called TEST.mp4. And is that possible from script in Automator via folder script
Here is a full script that will check if folders exists first.
Also most installs of command line programs will be put in folder /usr/local/bin
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
on run
local inFolder, outFolder, fileNames, fileExts, myFiles, inFile, OutFile, tid
set inFile to "TEST.mp4"
set inFolder to ((path to desktop) as text) & "JukeBox-Files:"
--set inFolder to POSIX path of (path to desktop) & "JukeBox-Files/"
try
inFolder as alias
on error
return
end try
set outFolder to inFolder & "Converted:"
try
outFolder as alias
on error
try
tell application "System Events"
make new folder at folder inFolder with properties {name:"Converted"}
end tell
on error
display alert "Error creating folder \"Converted\" in JukeBox-Files." giving up after 10
return false
end try
end try
do shell script "/usr/local/bin/ffmpeg -i \"" & POSIX path of (inFolder & inFile) & "\" -c libx264 -preset fast -crf 26 -profile:v baseline -pix_fmt yuv420p -vf scale=3840:2160 -r 30 -c:a copy \"" & (POSIX path of (outFolder & inFile)) & "\"> /dev/null 2>&1 &"
end run
Here is a version to do all files in the folder.
It also checks the converted folder to see if they already exist.
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
on run
local inFolder, outFolder, fileExts, myFiles, inFile, flag
set inFolder to ((path to desktop) as text) & "JukeBox-Files:"
try
inFolder as alias
on error
return
end try
set outFolder to inFolder & "Converted:"
try
outFolder as alias
on error
try
tell application "System Events"
make new folder at folder inFolder with properties {name:"Converted"}
end tell
on error
display alert "Error creating folder \"Converted\" in JukeBox-Files." giving up after 10
return false
end try
end try
tell application "System Events" to set myFiles to name of files of folder inFolder whose name extension is "mp4"
repeat with inFile in myFiles
set inFile to contents of inFile
try
(outFolder & inFile) as alias
set flag to false
on error
set flag to true
end try
if flag then
do shell script "/usr/local/bin/ffmpeg -i \"" & POSIX path of (inFolder & inFile) & "\" -c libx264 -preset fast -crf 26 -profile:v baseline -pix_fmt yuv420p -vf scale=3840:2160 -r 30 -c:a copy \"" & (POSIX path of (outFolder & inFile)) & "\"> /dev/null 2>&1 &"
repeat while "ffmpeg" is in paragraphs of (do shell script "ps -u " & (short user name of (system info)) & " -c -o comm=")
delay 20
end repeat
end if
end repeat
end run
Here is another version that asks for user input as to which folder to use.
Enjoy…
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
on run
local inFolder, outFolder, fileExts, myFiles, inFile, flag, pid, user
set inFolder to ((path to desktop) as text) & "JukeBox-Files:"
repeat
try
inFolder as alias
on error
set inFolder to (path to desktop) as text
end try
set inFolder to choose folder with prompt "Choose a folder with \"MP4\" files you want to convert…" default location (inFolder as alias)
set inFolder to inFolder as text
tell application "System Events" to set myFiles to name of files of folder inFolder whose name extension is "mp4"
if (count myFiles) > 0 then exit repeat
set flag to display dialog "Folder \"" & inFolder & "\" doesn't contain any MP4 files!" & return & "Do you wish to retry choosing a folder?" buttons {"Cancel", "Retry"} default button "Retry" with title "Error Choosing Folder!" with icon 1
if class of flag is boolean then return
if button returned of flag ≠ "Retry" then return
end repeat
set outFolder to inFolder & "Converted:"
try
outFolder as alias
on error
try
tell application "System Events"
make new folder at folder inFolder with properties {name:"Converted"}
end tell
on error
display alert "Error creating folder \"Converted\" in JukeBox-Files." giving up after 10
return false
end try
end try
set user to short user name of (system info)
repeat with inFile in myFiles
set inFile to contents of inFile
try
(outFolder & inFile) as alias
set flag to false
on error
set flag to true
end try
if flag then
set pid to do shell script "/usr/local/bin/ffmpeg -i \"" & POSIX path of (inFolder & inFile) & "\" -c libx264 -preset fast -crf 26 -profile:v baseline -pix_fmt yuv420p -vf scale=3840:2160 -r 30 -c:a copy \"" & (POSIX path of (outFolder & inFile)) & "\"> /dev/null 2>&1 & echo $!"
repeat while pid is in paragraphs of (do shell script "ps -u " & user & " -c -o pid")
delay 20
end repeat
end if
end repeat
end run