[webpmux] アニメーションWEBPファイルから各フレームイメージを書き出す
#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
(* libwebpが別途必要です
[applescript]libwebpインストール
https://quicktimer.cocolog-nifty.com/icefloe/2024/01/post-0a1a86.html
WEBPのアニメーションファイルからのイメージシーケンスの書き出しは
GIFと違って各フレームには
差分のみ保存されていますので あまり使いやすいものでもありません
*)
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use scripting additions
property refMe : a reference to current application
###【設定項目】バイナリーへのパス
set strWebpinfoPath to ("~/bin/libwebp/bin/webpinfo") as text
set strWebpmuxPath to ("~/bin/libwebp/bin/webpmux") as text
###webpinfoパス
set ocidBinPathStr to refMe's NSString's stringWithString:(strWebpinfoPath)
set ocidBinPath to ocidBinPathStr's stringByStandardizingPath()
set strWebpinfoPath to ocidBinPath as string
###strWebpmuxPathパス
set ocidBinPathStr to refMe's NSString's stringWithString:(strWebpmuxPath)
set ocidBinPath to ocidBinPathStr's stringByStandardizingPath()
set strWebpmuxPath to ocidBinPath as string
###ダイアログを前面に
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
tell application "Finder"
set aliasDesktopFolder to (path to desktop folder from user domain) as alias
end tell
####ファイル選択ダイアログ
set aliasFilePath to (choose file with prompt "WEBPのアニメーションファイルを選んでください" default location aliasDesktopFolder of type {"org.webmproject.webp"} with invisibles without showing package contents and multiple selections allowed) as alias
###入力ファイル
set strFilePath to (POSIX path of aliasFilePath) as text
##出力用のディレクトリを作る
tell application "Finder"
set strInputFileName to (name of aliasFilePath) as text
set strSaveDirName to (strInputFileName & "_フレーム画像") as text
set aliasContainerDirPath to (container of aliasFilePath) as alias
make new folder at aliasContainerDirPath with properties {name:strSaveDirName}
set aliasSaveDirPath to (folder strSaveDirName of folder aliasContainerDirPath) as alias
end tell
##出力用のディレクトリのパス
set strSaveDirPath to (POSIX path of aliasSaveDirPath) as text
############################
####webpinfo
############################
set strCommandText to ("\"" & strWebpinfoPath & "\" \"" & strFilePath & "\" | grep \"Chunk VP8L\"") as text
set strResponse to (do shell script strCommandText) as text
##フレーム数を数えます
set AppleScript's text item delimiters to "\r"
set listFlame to every text item of strResponse
set AppleScript's text item delimiters to ""
set numCntFlame to (count of listFlame) as integer
############################
####webpmux
############################
##フレームの数だけ繰り返します
repeat with itemFlameNO from 1 to numCntFlame by 1
##出力パス
set strOutPutFilePath to (strSaveDirPath & itemFlameNO & ".png") as text
##コマンド
set strCommandText to ("\"" & strWebpmuxPath & "\" -get frame " & itemFlameNO & " \"" & strFilePath & "\" -o \"" & strOutPutFilePath & "\"") as text
set strResponse to (do shell script strCommandText) as text
end repeat
| 固定リンク
「webp」カテゴリの記事
- [ffmpeg]ムービーファイルをアニメーションwebpにする(2023.12.06)
- [anim_dump] アニメーションWEBPファイルから各フレームイメージを書き出す(フレームイメージ)(2024.01.08)
- [webpmux] アニメーションWEBPファイルから各フレームイメージを書き出す(2023.12.20)
- [applescript]libwebpインストール(2024.01.07)
- [bash]libwebpインストール(2024.01.08)