« The Hunger Games(ハンガーゲーム) | トップページ | The Iron Lady(マーガレット・サッチャー 鉄の女の涙) »

[AppleScript]ffmpeg用のコマンドを整形する(ムービーから選択範囲を切り出す)

Website_image00290115_194738

QuickTime(もう終わった技術なのね…)プレーヤーで
選択範囲を切り出します。

ffmpeg用のコマンドを整形だけのスクリプト
コマンドはターミナルで実行します。

QuickTimeで切り出したい選択範囲を作ったら
スクリプトを実行します

Website_image00290115_200334


ここにコマンドがログとして出力されます
これをコピーして
ターミナルにペーストします

Website_image00290115_200403


終了すると


Website_image00290115_201250


選択部分のみ書出されます。

(*
QuickTimeプレーヤー上での選択範囲を
ffmpegで切り出すコマンドに整形します。
ffmpegが必須
QuickTime Player 7用なのでOS的には10.9までか?
*)



tell application "QuickTime Player 7"
tell document 1
properties
---選択部スタート部を取得
set numSelectStart to get selection start
---選択部の長さを取得
set numSelectDura to get selection duration
---開いているファイルのパスを取得
set aliasCurentMovie to original file as alias
---開いているファイルの縦横サイズを取得
set listNatDimension to natural dimensions as list
end tell
end tell


--------ここから切り取りはじめる時間+秒数の小数点以下を取得
set theTime to "0"
set theTimeDec to "00"
set theTimeDecNo to "00"
set theTimeInt to "00"

set theTime to numSelectStart as number
set theTime to theTime / 600 as number
set theTimeDec to (theTime mod 1) as text
set theTimeDecNo to doReplace(theTimeDec, "0.", "")
set theTimeInt to theTime - theTimeDec as integer
set theTimeInt to FormatSeconds(theTimeInt)
set theStartTime to "" & theTimeInt & "." & theTimeDecNo & ""
log theStartTime

--------ここから、切り取る時間+秒数の小数点以下を取得
set theTime to "0"
set theTimeDec to "00"
set theTimeDecNo to "00"
set theTimeInt to "00"

set theTime to numSelectDura as number
set theTime to theTime / 600 as number
set theTimeDec to (theTime mod 1) as text
set theTimeDecNo to doReplace(theTimeDec, "0.", "")
set theTimeIntNo to theTime - theTimeDec as integer
set theTimeInt to FormatSeconds(theTimeIntNo)
set theDuraTime to "" & theTimeInt & "." & theTimeDecNo & ""
log theDuraTime

--------
---ひらいているファイルのエイリアスをUNIXパスに変換
set theOriginalMovie to POSIX path of aliasCurentMovie as text
---横サイズを取得
set theImageWidth to item 1 of listNatDimension as text
---縦サイズを取得
set theImageHeight to item 2 of listNatDimension as text
---新しいファイル名を定義
set theExpFile to (theOriginalMovie & "_" & theImageWidth & "X" & theImageHeight & "_" & theTimeIntNo & "sec.mp4") as text
---コマンドまでのパスを定義
set theffmpegPath to "'/usr/local/bin/ffmpeg'"
---コマンドラインを生成
set theCommandCom to (theffmpegPath & " -i \"" & theOriginalMovie & "\" -ss " & theStartTime & " -t " & theDuraTime & " -strict -2 \"" & theExpFile & "\"") as text
---コマンドラインをログとして書出す
log "\n" & theCommandCom & "\n"
return theCommandCom

------------------#ゼロサプレス
to doZeroSupp(n)
if n < 10 then
return "0" & n
else
return n as text
end if
end doZeroSupp

-----#文字の置き換え
to doReplace(theText, orgStr, newStr)
set oldDelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to orgStr
set tmpList to every text item of theText
set AppleScript's text item delimiters to newStr
set tmpStr to tmpList as text
set AppleScript's text item delimiters to oldDelim
return tmpStr
end doReplace

-------時間表示整形
(*
www.jesseweb.comから転記
数値としての秒数を HH:mm:ss 形式に変換します。
*)
on FormatSeconds(totalSeconds)
set theHours to (totalSeconds div hours)
set theRemainderSeconds to (totalSeconds mod hours)
set theMinutes to (theRemainderSeconds div minutes)
set theRemainderSeconds to (theRemainderSeconds mod minutes)
if length of (theHours as text) = 1 then
set theHours to "0" & (theHours as text)
end if
if length of (theMinutes as text) = 1 then
set theMinutes to "0" & (theMinutes as text)
end if
if length of (theRemainderSeconds as text) = 1 then
set theRemainderSeconds to "0" & (theRemainderSeconds as text)
end if
set theTimeString to theHours & ":" & theMinutes & ":" & theRemainderSeconds as text
return theTimeString
end FormatSeconds

「Movie2Cut_qt7.scpt」をダウンロード


|

« The Hunger Games(ハンガーゲーム) | トップページ | The Iron Lady(マーガレット・サッチャー 鉄の女の涙) »

QuickTime」カテゴリの記事