ffmpeg로 동영상 자르는 오토메이터 애플스크립트

동영상 일부 자르려고 프로그램 쓰는게 귀찮아서 애플스크립트로 짜봤습니다.


on run {input, parameters}
    #try # encoding
# CHANGE IT
set OUT_DIR to "/Users/XXX/Movies/"
set OUT_SUFFIX to "_cutting"

    set start_time to "00:00:00"
    set end_time to start_time
    repeat with thisItem in input
        repeat while start_time ≥ end_time
            # input time
            set start_time to display dialog "Input START time" default answer start_time with icon note buttons {"Continue"} default button "Continue"
            set start_time to (text returned of start_time)
            #set end_time to get value of variable "end_time" of front workflow
            set end_time to display dialog "Input END time" default answer start_time with icon note buttons {"Continue"} default button "Continue"
            set end_time to (text returned of end_time)
            if end_time ≤ start_time then
                display dialog "Try again!" with icon caution buttons {"OK"} giving up after 1
            end if
        end repeat
        
        # time diff
        set timestamp1 to words of start_time
        set timestamp2 to words of end_time
        
        set diff_hours to (item 1 of timestamp2) - (item 1 of timestamp1)
        set diff_minutes to (item 2 of timestamp2) - (item 2 of timestamp1)
        set diff_seconds to (item 3 of timestamp2) - (item 3 of timestamp1)
        set time_diff to (diff_hours * 3600) + (diff_minutes * 60) + diff_seconds
        
        # get path to file
        # set inputFile to quoted form of POSIX path of thisItem
        set inputFile to POSIX path of thisItem
        set fileExtension to name extension of (info for thisItem)
        set fileNameBase to text 1 thru -((count of fileExtension) + 2) of (name of (info for thisItem))
        set fileSuffix to OUT_SUFFIX & "."
        set outputFile to POSIX path of (OUT_DIR & fileNameBase & fileSuffix & fileExtension)
        set fileNum to 1
        set status to true as boolean
        repeat while status
            set status to false
            tell application "Finder" to if exists outputFile as POSIX file then set status to true
            if status is true then
                set fileSuffix to (OUT_SUFFIX & fileNum as string) & "."
                set outputFile to POSIX path of (OUT_DIR & fileNameBase & fileSuffix & fileExtension)
                set fileNum to fileNum + 1
            end if
        end repeat
        
        # run ffmpeg for a file
        tell application "Terminal"
            activate
            #display dialog
            do script "/usr/local/bin/ffmpeg -hide_banner -y -ss " & start_time & " -i '" & inputFile & "' -to " & time_diff & " -c copy -avoid_negative_ts 1 '" & outputFile & "'; sleep 1; exit 0"
        end tell
    end repeat
    
    # on error ex
    # error "failed"
    #end try
    
    return input
end run

by NuRi | 2019/07/19 20:45 | 꿈꾸는 Mac | 트랙백 | 덧글(0)

트랙백 주소 : http://nuridol.egloos.com/tb/4173368
☞ 내 이글루에 이 글과 관련된 글 쓰기 (트랙백 보내기) [도움말]

:         :

:

비공개 덧글