[ffmpeg]ムービーファイルをアニメーションwebpにする
#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
# ###FFMPEGのインストールが別途必要です
# https://ffmpeg.org/
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AVFoundation"
use scripting additions
property refMe : a reference to current application
set appFileManager to refMe's NSFileManager's defaultManager()
##############################
###設定項目
###FFMPEGのパス
###通常はこちらかな?
# set strBinPath to ("/usr/local/bin/ffmpeg") as text
set strBinPath to ("~/bin/ffmpeg.6/ffmpeg") as text
#ffmpeg
set ocidBinPathStr to refMe's NSString's stringWithString:(strBinPath)
set ocidBinPath to ocidBinPathStr's stringByStandardizingPath()
set strBinPath 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
############ デフォルトロケーション
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 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) 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 strFilePathURL to (ocidFilePathURL's |path|()) as text
set ocidBaseFilePathURL to ocidFilePathURL's URLByDeletingPathExtension()
set strFileName to (ocidBaseFilePathURL's lastPathComponent()) as text
###AVURLAssetを利用してFPSを求める
set ocidReadAsset to (refMe's AVURLAsset's alloc()'s initWithURL:(ocidFilePathURL) options:(missing value))
set ocidReadAssetArray to (ocidReadAsset's tracksWithMediaType:(refMe's AVMediaTypeVideo))
set ocidAssetVideoTrack to (ocidReadAssetArray's objectAtIndex:0)
####フレームレートFPS
set ocidFrameRate to ocidAssetVideoTrack's nominalFrameRate()
####整数にしてテキスト化
set strFPS to ((round (ocidFrameRate * 100)) / 100) as integer
###デスクトップにファイル名のフォルダ作って
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
set strSetDirName to (strFileName & "_書出") as text
set ocidSaveDirPathURL to ocidDesktopDirPathURL's URLByAppendingPathComponent:(strSetDirName)
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions)
set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
##
set strSaveFileName to (strFileName & ".webp") as text
set ocidSaveFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(strSaveFileName)
set strSaveFilePathURL to ocidSaveFilePathURL's |path| as text
##イメージシーケンス生成
##フル設定
# set strCommandText to ("\"" & strBinPath & "\" -i \"" & strFilePathURL & "\" -vf \"fps=" & strFPS & "\" -vcodec libwebp -loop 0 -lossless 0 -compression_level 3 -q:v 70 -preset picture -an -vsync 0 \"" & strSaveFilePathURL & "\"") as text
##簡易設定
set strCommandText to ("\"" & strBinPath & "\" -i \"" & strFilePathURL & "\" -vf \"fps=" & strFPS & "\" -vcodec libwebp -loop 0 -lossless 0 -preset photo \"" & strSaveFilePathURL & "\"") as text
do shell script strCommandText
(*
libwebp_anim AVOptions:
-lossless <int> E..V...... Use lossless mode (from 0 to 1) (default 0)
-preset <int> E..V...... Configuration preset (from -1 to 5) (default none)
none -1 E..V...... do not use a preset
default 0 E..V...... default preset
picture 1 E..V...... digital picture, like portrait, inner shot
photo 2 E..V...... outdoor photograph, with natural lighting
drawing 3 E..V...... hand or line drawing, with high-contrast details
icon 4 E..V...... small-sized colorful images
text 5 E..V...... text-like
-cr_threshold <int> E..V...... Conditional replenishment threshold (from 0 to INT_MAX) (default 0)
-cr_size <int> E..V...... Conditional replenishment block size (from 0 to 256) (default 16)
-quality <float> E..V...... Quality (from 0 to 100) (default 75)
*)
| 固定リンク
「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)