Media AVAsset

[swift]AVAssetでのビデオファイルからのメタ情報の取得

assetWithURL:の非推奨で代替え案を模索中
swiftにURLを投げてswiftで値を取得してもらう方法
他だと
ffmpegを使う
QuickTimeを使う等があるけど決め手にかけるので迷走中


ダウンロード - getvideoinfo.zip




AppleScript サンプルコード

【スクリプトエディタで開く】 |

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004#
005# com.cocolog-nifty.quicktimer.icefloe
006----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
007use AppleScript version "2.8"
008use framework "Foundation"
009use framework "AVFoundation"
010use framework "AppKit"
011use framework "UniformTypeIdentifiers"
012use scripting additions
013
014property refMe : a reference to current application
015set appFileManager to refMe's NSFileManager's defaultManager()
016
017#############################
018###ダイアログ
019set strName to (name of current application) as text
020if strName is "osascript" then
021  tell application "Finder" to activate
022else
023  tell current application to activate
024end if
025set appFileManager to refMe's NSFileManager's defaultManager()
026set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
027set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
028set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias
029set listUTI to {"public.movie"} as list
030set strMes to ("ファイルを選んでください") as text
031set strPrompt to ("ファイルを選んでください") as text
032try
033  set aliasFilePath to (choose file strMes with prompt strPrompt default location (aliasDefaultLocation) of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias
034on error
035  log "エラーしました"
036  return "エラーしました"
037end try
038
039set strFilePath to (POSIX path of aliasFilePath) as text
040set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
041set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
042set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
043set strFilePath to ocidFilePathURL's |path|() as text
044
045#############################
046### swiftパス
047#############################
048set aliasPathToMe to (path to me) as alias
049set strPathToMe to (POSIX path of aliasPathToMe) as text
050set ocidPathToMeStr to refMe's NSString's stringWithString:(strPathToMe)
051set ocidPathToMe to ocidPathToMeStr's stringByStandardizingPath()
052set ocidPathToMeURL to refMe's NSURL's alloc()'s initFileURLWithPath:(ocidPathToMe) isDirectory:(false)
053set ocidContainerDirPathURL to ocidPathToMeURL's URLByDeletingLastPathComponent()
054set ocidBinDirPathURL to ocidContainerDirPathURL's URLByAppendingPathComponent:("bin") isDirectory:(true)
055#不可視ファイル無視
056set ocidOption to (refMe's NSDirectoryEnumerationSkipsHiddenFiles)
057#収集キー
058set ocidKeyArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
059ocidKeyArray's addObject:(refMe's NSURLPathKey)
060ocidKeyArray's addObject:(refMe's NSURLIsSymbolicLinkKey)
061ocidKeyArray's addObject:(refMe's NSURLIsDirectoryKey)
062ocidKeyArray's addObject:(refMe's NSURLContentTypeKey)
063#URLの収集
064set listResponse to (appFileManager's contentsOfDirectoryAtURL:(ocidBinDirPathURL) includingPropertiesForKeys:(ocidKeyArray) options:(ocidOption) |error| :(reference))
065set ocidSubPathURLArray to (item 1 of listResponse)
066set listFileName to {} as list
067repeat with itemURL in ocidSubPathURLArray
068  #ファイル名を
069  set strItemFileName to itemURL's lastPathComponent() as text
070  copy strItemFileName to beginning of listFileName
071end repeat
072#############################
073### ダイアログ
074#############################
075set strName to (name of current application) as text
076if strName is "osascript" then
077  tell application "Finder" to activate
078else
079  tell current application to activate
080end if
081###
082set strTitle to ("ムービーファイルを選んでください") as text
083set strPrompt to ("ムービーファイルを選んでください") as text
084try
085  set objResponse to (choose from list listFileName with title strTitle with prompt strPrompt default items (item 1 of listFileName) OK button name "OK" cancel button name "キャンセル" with empty selection allowed without multiple selections allowed)
086on error
087  log "エラーしました"
088  return "エラーしました"
089end try
090# log class of objResponse
091if (class of objResponse) is boolean then
092  return "キャンセルしましたA"
093else if (class of objResponse) is list then
094  if objResponse is {} then
095    return "キャンセルしましたB"
096  else
097    set strResponse to (item 1 of objResponse) as text
098  end if
099end if
100
101
102#############################
103### SWIFTファイルの情報取得
104#############################
105set ocidSwiftFilePathURL to ocidBinDirPathURL's URLByAppendingPathComponent:(strResponse) isDirectory:(false)
106set strSwiftFilePath to ocidSwiftFilePathURL's |path| as text
107
108################################
109##タスク実行
110################################
111log "開始:" & doGetDateNo("yyyyMMdd hhmmss")
112
113set ocidStartTime to refMe's NSDate's |date|()
114
115##################
116#ログディレクトリ
117set appFileManager to refMe's NSFileManager's defaultManager()
118set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSLibraryDirectory) inDomains:(refMe's NSUserDomainMask))
119set ocidLibraryDirPathURL to ocidURLsArray's firstObject()
120set ocidLogDirPathURL to ocidLibraryDirPathURL's URLByAppendingPathComponent:("Logs") isDirectory:(true)
121set ocidLogSaveDirPathURL to ocidLogDirPathURL's URLByAppendingPathComponent:("AppleScript") isDirectory:(true)
122#
123set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
124ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions)
125set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidLogSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error| :(reference)
126
127##################
128#ログファイル
129set ocidCurrentDate to refMe's NSDate's |date|()
130set appFormatter to refMe's NSDateFormatter's alloc()'s init()
131appFormatter's setDateFormat:("yyyyMMddHHmmss")
132set ocidNowDate to appFormatter's stringFromDate:(ocidCurrentDate)
133set strNowDate to ocidNowDate as text
134set strLogFileName to ("scriptlog." & strNowDate & ".log") as text
135set ocidLogFilePathURL to ocidLogSaveDirPathURL's URLByAppendingPathComponent:(strLogFileName) isDirectory:(false)
136set ocidLogFilePath to ocidLogFilePathURL's |path|
137set strLogFilePath to ocidLogFilePath as text
138
139##################
140#ログファイル生成
141set ocidNulString to refMe's NSString's alloc()'s init()
142set listDone to ocidNulString's writeToURL:(ocidLogFilePathURL) atomically:(true) encoding:(refMe's NSUTF8StringEncoding) |error| :(reference)
143
144
145##################
146#ログファイルのアクセス権 644
147ocidAttrDict's setValue:(420) forKey:(refMe's NSFilePosixPermissions)
148set listDone to appFileManager's setAttributes:(ocidAttrDict) ofItemAtPath:(ocidLogFilePath) |error| :(reference)
149
150##################
151#実行時のカレントディレクトリ
152set ocidCurrentDirPathURL to ocidLibraryDirPathURL's URLByAppendingPathComponent:("Containers/com.cocolog-nifty.quicktimer/Data/tmp/TemporaryItems") isDirectory:(true)
153set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidCurrentDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error| :(reference)
154
155################## 
156#コマンド実行
157set ocidTermTask to refMe's NSTask's alloc()'s init()
158ocidTermTask's setLaunchPath:("/usr/bin/swift")
159set ocidArgumentsArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
160ocidArgumentsArray's addObject:(strSwiftFilePath)
161ocidArgumentsArray's addObject:(strFilePath)
162ocidTermTask's setArguments:(ocidArgumentsArray)
163set ocidOutPut to refMe's NSPipe's pipe()
164set ocidError to refMe's NSPipe's pipe()
165ocidTermTask's setStandardOutput:(ocidOutPut)
166ocidTermTask's setStandardError:(ocidError)
167ocidTermTask's setCurrentDirectoryURL:(ocidCurrentDirPathURL)
168set listDoneReturn to ocidTermTask's launchAndReturnError:(reference)
169if (item 1 of listDoneReturn) is (false) then
170  log "エラーコード:" & (item 2 of listDoneReturn)'s code() as text
171  log "エラードメイン:" & (item 2 of listDoneReturn)'s domain() as text
172  log "Description:" & (item 2 of listDoneReturn)'s localizedDescription() as text
173  log "FailureReason:" & (item 2 of listDoneReturn)'s localizedFailureReason() as text
174end if
175##################
176#終了待ち
177ocidTermTask's waitUntilExit()
178
179log "終了:" & doGetDateNo("yyyyMMdd hhmmss")
180log "経過時間: " & doGetTimeInderval(ocidStartTime)
181
182##################
183#標準出力をログに
184set ocidOutPutData to ocidOutPut's fileHandleForReading()
185set listResponse to ocidOutPutData's readDataToEndOfFileAndReturnError:(reference)
186set ocidStdOut to (item 1 of listResponse)
187set ocidStdOut to refMe's NSString's alloc()'s initWithData:(ocidStdOut) encoding:(refMe's NSUTF8StringEncoding)
188set listDone to ocidStdOut's writeToURL:(ocidLogFilePathURL) atomically:(true) encoding:(refMe's NSUTF8StringEncoding) |error| :(reference)
189set ocidStdOut to (ocidStdOut's stringByReplacingOccurrencesOfString:("\n") withString:(""))
190
191##################
192#戻り値チェック
193set numReturnNo to ocidTermTask's terminationStatus() as integer
194if numReturnNo = 0 then
195  log ocidStdOut as text
196  return ocidStdOut as text
197else
198  ##################
199  #エラーをログに
200  set ocidErrorData to ocidError's fileHandleForReading()
201  set listResponse to ocidErrorData's readDataToEndOfFileAndReturnError:(reference)
202  set ocidErrorOutData to (item 1 of listResponse)
203  set ocidErrorOutString to refMe's NSString's alloc()'s initWithData:(ocidErrorOutData) encoding:(refMe's NSUTF8StringEncoding)
204  set listResponse to refMe's NSFileHandle's fileHandleForWritingToURL:(ocidLogFilePathURL) |error| :(reference)
205  set ocidReadHandle to (item 1 of listResponse)
206  set listDone to ocidReadHandle's seekToEndReturningOffset:(0) |error| :(reference)
207  log (item 1 of listDone) as boolean
208  set listDone to ocidReadHandle's writeData:(ocidErrorOutData) |error| :(reference)
209  log (item 1 of listDone) as boolean
210  set listDone to ocidReadHandle's closeAndReturnError:(reference)
211  log (item 1 of listDone) as boolean
212end if
213
214if numReturnNo = 1 then
215  return "1: スクリプトエラー"
216else if numReturnNo = 2 then
217  return "2: 引数エラー"
218else if numReturnNo = 126 then
219  return "126: アクセス権エラー"
220else if numReturnNo = 127 then
221  return "127: スクリプトファイルが見つかりません"
222else if numReturnNo = 130 then
223  return "130: 強制終了"
224else if numReturnNo = 133 then
225  return "133: 異常終了"
226end if
227
228
229
230##############################
231### 今の日付日間 テキスト
232##############################
233to doGetDateNo(argDateFormat)
234  ####日付情報の取得
235  set ocidDate to current application's NSDate's |date|()
236  ###日付のフォーマットを定義
237  set ocidNSDateFormatter to current application's NSDateFormatter's alloc()'s init()
238  set ocidLocale to current application's NSLocale's localeWithLocaleIdentifier:("ja_JP_POSIX")
239  ocidNSDateFormatter's setLocale:(ocidLocale)
240  set ocidTimeZone to current application's NSTimeZone's alloc()'s initWithName:("Asia/Tokyo")
241  ocidNSDateFormatter's setTimeZone:(ocidTimeZone)
242  ocidNSDateFormatter's setDateFormat:(argDateFormat)
243  set ocidDateAndTime to ocidNSDateFormatter's stringFromDate:(ocidDate)
244  set strDateAndTime to ocidDateAndTime as text
245  return strDateAndTime
246end doGetDateNo
247
248
249################################
250##経過時間計算
251################################
252to doGetTimeInderval(argStartTime)
253  #今の時間
254  set ocidEndTime to refMe's NSDate's |date|()
255  #渡されたスタート時間からの間隔を取得
256  set numIntervalSec to ocidEndTime's timeIntervalSinceDate:(argStartTime)
257  #戻り値が秒数値なので時間にする
258  set numH to (numIntervalSec / 3600) as integer
259  set numM to ((numIntervalSec - (numH * 3600)) / 60) as integer
260  set numS to (numIntervalSec - (numH * 3600) - (numM * 60)) as integer
261  #2桁テキストにして
262  set appFormatter to refMe's NSNumberFormatter's alloc()'s init()
263  appFormatter's setMinimumIntegerDigits:(2)
264  appFormatter's setPaddingCharacter:("0")
265  appFormatter's setPaddingPosition:(refMe's NSNumberFormatterPadBeforePrefix)
266  set strH to (appFormatter's stringFromNumber:(numH)) as text
267  set strM to (appFormatter's stringFromNumber:(numM)) as text
268  set strS to (appFormatter's stringFromNumber:(numS)) as text
269  #戻り値用整形
270  set strInterval to (strH & ":" & strM & ":" & strS) as text
271  return strInterval
272end doGetTimeInderval
273
AppleScriptで生成しました

|

[AVAsset]選択したオーディオファイルの時間と合計時間を求める


あくまでも参考にしてください

【スクリプトエディタで開く】 |

サンプルソース(参考)
行番号ソース
001#! /usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004#com.cocolog-nifty.quicktimer.icefloe
005----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
006use AppleScript version "2.8"
007use framework "Foundation"
008use framework "UniformTypeIdentifiers"
009use framework "AppKit"
010use framework "CoreMedia"
011use scripting additions
012
013property refMe : a reference to current application
014
015
016##############################
017## ダイアログ
018##############################
019set strName to (name of current application) as text
020if strName is "osascript" then
021  tell application "Finder" to activate
022else
023  tell current application to activate
024end if
025############ デフォルトロケーション
026set appFileManager to refMe's NSFileManager's defaultManager()
027set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
028set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
029set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias
030#
031set listUTI to {"public.audio"} as list
032set strMes to ("ファイルを選んでください") as text
033set strPrompt to ("ファイルを選んでください") as text
034try
035  ### ファイル選択
036  set listAliasFilePath to (choose file strMes with prompt strPrompt default location aliasDefaultLocation of type listUTI with invisibles, multiple selections allowed and showing package contents) as list
037on error
038  log "エラーしました"
039  return "エラーしました"
040end try
041if listAliasFilePath is {} then
042  return "選んでください"
043end if
044##############################
045## 時間表示用のフォーマット
046##############################
047set ocidDateFormatter to refMe's NSDateComponentsFormatter's alloc()'s init()
048set numHunit to (refMe's NSCalendarUnitHour) as integer
049set numMunit to (refMe's NSCalendarUnitMinute) as integer
050set numSunit to (refMe's NSCalendarUnitSecond) as integer
051ocidDateFormatter's setAllowedUnits:((numHunit) + (numMunit) + (numSunit))
052ocidDateFormatter's setUnitsStyle:(refMe's NSDateComponentsFormatterUnitsStyleFull)
053#カウンター初期化
054set strOutPutText to "" as text
055set numTotalTime to 0 as integer
056##選択中の曲の数だけ繰り返し
057repeat with itemAliasFilePath in listAliasFilePath
058  #パス
059  set strFilePath to (POSIX path of itemAliasFilePath) as text
060  set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath))
061  set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
062  set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
063  #AVAssetに読み込んで 長さを計算
064  set ocidReadAsset to (refMe's AVAsset's assetWithURL:(ocidFilePathURL))
065  set listDuration to ocidReadAsset's duration()
066  set numTimeValue to (item 1 of listDuration) as integer
067  set numTimeScall to (item 2 of listDuration) as integer
068  set numTimeSec to (numTimeValue / numTimeScall) as integer
069  #メタデータからタイトルとアーティスト名を取得
070  set strTitle to ("タイトル不明") as text
071  set strArtist to ("アーティスト名不明") as text
072  set ocidMetaDataArray to ocidReadAsset's commonMetadata()
073  repeat with itemMetaData in ocidMetaDataArray
074    set strKeyName to (itemMetaData's commonKey()) as text
075    if strKeyName is "title" then
076      set strTitle to itemMetaData's value() as text
077    else if strKeyName is "artist" then
078      set strArtist to itemMetaData's value() as text
079    end if
080  end repeat
081  #この曲の長さ
082  set ocidSongTime to (ocidDateFormatter's stringFromTimeInterval:(numTimeSec))
083  ###取得した情報をテキストに加算していく
084  set strOutPutText to strOutPutText & ("" & (ocidSongTime as text) & ":" & strTitle & " - " & strArtist & "\r") as text
085  ###時間(秒)の加算
086  set numTotalTime to numTotalTime + numTimeSec as number
087  
088end repeat
089##合計時間
090set ocidTimeStr to ocidDateFormatter's stringFromTimeInterval:(numTotalTime)
091##
092set strMes1 to "合計時間は" & ocidTimeStr & "秒です"
093
094###出力テキスト整形
095set strOutPutText to "" & strMes1 & "\n" & strOutPutText as text
096##############################
097## ダイアログ
098##############################
099#####ダイアログを前面に
100tell current application
101  set strName to name as text
102end tell
103####スクリプトメニューから実行したら
104if strName is "osascript" then
105  tell application "Finder" to activate
106else
107  tell current application to activate
108end if
109set strBundleID to "com.apple.Music"
110set aliasIconPath to doGetIconPath(strBundleID) as alias
111set strDefaultAnswer to "入力してください" as text
112try
113  set recordResponse to (display dialog "選択したミュージックファイルの合計時間" with title "結果です" default answer strOutPutText buttons {"クリップボードにコピー", "再実行", "終了"} default button "終了" cancel button "終了" with icon aliasIconPath giving up after 30 without hidden answer)
114on error
115  log "エラーしました"
116  return "エラーしました"
117end try
118if true is equal to (gave up of recordResponse) then
119  return "時間切れですやりなおしてください"
120end if
121##############################
122#####自分自身を再実行
123##############################
124if button returned of recordResponse is "再実行" then
125  tell application "Finder"
126    set aliasPathToMe to (path to me) as alias
127  end tell
128  run script aliasPathToMe with parameters "再実行"
129end if
130
131##############################
132#####値のコピー
133##############################
134if button returned of recordResponse is "クリップボードにコピー" then
135  try
136    set strText to text returned of recordResponse as text
137    ####ペーストボード宣言
138    set appPasteboard to refMe's NSPasteboard's generalPasteboard()
139    set ocidText to (refMe's NSString's stringWithString:(strText))
140    appPasteboard's clearContents()
141    appPasteboard's setString:(ocidText) forType:(refMe's NSPasteboardTypeString)
142  on error
143    tell application "Finder"
144      set the clipboard to strText as text
145    end tell
146  end try
147end if
148
149
150
151##############################
152## サブルーチン
153##############################
154
155to doGetIconPath(argBundleID)
156  ##初期化
157  set appFileManager to refMe's NSFileManager's defaultManager()
158  set appShardWorkspace to refMe's NSWorkspace's sharedWorkspace()
159  ##バンドルIDからアプリケーションのインストール先を求める
160  set ocidAppBundle to (refMe's NSBundle's bundleWithIdentifier:(argBundleID))
161  if ocidAppBundle ≠ (missing value) then
162    set ocidAppPathURL to ocidAppBundle's bundleURL()
163  else if ocidAppBundle = (missing value) then
164    set ocidAppPathURL to (appShardWorkspace's URLForApplicationWithBundleIdentifier:(argBundleID))
165  end if
166  ##予備(アプリケーションのURL)
167  if ocidAppPathURL = (missing value) then
168    tell application "Finder"
169      try
170        set aliasAppApth to (application file id argBundleID) as alias
171        set strAppPath to POSIX path of aliasAppApth as text
172        set strAppPathStr to refMe's NSString's stringWithString:(strAppPath)
173        set strAppPath to strAppPathStr's stringByStandardizingPath()
174        set ocidAppPathURL to refMe's NSURL's alloc()'s initFileURLWithPath:(strAppPath) isDirectory:true
175      on error
176        return "アプリケーションが見つかりませんでした"
177      end try
178    end tell
179  end if
180  
181  ###アイコン名をPLISTから取得
182  set ocidPlistPathURL to ocidAppPathURL's URLByAppendingPathComponent:("Contents/Info.plist") isDirectory:false
183  set ocidPlistDict to refMe's NSMutableDictionary's alloc()'s initWithContentsOfURL:(ocidPlistPathURL)
184  set strIconFileName to (ocidPlistDict's valueForKey:("CFBundleIconFile")) as text
185  ###ICONのURLにして
186  set strPath to ("Contents/Resources/" & strIconFileName) as text
187  set ocidIconFilePathURL to ocidAppPathURL's URLByAppendingPathComponent:(strPath) isDirectory:false
188  ###拡張子の有無チェック
189  set strExtensionName to (ocidIconFilePathURL's pathExtension()) as text
190  if strExtensionName is "" then
191    set ocidIconFilePathURL to ocidIconFilePathURL's URLByAppendingPathExtension:"icns"
192  end if
193  ###ICONファイルが実際にあるか?チェック
194  set boolExists to appFileManager's fileExistsAtPath:(ocidIconFilePathURL's |path|)
195  ###ICONがみつかない時用にデフォルトを用意する
196  if boolExists is false then
197    set aliasIconPath to POSIX file "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertNoteIcon.icns"
198  else
199    set aliasIconPath to ocidIconFilePathURL's absoluteURL() as alias
200  end if
201  return aliasIconPath as alias
202end doGetIconPath
AppleScriptで生成しました

|

サウンドファイルのリネーム(データレート、サンプルレート、時間分入り)


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AVFoundation"
use framework "CoreMedia"
use scripting additions

property refMe : a reference to current application
set appFileManager to refMe's NSFileManager's defaultManager()

###################################
#####入力フォルダ
###################################
###ダイアログのデフォルト
set ocidUserDesktopPath to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set aliasDefaultLocation to ocidUserDesktopPath as alias
tell application "Finder"
  ## set aliasDefaultLocation to container of (path to me) as alias
end tell
###ダイアログテキスト
set strPromptText to "入力フォルダを選んでください"
try
  set listResponse to (choose folder strPromptText with prompt strPromptText default location aliasDefaultLocation without multiple selections allowed, invisibles and showing package contents) as list
on error
log "エラーしました"
return
end try
###エリアス
set aliasDirPath to (item 1 of listResponse) as alias
###UNIXパス
set strDirPath to POSIX path of aliasDirPath as text
###String
set ocidDirPath to refMe's NSString's stringWithString:strDirPath
###NSURL
set ocidDirPathURL to refMe's NSURL's alloc()'s initFileURLWithPath:ocidDirPath isDirectory:true
###########################
###ディレクトリ内のファイルをURLリストに(下位まで)
###########################
set listSubPathArray to appFileManager's subpathsOfDirectoryAtPath:ocidDirPathURL |error|:(reference)
set ocidSubPathArray to item 1 of listSubPathArray

###########################
###本処理
###########################
##ファイルリストの数だけ繰り返し
repeat with itemSubPathArray in ocidSubPathArray
  ####選択したフォルダURLに取得したリストを追加してURLに
  set ocidFilePathURL to (ocidDirPathURL's URLByAppendingPathComponent:itemSubPathArray)
  ####ファイル名取得
  set ocidFileName to ocidFilePathURL's lastPathComponent
  set strFileName to ocidFileName as text
  ####拡張子を取ったベースファイル名
  set ocidBaseFileName to ocidFileName's stringByDeletingPathExtension
  set strBaseFileName to ocidBaseFileName as text
  ####拡張子取得
  set ocidFileExtension to ocidFilePathURL's pathExtension
  set strFileExtension to ocidFileExtension as text
  
  if strFileExtension is "mp3" then
    ####URLのファイル名を取ってコンテナディレクトリに
    set ocidContainerDirPathURL to ocidFilePathURL's URLByDeletingLastPathComponent
    #####サブを実行
    set listRate to doGetDataAndSampleRate(ocidFilePathURL)
    ###置き換えファイル名の定義
    set strAddFileName to ("." & (item 1 of listRate) & "x" & (item 2 of listRate) & "." & (item 3 of listRate) & "M.") as text
    ####新しいファイル名
    set strNewFileName to strBaseFileName & strAddFileName & strFileExtension as text
    ####コンテナディレクトリに新しいファイル名でリネーム用のURL
    set ocidNewFilePathURL to (ocidContainerDirPathURL's URLByAppendingPathComponent:strNewFileName)
    ####リネームする
    set listResult to (appFileManager's moveItemAtURL:ocidFilePathURL toURL:ocidNewFilePathURL |error|:(reference))
    
  else if strFileExtension is "m4a" then
    ####URLのファイル名を取ってコンテナディレクトリに
    set ocidContainerDirPathURL to ocidFilePathURL's URLByDeletingLastPathComponent
    #####サブを実行
    set listRate to doGetDataAndSampleRate(ocidFilePathURL)
    ###置き換えファイル名の定義
    set strAddFileName to ("." & (item 1 of listRate) & "x" & (item 2 of listRate) & "." & (item 3 of listRate) & "M.") as text
    ####新しいファイル名
    set strNewFileName to strBaseFileName & strAddFileName & strFileExtension as text
    ####コンテナディレクトリに新しいファイル名でリネーム用のURL
    set ocidNewFilePathURL to (ocidContainerDirPathURL's URLByAppendingPathComponent:strNewFileName)
    ####リネームする
    set listResult to (appFileManager's moveItemAtURL:ocidFilePathURL toURL:ocidNewFilePathURL |error|:(reference))
    
  end if
  
end repeat


###########################################
### データレート と サンプルレートを読み取るサブ
###########################################
to doGetDataAndSampleRate(argURL)
  ####URLをAVAsset読み込み
  set ocidReadAsset to (refMe's AVAsset's assetWithURL:argURL)
  ## log ocidReadAsset's preferredRate()
  ##ファイルの長さ
  set ocidReadAssetDuration to ocidReadAsset's duration()
  set numTimeValue to (item 1 of ocidReadAssetDuration) as integer
  set numTimeScall to (item 2 of ocidReadAssetDuration) as integer
  set numMin to ((numTimeValue / numTimeScall) / 60) as number
  set strMin to doRound2Dec({numMin, 2, "up"}) as text
  
  
  ###トラック読み込み
  set ocidReadAssetTrackArray to ocidReadAsset's tracks()
  ###オーディオトラック読み込み
  set ocidTrack to (ocidReadAssetTrackArray's objectAtIndex:0)
  ###サンプルレート取得
  set numSampleRate to ocidTrack's naturalTimeScale() as integer
  set strSampleRate to (round (numSampleRate / 100) rounding down) as text
  ###データレート取得
  set ocidDataRate to ocidTrack's estimatedDataRate() as integer
  set numDataRate to ocidDataRate as integer
  #
  
  
  ###データレート0対策
  if numDataRate = 0 then
    set strArgFilePath to (argURL's |path|()) as text
    set strCommandText to ("/usr/bin/afinfo -i \"" & strArgFilePath & "\"") as text
log strCommandText
    try
      with timeout of 10 seconds
        set strResponse to (do shell script strCommandText) as text
      end timeout
    on error
return {0, strSampleRate}
    end try
    set AppleScript's text item delimiters to "\r"
    set listResponse to every text item of strResponse
    set AppleScript's text item delimiters to ""
    repeat with itemLineText in listResponse
      if itemLineText starts with "bit rate" then
        set AppleScript's text item delimiters to " "
        set listLineText to every text item of itemLineText
        set AppleScript's text item delimiters to ""
        set strDataRate to (round ((item 3 of listLineText) / 1000)) as text
        exit repeat
      end if
    end repeat
  else
    set strDataRate to (round (numDataRate / 1000)) as text
  end if
  ####値を戻す
return {strDataRate, strSampleRate, strMin}
end doGetDataAndSampleRate
##########################################
# 小数点以下桁揃え  数値 桁数 四捨五入 up or down
##########################################
to doRound2Dec({argNumNumber, argNumDecNo, argStrRound})
  set numNumber to argNumNumber as number
  set numDecNo to argNumDecNo as integer
  set strRound to argStrRound as text
  # 10のx乗 
  set numDec to (10 ^ numDecNo) as integer
  # ↑の数桁数だけ元の数値の桁数を増やして
  set numStep1 to (numNumber * numDec) as number
  # 数値の丸め 繰り上がりup と繰り下がりdownの処理
  if strRound is "up" then
    set numStep2 to (round of numStep1 rounding up) as integer
  else if strRound is "down" then
    set numStep2 to (round of numStep1 rounding down) as integer
  end if
  # 最後の桁数を戻して
  set numStep3 to (numStep2 / numDec) as number
  # テキストで戻す場合
  # set strStep3 to (numStep2 / numDec) as text
  # 数値で戻す
return numStep3
end doRound2Dec

|

[AVAsset]ビデオのサイズ(縦横サイズ)の取得


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use framework "AVFoundation"
use framework "CoreMedia"
use scripting additions

property refMe : a reference to current application
set appFileManager to refMe's NSFileManager's defaultManager()



#############################
###入力ファイル
#############################
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
############ デフォルトロケーション
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias
####UTIリスト
set listUTI to {"public.movie"}
####ダイアログを出す
set aliasFilePath to (choose file with prompt "ムービーファイルを選んでください" default location (aliasDefaultLocation) of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias
###入力ファイル
set strFilePath to (POSIX path of aliasFilePath) as text
set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)


#############################
### ムービー読み込み
#############################
set ocidReadAsset to refMe's AVAsset's assetWithURL:(ocidFilePathURL)
set ocidReadAssetTrackArray to ocidReadAsset's tracks()
set ocidVideoTrack to ocidReadAssetTrackArray's firstObject()
#
set recordAssetTrackNaturalSize to ocidVideoTrack's naturalSize()
log recordAssetTrackNaturalSize
set numW to (width of recordAssetTrackNaturalSize) as integer
set numH to (height of recordAssetTrackNaturalSize) as integer

log "w:" & numW
log "h:" & numH
return

|

[AVAsset]ビデオの長さ 時間の取得


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use framework "AVFoundation"
use framework "CoreMedia"
use scripting additions

property refMe : a reference to current application
set appFileManager to refMe's NSFileManager's defaultManager()



#############################
###入力ファイル
#############################
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
############ デフォルトロケーション
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias
####UTIリスト
set listUTI to {"public.movie"}
####ダイアログを出す
set aliasFilePath to (choose file with prompt "ムービーファイルを選んでください" default location (aliasDefaultLocation) of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias
###入力ファイル
set strFilePath to (POSIX path of aliasFilePath) as text
set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)

#############################
### ムービー読み込み
#############################
set ocidReadAsset to refMe's AVAsset's assetWithURL:(ocidFilePathURL)
set ocidReadAssetTrackArray to ocidReadAsset's tracks()
set ocidVideoTrack to ocidReadAssetTrackArray's firstObject()
#
set ocidAssetTrackTimeRange to ocidVideoTrack's timeRange()
set listTimeRange to (item 2 of ocidAssetTrackTimeRange)
set strSec to ((item 1 of listTimeRange) / (item 2 of listTimeRange)) as integer
#
set numH to (round of (strSec / 3600) rounding down)
set numM to (round of ((strSec - (numH * 3600)) / 60) rounding down)
set numS to strSec - (numH * 3600) - (numM * 60)

###ゼロパディング
set strZeroSup to "00" as text
set strH to (text -2 through -1 of ("00" & numH)) as text
set strM to (text -2 through -1 of ("00" & numM)) as text
set strS to (text -2 through -1 of ("00" & numS)) as text

###戻り値
set strSStime to (strH & ":" & strM & ":" & strS) as text
log strSStime
set strMes to ("計算結果です: " & strSec & "秒は \r " & strSStime & "\r" & numH & "時間" & numM & "分" & numS & "秒\r" & strH & "時間" & strM & "分" & strS & "秒\r") as text

log strMes


return

|

[AVAsset]データレートbpsの取得


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use framework "AVFoundation"
use framework "CoreMedia"
use scripting additions

property refMe : a reference to current application
set appFileManager to refMe's NSFileManager's defaultManager()



#############################
###入力ファイル
#############################
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
############ デフォルトロケーション
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias
####UTIリスト
set listUTI to {"public.movie"}
####ダイアログを出す
set aliasFilePath to (choose file with prompt "ムービーファイルを選んでください" default location (aliasDefaultLocation) of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias
###入力ファイル
set strFilePath to (POSIX path of aliasFilePath) as text
set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)

#############################
### ムービー読み込み
#############################
set ocidReadAsset to refMe's AVAsset's assetWithURL:(ocidFilePathURL)
set ocidReadAssetTrackArray to ocidReadAsset's tracks()
set ocidVideoTrack to ocidReadAssetTrackArray's firstObject()
#
set numDataRate to ocidVideoTrack's estimatedDataRate() as number
set numDataRate to (numDataRate / 1000) as integer
set strDataRate to numDataRate as text
log strDataRate
return

|

[AVAsset] フレームレートfpsの取得


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use framework "AVFoundation"
use framework "CoreMedia"
use scripting additions

property refMe : a reference to current application
set appFileManager to refMe's NSFileManager's defaultManager()

#############################
###入力ファイル
#############################
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
############ デフォルトロケーション
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias
####UTIリスト
set listUTI to {"public.movie"}
####ダイアログを出す
set aliasFilePath to (choose file with prompt "ムービーファイルを選んでください" default location (aliasDefaultLocation) of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias
###入力ファイル
set strFilePath to (POSIX path of aliasFilePath) as text
set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)

#############################
### ムービー読み込み
#############################
set ocidReadAsset to refMe's AVAsset's assetWithURL:(ocidFilePathURL)
set ocidReadAssetTrackArray to ocidReadAsset's tracks()
set ocidVideoTrack to ocidReadAssetTrackArray's firstObject()
#
set ocidAssetTrackTimeRange to ocidVideoTrack's timeRange()
set listTimeRange to (item 2 of ocidAssetTrackTimeRange)
set strSec to ((item 1 of listTimeRange) / (item 2 of listTimeRange)) as integer

set numFlameRate to ocidVideoTrack's nominalFrameRate()
log numFlameRate
set ocidFormatter to refMe's NSNumberFormatter's alloc()'s init()
(ocidFormatter's setNumberStyle:(refMe's NSNumberFormatterDecimalStyle))
(ocidFormatter's setMinimumFractionDigits:(1))
(ocidFormatter's setMaximumFractionDigits:(1))
(ocidFormatter's setRoundingMode:(refMe's NSNumberFormatterRoundDown))
set strFlameRate to (ocidFormatter's stringFromNumber:(numFlameRate)) as text
log strFlameRate
return

|

[AVAsset]基本的な情報の取得


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AVFoundation"
use framework "AppKit"
use framework "CoreMedia"
use scripting additions
property refMe : a reference to current application
####################################
####ダイアログ 入力ビデオ
####################################
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
############ デフォルトロケーション
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias
set listUTI to {"public.movie"}
set strMes to ("ファイルを選んでください") as text
set strPrompt to ("ファイルを選んでください") as text
try
  ### ファイル
  set aliasFilePath to (choose file strMes with prompt strPrompt default location (aliasDefaultLocation) of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias
on error
  log "エラーしました"
return "エラーしました"
end try
set strFilePath to POSIX path of aliasFilePath
set ocidFilePath to refMe's NSString's stringWithString:(strFilePath)
set ocidFilePathURL to refMe's NSURL's fileURLWithPath:(ocidFilePath)

####################################
####ダイアログ 出力フォルダ
####################################
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
set strMes to "フォルダを選んでください" as text
set strPrompt to "フォルダを選択してください" as text
try
  set aliasResponse to (choose folder strMes with prompt strPrompt default location aliasDefaultLocation without multiple selections allowed, invisibles and showing package contents) as alias
on error
  log "エラーしました"
return "エラーしました"
end try
set strSaveDirPath to POSIX path of aliasResponse
set ocidSaveDirPath to refMe's NSString's stringWithString:(strSaveDirPath)
set ocidSaveDirPathURL to refMe's NSURL's fileURLWithPath:(ocidSaveDirPath)

##########################################
######AVAsset
##########################################
set ocidReadAsset to refMe's AVAsset's assetWithURL:(ocidFilePathURL)
##Duration
set ocidReadAssetDuration to ocidReadAsset's duration()
log ocidReadAssetDuration as record
###総秒
set cmTime to refMe's CMTimeGetSeconds(ocidReadAssetDuration)
###時間
set numHours to (round of ((cmTime as number) / 3600) rounding down) as integer
###分
set numMinutes to (round of (((cmTime as number) - (numHours * 3600)) / 60) rounding down) as integer
###残り秒
set numSec to cmTime - ((numHours * 3600) + (numMinutes * 60))
log "時間:" & numHours & "時 " & numHours & "分 " & numSec & "秒"
######AVAssetTrackGroup
set ocidReadAssetTrackGArray to ocidReadAsset's trackGroups()
set numCntTrackG to (ocidReadAssetTrackGArray count) as integer
log "トラックグループ数: " & numCntTrackG
log ("トラックグループID: " & ((ocidReadAssetTrackGArray's firstObject())'s trackIDs() as integer)) as text

######AVAssetTrack
set ocidReadAssetTrackArray to ocidReadAsset's tracks()
set numCntTrack to (ocidReadAssetTrackArray count) as integer
log "トラック数は: " & numCntTrack
##
repeat with itemIntNo from 0 to (numCntTrack - 1) by 1
  set ocidTrack to (ocidReadAssetTrackArray's objectAtIndex:(itemIntNo))
  log className() of ocidTrack as text
  set strTrackID to ocidTrack's trackID() as text
  log strTrackID
  set strMediaType to ocidTrack's mediaType() as text
  if strMediaType is "vide" then
    ########################
    log "MediaType: vide ビデオトラック:トラックIDは" & strTrackID
    ## トラックの総時間
    set listAssetTrackTimeRange to ocidTrack's timeRange()
    set listStartTime to (item 1 of listAssetTrackTimeRange)
    set listDurationTime to (item 2 of listAssetTrackTimeRange)
    log listStartTime as list
    log listDurationTime as list
    ##タイムスケール
    set numAssetTrackTimeScale to ocidTrack's naturalTimeScale()
    log numAssetTrackTimeScale
    ##トラックの画面サイズ
    set recordAssetTrackNaturalSize to ocidTrack's naturalSize()
    log recordAssetTrackNaturalSize
    set numTrackWidth to (width of recordAssetTrackNaturalSize) as integer
    set numTrackHeight to (height of recordAssetTrackNaturalSize) as integer
    ##1フレームの長さ
    set recordCMTimeFrameDura to ocidTrack's minFrameDuration()
    set numFlameScale to ((value of recordCMTimeFrameDura) / (timescale of recordCMTimeFrameDura)) as number
    log numFlameScale
    set numFlameRateDura to (1 / numFlameScale)
    log numFlameRateDura
    ##フレームレート
    set numFlameRate to ocidTrack's nominalFrameRate() as number
    log numFlameRate
  else if strMediaType is "soun" then
    ########################
    log "MediaType: soun サウンドトラック:トラックIDは" & strTrackID
  end if
  
end repeat

|

[AVAsset]トラックグループ と トラック数


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AVFoundation"
use framework "AppKit"
use framework "CoreMedia"
use scripting additions
property refMe : a reference to current application
####################################
####ダイアログ
####################################
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
############ デフォルトロケーション
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias
set listUTI to {"public.movie"}
set strMes to ("ファイルを選んでください") as text
set strPrompt to ("ファイルを選んでください") as text
try
  ### ファイル
  set aliasFilePath to (choose file strMes with prompt strPrompt default location (aliasDefaultLocation) of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias
on error
  log "エラーしました"
return "エラーしました"
end try
set strFilePath to POSIX path of aliasFilePath
set ocidFilePath to refMe's NSString's stringWithString:(strFilePath)
set ocidFilePathURL to refMe's NSURL's fileURLWithPath:(ocidFilePath)
######AVAsset
set ocidReadAsset to refMe's AVAsset's assetWithURL:(ocidFilePathURL)

######AVAssetTrackGroup
set ocidReadAssetTrackArray to ocidReadAsset's trackGroups()
set numCntTrackG to (ocidReadAssetTrackArray count) as integer
log "トラックグループ数: " & numCntTrackG
log ("トラックグループID: " & ((ocidReadAssetTrackArray's firstObject())'s trackIDs() as integer)) as text

######AVAssetTrack
set ocidReadAssetTrackArray to ocidReadAsset's tracks()
set numCntTrack to (ocidReadAssetTrackArray count) as integer
log "トラック数は: " & numCntTrack

|

[AVAsset]ビデオの時間


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AVFoundation"
use framework "AppKit"
use framework "CoreMedia"
use scripting additions
property refMe : a reference to current application
####################################
####ダイアログ
####################################
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
############ デフォルトロケーション
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias
set listUTI to {"public.movie"}
set strMes to ("ファイルを選んでください") as text
set strPrompt to ("ファイルを選んでください") as text
try
  ### ファイル
  set aliasFilePath to (choose file strMes with prompt strPrompt default location (aliasDefaultLocation) of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias
on error
  log "エラーしました"
return "エラーしました"
end try
set strFilePath to POSIX path of aliasFilePath
set ocidFilePath to refMe's NSString's stringWithString:(strFilePath)
set ocidFilePathURL to refMe's NSURL's fileURLWithPath:(ocidFilePath)
######AVAsset
set ocidReadAsset to refMe's AVAsset's assetWithURL:(ocidFilePathURL)
##Duration
set ocidReadAssetDuration to ocidReadAsset's duration()
###総秒
set cmTime to refMe's CMTimeGetSeconds(ocidReadAssetDuration)
###時間
set numHours to (round of ((cmTime as number) / 3600) rounding down) as integer
###分
set numMinutes to (round of (((cmTime as number) - (numHours * 3600)) / 60) rounding down) as integer
###残り秒
set numSec to cmTime - ((numHours * 3600) + (numMinutes * 60))
log "時間:" & numHours & "時 " & numHours & "分 " & numSec & "秒"

######AVAssetTrack"


|

その他のカテゴリー

Accessibility Acrobat Acrobat 2020 Acrobat AddOn Acrobat Annotation Acrobat ARMDC Acrobat AV2 Acrobat BookMark Acrobat Classic Acrobat DC Acrobat Dialog Acrobat Distiller Acrobat Form Acrobat JS Acrobat Manifest Acrobat Menu Acrobat Open Acrobat Plugin Acrobat Preferences Acrobat Preflight Acrobat python Acrobat Reader Acrobat SCA Acrobat SCA Updater Acrobat Sequ Acrobat Sign Acrobat Stamps Acrobat Watermark Acrobat Windows Acrobat Windows Reader Admin Admin Account Admin Apachectl Admin configCode Admin Device Management Admin LaunchServices Admin Locationd Admin loginitem Admin Maintenance Admin Mobileconfig Admin Permission Admin Pkg Admin Power Management Admin Printer Admin SetUp Admin SMB Admin Support Admin System Information Admin Tools Admin Users Admin Volumes Adobe Adobe FDKO Adobe RemoteUpdateManager AppKit Apple AppleScript AppleScript do shell script AppleScript List AppleScript ObjC AppleScript Osax AppleScript PDF AppleScript Pictures AppleScript record AppleScript Script Editor AppleScript Script Menu AppleScript Shortcuts AppleScript Shortcuts Events AppleScript System Events AppleScript System Events Plist AppleScript Video Applications AppStore Archive Attributes Automator BackUp Barcode Barcode QR Barcode QR Decode Bash Basic Basic Path Bluetooth BOX Browser Calendar CD/DVD Choose Chrome CIImage CityCode CloudStorage Color com.apple.LaunchServices.OpenWith Console Contacts CotEditor CURL current application Date&Time delimiters Desktop Device Diff Disk Dock DropBox Droplet eMail Encode % Encode Decode Encode UTF8 Error EXIFData ffmpeg File Finder Firefox Folder FolderAction Fonts GIF github Guide HTML HTML Entity Icon Illustrator Image Events Image2PDF ImageOptim iPhone iWork Javascript Jedit Json Label Leading Zero List locationd LRC lsappinfo LSSharedFileList m3u8 Mail MakePDF Map Math Media Media AVAsset Media AVconvert Media AVFoundation Media AVURLAsset Media Movie Media Music Memo Messages Microsoft Microsoft Edge Microsoft Excel Mouse Music NetWork Notes NSArray NSArray Sort NSBezierPath NSBitmapImageRep NSBundle NSCFBoolean NSCharacterSet NSColor NSColorList NSData NSDecimalNumber NSDictionary NSError NSEvent NSFileAttributes NSFileManager NSFileManager enumeratorAtURL NSFont NSFontManager NSGraphicsContext NSImage NSIndex NSKeyedArchiver NSKeyedUnarchiver NSLocale NSMutableArray NSMutableDictionary NSMutableString NSNotFound NSNumber NSOpenPanel NSPasteboard NSpoint NSPredicate NSPrintOperation NSRange NSRect NSRegularExpression NSRunningApplication NSScreen NSSize NSString NSString stringByApplyingTransform NSStringCompareOptions NSTask NSTimeZone NSURL NSURL File NSURLBookmark NSURLComponents NSURLResourceKey NSURLSession NSUserDefaults NSUUID NSView NSWorkspace Numbers OAuth OneDrive PDF PDFAnnotation PDFAnnotationWidget PDFContext PDFDisplayBox PDFDocumentPermissions PDFImageRep PDFKit PDFnUP PDFOutline perl Photoshop PlistBuddy pluginkit postalcode PostScript prefPane Preview Python QuickLook QuickTime ReadMe Regular Expression Reminders ReName Repeat RTF Safari SaveFile ScreenCapture ScreenSaver SF Symbols character id SF Symbols Entity sips Skype Slack Sound Spotlight sqlite SRT StandardAdditions Swift System Settings TCC TemporaryItems Terminal Text Text CSV Text MD Text TSV TextEdit Tools Translate Trash Twitter Typography UI Unit Conversion UTType valueForKeyPath Video VisionKit Visual Studio Code Wacom webarchive webp Wifi Windows XML XML EPUB XML OPML XML Plist XML RSS XML savedSearch XML SVG XML TTML XML webloc XML XMP YouTube zoom