[ffmpeg] タイムスケールを1000に設定する
AppleScript サンプルコード
行番号 | ソース |
---|---|
001 | #!/usr/bin/env osascript |
002 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
003 | # |
004 | (* |
005 | FFMPEGをインストールしていない場合は |
006 | インストールもします |
007 | |
008 | リサイズ設定無し エンコード同じでmp4に |
009 | タイムスケールを1000に設定します |
010 | |
011 | バイナリーはFFMPEGの野良サイトからダウンロードになりますので |
012 | ぜキュイティを担保できません |
013 | 不安な方は実行してください |
014 | *) |
015 | # |
016 | #com.cocolog-nifty.quicktimer.icefloe |
017 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
018 | use AppleScript version "2.8" |
019 | use framework "Foundation" |
020 | use framework "AppKit" |
021 | use scripting additions |
022 | property refMe : a reference to current application |
023 | set appFileManager to refMe's NSFileManager's defaultManager() |
024 | |
025 | |
026 | ################################ |
027 | ####設定項目 |
028 | ################################ |
029 | #インストール先 |
030 | set strBinFilePath to "~/bin/ffmpeg7.1/ffmpeg" as text |
031 | |
032 | |
033 | ################################ |
034 | ####BINPATH ffmpegのパス |
035 | ################################ |
036 | set ocidBinFilePathStr to refMe's NSString's stringWithString:(strBinFilePath) |
037 | set ocidBinFilePath to ocidBinFilePathStr's stringByStandardizingPath() |
038 | set ocidBinFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidBinFilePath) isDirectory:false) |
039 | set strBinFilePath to (ocidBinFilePathURL's |path|()) as text |
040 | #有無チェック |
041 | set boolDirExists to appFileManager's fileExistsAtPath:(ocidBinFilePath) isDirectory:(false) |
042 | if boolDirExists = true then |
043 | log "【OK】指定のパスにFFMPEGがあります" |
044 | else if boolDirExists = false then |
045 | log "【NG】指定のパスにFFMPEGがありません\rインストールします 1分程度時間がかかります" |
046 | set boolDone to doGetFFMPEG() |
047 | if boolDone is true then |
048 | log "インストール成功 処理継続" |
049 | else |
050 | return "インストール失敗 処理中断" |
051 | end if |
052 | end if |
053 | |
054 | ################################ |
055 | #####書き出し先パス Moviesフォルダ内へ |
056 | ################################ |
057 | set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSMoviesDirectory) inDomains:(refMe's NSUserDomainMask)) |
058 | set ocidMoviesDirPathURL to ocidURLsArray's firstObject() |
059 | set ocidSaveDirPathURL to (ocidMoviesDirPathURL's URLByAppendingPathComponent:("_FFMPEG書出")) |
060 | ## |
061 | set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0 |
062 | # 777-->511 755-->493 700-->448 766-->502 |
063 | ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions) |
064 | set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error| :(reference) |
065 | ################################ |
066 | #####ダイアログを前面に |
067 | ################################ |
068 | tell current application |
069 | set strName to name as text |
070 | end tell |
071 | if strName is "osascript" then |
072 | tell application "Finder" to activate |
073 | else |
074 | tell current application to activate |
075 | end if |
076 | set listAliasFile to (choose file "ファイルを選んでください" with prompt "ファイルを選んでください" default location (path to desktop folder from user domain) of type {"com.apple.quicktime-movie", "public.movie", "public.item"} with invisibles, showing package contents and multiple selections allowed) as list |
077 | |
078 | repeat with itemAliasFile in listAliasFile |
079 | set aliasFile to itemAliasFile as alias |
080 | set strFilePath to (POSIX path of aliasFile) as text |
081 | set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath)) |
082 | set ocidFilePath to ocidFilePathStr's stringByStandardizingPath() |
083 | set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false) |
084 | ##拡張子をとったファイル名 |
085 | set ocidBaseFilePathURL to ocidFilePathURL's URLByDeletingPathExtension() |
086 | set strBaeFileFileName to (ocidBaseFilePathURL's lastPathComponent()) as text |
087 | ##保存ファイル名 |
088 | set strSaveFileName to (strBaeFileFileName & ".mp4") as text |
089 | ##保存URL |
090 | set ocidSaveFilePathURL to (ocidSaveDirPathURL's URLByAppendingPathComponent:(strSaveFileName)) |
091 | set strSaveFilePath to ocidSaveFilePathURL's |path| as text |
092 | (* |
093 | ################ ビデオ |
094 | ### bitrate |
095 | -vb 720k |
096 | -vb 3600k |
097 | -vb 7200k |
098 | -vb 1080k |
099 | ### FPS |
100 | -r 23.9 |
101 | -r 24 |
102 | -r 30 |
103 | -r 50 |
104 | -r 60 |
105 | -r 120 |
106 | ### |
107 | -codec:v libx264 |
108 | -codec:v libx265 |
109 | -codec:v h264_videotoolbox |
110 | ### |
111 | -profile:v baseline |
112 | -profile:v main |
113 | -profile:v high |
114 | -profile:v high10 |
115 | -profile:v high422 |
116 | -profile:v high444 |
117 | ### |
118 | -tune film |
119 | -tune animation |
120 | -tune grain |
121 | -tune stillimage |
122 | -tune fastdecode |
123 | -tune zerolatency |
124 | ### |
125 | -preset ultrafast |
126 | -preset superfast |
127 | -preset veryfast |
128 | -preset faster |
129 | -preset fast |
130 | -preset medium |
131 | -preset slow |
132 | -preset slower |
133 | -preset veryslow |
134 | ### |
135 | -crf 0 |
136 | -crf 22 |
137 | -crf 28 |
138 | -crf 63 |
139 | ### Pillarbox |
140 | -vf "scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:-1:-1:color=black" |
141 | ### crop |
142 | -vf "scale=1280:720:force_original_aspect_ratio=increase, crop=1280:720" |
143 | ### 幅合わせ 高自動 |
144 | -vf "scale=1280:-2" |
145 | ###高さ合わせ 幅自動 |
146 | -vf "scale=-2:720" |
147 | ################ オーディオ |
148 | ### |
149 | -codec:a copy |
150 | -codec:a aac |
151 | -codec:a aac_at |
152 | -codec:a libfdk_aac |
153 | -codec:a libmp3lame |
154 | ### ビットレート bitrates |
155 | -b:a 32k |
156 | -b:a 96k |
157 | -b:a 128k |
158 | -b:a 256k |
159 | -b:a 320k |
160 | -b:a 512k |
161 | ###サンプルレート Samplerate |
162 | -r:a 16K |
163 | -r:a 22050 |
164 | -r:a 32K |
165 | -r:a 44100 |
166 | -r:a 48K |
167 | -r:a 96K |
168 | -r:a 192K |
169 | ### |
170 | -codec:a libmp3lame -ar 48K -ab 320k |
171 | -codec:a aac -ar 32K -ab 128k -aac_coder twoloop |
172 | |
173 | *) |
174 | |
175 | set strCommandText to ("\"" & ocidBinFilePath & "\" -i \"" & strFilePath & "\" -codec:v copy -codec:a copy -movflags +faststart -video_track_timescale 1000 \"" & strSaveFilePath & "\"") as text |
176 | |
177 | tell application "Terminal" |
178 | activate |
179 | set objWindowID to (do script "\n\n") |
180 | delay 1 |
181 | do script strCommandText in objWindowID |
182 | end tell |
183 | delay 3 |
184 | set listTime to {0, 0, 0} as list |
185 | set numInterval to 10 as integer |
186 | repeat |
187 | tell application "Terminal" |
188 | tell front window |
189 | tell front tab |
190 | set boolBusy to busy as boolean |
191 | end tell |
192 | end tell |
193 | end tell |
194 | if boolBusy is true then |
195 | ###スタートタイム |
196 | set strStartTime to doHMSms(listTime) |
197 | log "経過時間: " & strStartTime |
198 | delay numInterval |
199 | |
200 | ##まず秒が加算されるといくつになるか? |
201 | set numChkDigUp to (item 3 of listTime) + numInterval |
202 | ###↑この結果が59より大きければ繰り上がる |
203 | if numChkDigUp ≥ 60 then |
204 | set (item 3 of listTime) to numChkDigUp - 60 |
205 | if (item 2 of listTime) = 59 then |
206 | set (item 2 of listTime) to 0 |
207 | ####修正箇所 |
208 | #### set (item 1 of listTime) to (item 1 of listTime) + 1 |
209 | set (item 1 of listTime) to (item 1 of listTime) |
210 | else |
211 | set (item 2 of listTime) to (item 2 of listTime) + 1 |
212 | end if |
213 | else |
214 | set (item 3 of listTime) to (item 3 of listTime) + numInterval |
215 | end if |
216 | |
217 | ####エンドタイム |
218 | set strEndTime to doHMSms(listTime) |
219 | log strEndTime |
220 | |
221 | else if boolBusy is false then |
222 | exit repeat |
223 | end if |
224 | end repeat |
225 | |
226 | |
227 | end repeat |
228 | |
229 | ################################### |
230 | ###保存先を開く |
231 | ################################### |
232 | set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace() |
233 | set boolDone to appSharedWorkspace's openURL:(ocidSaveDirPathURL) |
234 | if boolDone is false then |
235 | set aliasFilePathURL to (ocidSaveDirPathURL's absoluteURL()) as alias |
236 | set boolResults to (appShardWorkspace's openURL:ocidCloudStorageDirURL) |
237 | if boolResults is false then |
238 | tell application "Finder" |
239 | make new Finder window to aliasFilePathURL |
240 | end tell |
241 | end if |
242 | end if |
243 | |
244 | ################################ |
245 | ##経過時間計算 |
246 | on doHMSms(listTime) |
247 | set strH to item 1 of listTime |
248 | set strM to item 2 of listTime |
249 | set strS to item 3 of listTime |
250 | return doPadding2Dig(strH) & ":" & doPadding2Dig(strM) & ":" & doPadding2Dig(strS) |
251 | end doHMSms |
252 | |
253 | ###2桁ゼロサプレス |
254 | on doPadding2Dig(numNO) |
255 | set strNO to ("0" & numNO) as text |
256 | return text -2 thru -1 of strNO |
257 | end doPadding2Dig |
258 | |
259 | |
260 | ###3桁逆ゼロサブレス |
261 | on doAfterPadding3Dig(numNO) |
262 | set strNO to (numNO & "00") as text |
263 | return text 1 thru 3 of strNO |
264 | end doAfterPadding3Dig |
265 | |
266 | ################################ |
267 | # 日付 doGetDateNo(argDateFormat,argCalendarNO) |
268 | # argCalendarNO 1 NSCalendarIdentifierGregorian 西暦 |
269 | # argCalendarNO 2 NSCalendarIdentifierJapanese 和暦 |
270 | ################################ |
271 | to doGetDateNo({argDateFormat, argCalendarNO}) |
272 | ##渡された値をテキストで確定させて |
273 | set strDateFormat to argDateFormat as text |
274 | set intCalendarNO to argCalendarNO as integer |
275 | ###日付情報の取得 |
276 | set ocidDate to current application's NSDate's |date|() |
277 | ###日付のフォーマットを定義(日本語) |
278 | set ocidFormatterJP to current application's NSDateFormatter's alloc()'s init() |
279 | ###和暦 西暦 カレンダー分岐 |
280 | if intCalendarNO = 1 then |
281 | set ocidCalendarID to (current application's NSCalendarIdentifierGregorian) |
282 | else if intCalendarNO = 2 then |
283 | set ocidCalendarID to (current application's NSCalendarIdentifierJapanese) |
284 | else |
285 | set ocidCalendarID to (current application's NSCalendarIdentifierISO8601) |
286 | end if |
287 | set ocidCalendarJP to current application's NSCalendar's alloc()'s initWithCalendarIdentifier:(ocidCalendarID) |
288 | set ocidTimezoneJP to current application's NSTimeZone's alloc()'s initWithName:("Asia/Tokyo") |
289 | set ocidLocaleJP to current application's NSLocale's alloc()'s initWithLocaleIdentifier:("ja_JP_POSIX") |
290 | ###設定 |
291 | ocidFormatterJP's setTimeZone:(ocidTimezoneJP) |
292 | ocidFormatterJP's setLocale:(ocidLocaleJP) |
293 | ocidFormatterJP's setCalendar:(ocidCalendarJP) |
294 | # ocidFormatterJP's setDateStyle:(current application's NSDateFormatterNoStyle) |
295 | # ocidFormatterJP's setDateStyle:(current application's NSDateFormatterShortStyle) |
296 | # ocidFormatterJP's setDateStyle:(current application's NSDateFormatterMediumStyle) |
297 | # ocidFormatterJP's setDateStyle:(current application's NSDateFormatterLongStyle) |
298 | ocidFormatterJP's setDateStyle:(current application's NSDateFormatterFullStyle) |
299 | ###渡された値でフォーマット定義 |
300 | ocidFormatterJP's setDateFormat:(strDateFormat) |
301 | ###フォーマット適応 |
302 | set ocidDateAndTime to ocidFormatterJP's stringFromDate:(ocidDate) |
303 | ###テキストで戻す |
304 | set strDateAndTime to ocidDateAndTime as text |
305 | return strDateAndTime |
306 | end doGetDateNo |
307 | |
308 | ################################### |
309 | ###ARM用にMakeされたFFMPEGをインストール |
310 | ################################### |
311 | to doGetFFMPEG() |
312 | |
313 | #インストールURL |
314 | set strZip1 to ("https://ffmpeg.martin-riedl.de/download/macos/arm64/1728231167_7.1/ffmpeg.zip") as text |
315 | set strZip2 to ("https://ffmpeg.martin-riedl.de/download/macos/arm64/1728231167_7.1/ffprobe.zip") as text |
316 | set strZip3 to ("https://ffmpeg.martin-riedl.de/download/macos/arm64/1728231167_7.1/ffplay.zip") as text |
317 | ######################## |
318 | #ダウンロード起動時に削除 |
319 | set appFileManager to refMe's NSFileManager's defaultManager() |
320 | set ocidTempDirURL to appFileManager's temporaryDirectory() |
321 | set ocidUUID to refMe's NSUUID's alloc()'s init() |
322 | set ocidUUIDString to ocidUUID's UUIDString |
323 | set ocidSaveDirPathURL to ocidTempDirURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:true |
324 | #ダウンロード用フォルダ |
325 | set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0 |
326 | ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions) |
327 | set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error| :(reference) |
328 | #パス |
329 | set ocidSaveZip1PathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:("ffmpeg.zip") isDirectory:(false) |
330 | set ocidSaveZip2PathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:("ffprobe.zip") isDirectory:(false) |
331 | set ocidSaveZip3PathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:("ffplay.zip") isDirectory:(false) |
332 | set strSaveZip1Path to ocidSaveZip1PathURL's |path|() as text |
333 | set strSaveZip2Path to ocidSaveZip2PathURL's |path|() as text |
334 | set strSaveZip3Path to ocidSaveZip3PathURL's |path|() as text |
335 | ######################## |
336 | #インストール先 |
337 | set appFileManager to refMe's NSFileManager's defaultManager() |
338 | set ocidHomeDirURL to appFileManager's homeDirectoryForCurrentUser() |
339 | set ocidDistDirPathURL to ocidHomeDirURL's URLByAppendingPathComponent:("bin/ffmpeg7.1") isDirectory:(true) |
340 | ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions) |
341 | set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidDistDirPathURL) withIntermediateDirectories:(true) attributes:(ocidAttrDict) |error| :(reference) |
342 | set ocidFFmpegPathURL to ocidDistDirPathURL's URLByAppendingPathComponent:("ffmpeg") isDirectory:(false) |
343 | set ocidFFprobePathURL to ocidDistDirPathURL's URLByAppendingPathComponent:("ffprobe") isDirectory:(false) |
344 | set ocidFFplayPathURL to ocidDistDirPathURL's URLByAppendingPathComponent:("ffplay") isDirectory:(false) |
345 | set strFFmpegPath to ocidFFmpegPathURL's |path|() as text |
346 | set strFFprobePath to ocidFFprobePathURL's |path|() as text |
347 | set strFFplayPath to ocidFFplayPathURL's |path|() as text |
348 | set strDistDirPath to ocidDistDirPathURL's |path|() as text |
349 | ######################## |
350 | #ダウンロード 1 |
351 | try |
352 | set strCommandText to ("/usr/bin/curl -L \"" & strZip1 & "\" -o \"" & strSaveZip1Path & "\" --connect-timeout 20") as text |
353 | set strExec to ("/bin/zsh -c '" & strCommandText & "'") |
354 | do shell script strExec |
355 | on error |
356 | return false |
357 | end try |
358 | try |
359 | set strCommandText to ("/usr/bin/curl -L \"" & strZip2 & "\" -o \"" & strSaveZip2Path & "\" --connect-timeout 20") as text |
360 | set strExec to ("/bin/zsh -c '" & strCommandText & "'") |
361 | do shell script strExec |
362 | on error |
363 | return false |
364 | end try |
365 | try |
366 | set strCommandText to ("/usr/bin/curl -L \"" & strZip3 & "\" -o \"" & strSaveZip3Path & "\" --connect-timeout 20") as text |
367 | set strExec to ("/bin/zsh -c '" & strCommandText & "'") |
368 | do shell script strExec |
369 | on error |
370 | return false |
371 | end try |
372 | |
373 | ######################## |
374 | #解凍 |
375 | try |
376 | set strCommandText to ("/usr/bin/unzip \"" & strSaveZip1Path & "\" -d \"" & strDistDirPath & "\"") as text |
377 | set strExec to ("/bin/zsh -c '" & strCommandText & "'") |
378 | do shell script strExec |
379 | on error |
380 | return false |
381 | end try |
382 | #解凍 |
383 | try |
384 | set strCommandText to ("/usr/bin/unzip \"" & strSaveZip2Path & "\" -d \"" & strDistDirPath & "\"") as text |
385 | set strExec to ("/bin/zsh -c '" & strCommandText & "'") |
386 | do shell script strExec |
387 | on error |
388 | return false |
389 | end try |
390 | #解凍 |
391 | try |
392 | set strCommandText to ("/usr/bin/unzip \"" & strSaveZip3Path & "\" -d \"" & strDistDirPath & "\"") as text |
393 | set strExec to ("/bin/zsh -c '" & strCommandText & "'") |
394 | do shell script strExec |
395 | on error |
396 | return false |
397 | end try |
398 | return true |
399 | |
400 | end doGetFFMPEG |
AppleScriptで生成しました |
| 固定リンク