Saturday 30 January 2016

OSX Script - convert/split video usng ffmpeg



(* display dialog "Enter start time" default answer ""
set _start to text returned of result
display dialog "Enter end time " default answer ""
set _end to text returned of result
*)

on run {input, parameters}
    tell application "Terminal"
        activate
       
        set filesString to ""
        display dialog "Enter start time" default answer ""
        set temp to text returned of result
        set temp to ((characters 1 thru 2 of temp) as string) & ":" & ((characters 3 thru 4 of temp) as string) & ":" & ((characters 5 thru 6 of temp) as string)
        set starttime to temp
        set temp to ""
       
        display dialog "Enter end time " default answer ""
        set temp to text returned of result
        set temp to ((characters 1 thru 2 of temp) as string) & ":" & ((characters 3 thru 4 of temp) as string) & ":" & ((characters 5 thru 6 of temp) as string)
        set endtime to temp
       
        set filesString to ""
        repeat with file_ in input
            set filesString to filesString & " " & quoted form of (POSIX path of file_)
        end repeat
       
       
        (*    set filesName to {}
        repeat with anItem in filesString
            if anItem is not package folder and kind of anItem is not "Folder" and kind of anItem is not "Volume" then
                set end of filesName to contents of anItem
            end if
        end repeat
        *)
        do script "for f in" & filesString & "; do ffmpeg -i \"$f\" -vcodec copy -acodec copy -ss " & starttime & " -to " & endtime & " \"${f%.*}_.mp4\"
        exit 0
        done"
    end tell
    return input
end run

No comments:

Post a Comment