QuickTimeムービーから指定ポイント(先頭からの再生秒)のフレームを静止画(PNG)に書き出すAppleScriptです。
ffmpegをバンドル内に格納して、それを呼び出すようにしています。ffmpegでフレーム抽出処理を行うと、QuickTime Playerに比べて処理時間がかかるようです。
AppleScript名:ffmpegでムービーの静止画書き出し |
— Created 2017-03-13 by Takaaki Naganoya — 2017 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "AVFoundation" –Caution: Don’t run on ASObjc Explorer 4 property NSUUID : a reference to current application’s NSUUID property AVAsset : a reference to current application’s AVAsset property AVAssetImageGenerator : a reference to current application’s AVAssetImageGenerator property |NSURL| : a reference to current application’s |NSURL| set targTime to 320 –target duration (seconds) set inPath to choose file of type {"public.mpeg-4", "public.movie"} set outPathPosix to getImageFromMovie(inPath, targTime) of me on getImageFromMovie(inPath, outTime) –https://yuichon.com/2016/02/ffmpeg-install/ –https://www.npmjs.com/package/ffmpeg-static set ffmpegPath to POSIX path of (path to me) & "Contents/Resources/ffmpeg" –ffmpeg-static –Adjust the pickup frame duration of the target set aDuration to getMovieDurationInSeconds(inPath) of me if outTime > aDuration then set outTime to aDuration end if –Generate Out File Path set outPath to POSIX path of (path to desktop) set aUUID to NSUUID’s UUID()’s UUIDString() as string set outFullPath to (outPath & aUUID & ".png") set sText to ffmpegPath & space & "-i" & space & (quoted form of POSIX path of inPath) & space & "-ss " & (outTime as string) & space & "-vframes 1" & space & quoted form of outFullPath do shell script sText return outFullPath end getImageFromMovie –指定ムービーの再生時間を秒で取得する on getMovieDurationInSeconds(aMoviePathAlias) set aPOSIX to POSIX path of aMoviePathAlias set aURL to |NSURL|’s fileURLWithPath:aPOSIX set anAsset to AVAsset’s assetWithURL:aURL set imageGenerator to AVAssetImageGenerator’s alloc()’s initWithAsset:anAsset set durTimes to current application’s CMTimeGetSeconds(anAsset’s duration()) return durTimes end getMovieDurationInSeconds |
More from my site
(Visited 57 times, 1 visits today)