0

I'm an artist looking for automating some processes. Unfortunately, I'm too far from coding to wrap my head around even this seemingly elementary problem. I'm crying for professional's help with this task:

I need to create a service via Automator that will re-encode video files with FFMPEG. It should basically do what I'm doing manually when executу in Terminal a line like this:

ffmpeg —i FILE_NAME.EXTENSION -vf "vflip,hflip" -an FILE_NAME_converted.MP4

When this script is wrapped into the service FILE_NAME must be substituted with the file the service is applied to. How can I use such variables in AppleScript of Shell-script? I would highly appreciate any advice or even step-by-step instruction. Thank you!

Stan
  • 11
  • 2

1 Answers1

1

I was able to figure it out. Here is the AppleScript code that works for me:

on run {input, parameters}
    tell application "Finder"
        set theWin to window 1
        set thePath to (POSIX path of (target of theWin as alias))
        set theFile to name of file input
    end tell

    tell application "Terminal"
        activate
        set currentTab to do script ("cd " & thePath)
        do script ("ffmpeg -i " & theFile & " -vf \"vflip,hflip\" -an " & theFile & "_converted.mp4") in currentTab
        set frontWindow to window 1
        repeat until busy of frontWindow is false
            delay 1
        end repeat
        quit
    end tell
end run
user3439894
  • 7,266
  • 3
  • 17
  • 28
Stan
  • 11
  • 2