AppleScript ffmpeg

ビデオサイズ変換(FFmpeg7用)

Ffmpeg001_20240409110801

ダウンロード - mov2mp4ffmpeg7.zip

バイナリーはこちらのサイトのものを利用 https://www.osxexperts.net/

|

ビデオからタイムラインのサムネイル 横型用 5x5サイズ


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#  Press [q] to stop, [?] for helpで作成中しばし待たれよ
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use framework "Foundation"
use AppleScript version "2.8"
use scripting additions

#################################
###ffprobe へのパス
set strPathToFFProbe to "echo $HOME/bin/ffmpeg.arm/ffprobe" as text
set strPathToFFProbe to (do shell script strPathToFFProbe)
#################################
###ffmpeg へのパス
set strPathToFFMPEG to "echo $HOME/bin/ffmpeg.arm/ffmpeg" as text
set strBinPath to (do shell script strPathToFFMPEG)
#################################
###ダイアログを出す
set theWithPrompt to "ビデオを選んでください"
set aliasDefaultLocation to path to desktop folder from user domain
set theFileType to "public.movie,public.mpeg-4,public.mpeg-4-audio" as text
set AppleScript's text item delimiters to {","}
set theFileTypeList to every text item of theFileType
set AppleScript's text item delimiters to ""
set listFileAlias to (choose file default location aliasDefaultLocation ¬
  with prompt theWithPrompt ¬
  of type theFileTypeList ¬
invisibles true ¬
  with multiple selections allowed without showing package contents) as list
#################
tell application "QuickTime Player"
launch
activate
end tell
tell application "Terminal"
launch
activate
end tell
#################################
### 選択したファイルの数だけ繰り返し
repeat with ObjFileAlias in listFileAlias
  tell application "QuickTime Player"
open ObjFileAlias
    tell document 1
properties
      set numDuration to (duration) as number
      set numDataRate to data rate as number
      set numDataSize to data size as number
      set strFileName to name as text
      set listDimension to natural dimensions as list
close
    end tell
  end tell
  set strFilePath to POSIX path of (ObjFileAlias as alias)
  set strCommandText to "\"" & strPathToFFProbe & "\" -show_streams \"" & strFilePath & "\" 2> /dev/null | grep nb_frames | head -n1 | sed 's/.*=//'"
  set numCntFlame to (do shell script strCommandText) as text
log numCntFlame
  if numCntFlame is "N/A" then
log "エラー:フレーム数を取得出来ませんでした"
    -->まぁだいたい元のムービーの不具合が多い
  else
    set numSec25 to (round (numCntFlame / 25) rounding down) as number
    set strPathToDistFileDir to "echo $HOME/Desktop/" as text
    set strPathToDistFile to ((do shell script strPathToDistFileDir) & strFileName & ".png") as text
    set strCommandText to "\"" & strBinPath & "\" -i \"" & strFilePath & "\" -vf select='not(mod(n\\," & numSec25 & "))',scale=256:144,tile=5x5 -frames:v 1 \"" & strPathToDistFile & "\"" as text
log strCommandText
    tell application "Terminal"
launch
activate
      set objWindowID to (do script "\n\n")
delay 1
do script strCommandText in objWindowID
    end tell
  end if
  
end repeat

|

ビデオからタイムラインのサムネイル 縦型用 3x15サイズ


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#  Press [q] to stop, [?] for help でしばし待たれよ
#
#
# 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
property refNSString : a reference to refMe's NSString
property refNSURL : a reference to refMe's NSURL
property refAVAsset : a reference to refMe's AVAsset

#################################
###ffmpeg へのパス(ここは設定項目です)
set strPathToFFMPEG to "echo $HOME/bin/ffmpeg/ffmpeg" as text
set strBinPath to (do shell script strPathToFFMPEG)
###通常はこちらかな?
# set strBinPath to ("/usr/local/bin/ffmpeg") as text
#################################
###ダイアログを出す

set theWithPrompt to "ビデオを選んでください"
set aliasDefaultLocation to path to desktop folder from user domain
set theFileType to "public.movie,public.mpeg-4,public.mpeg-4-audio" as text
set AppleScript's text item delimiters to {","}
set theFileTypeList to every text item of theFileType
set AppleScript's text item delimiters to ""
set listFileAlias to (choose file default location aliasDefaultLocation ¬
  with prompt theWithPrompt ¬
  of type theFileTypeList ¬
invisibles true ¬
  without showing package contents and multiple selections allowed) as list
###ファイルパス関連
set aliasFilePath to item 1 of listFileAlias as alias
set strFilePath to POSIX path of aliasFilePath as text
set ocidFilePath to refNSString's stringWithString:strFilePath
set ocidFullFilePath to ocidFilePath's stringByStandardizingPath()
set ocidFullFilePathURL to refMe's NSURL's fileURLWithPath:ocidFullFilePath
####出力ファイルパス
set strFileName to ocidFullFilePathURL's lastPathComponent
set ocidBaeFileName to strFileName's stringByDeletingPathExtension as text
set ocidContainerDirPath to ocidFullFilePathURL's URLByDeletingLastPathComponent
set strNSStringOrigFilePath to ocidContainerDirPath's |path|() as text
set strSaveFilePath to (strNSStringOrigFilePath & "/" & ocidBaeFileName & ".png") as text

log "##################AVAsset"
set ocidReadAsset to refAVAsset's assetWithURL:ocidFullFilePathURL
########duration(ビデオの長さ時間)を求める
set ocidReadAssetDuration to ocidReadAsset's duration()

(*tbn×秒数, tbn, flags, epoch*)
set strMovieSec to ((item 1 of ocidReadAssetDuration) / (item 2 of ocidReadAssetDuration)) as number
log strMovieSec & "秒"
(*
tbn = AVStream のタイム ベース
tbc = AVCodecContext のタイム ベース(timescale)
tbr = ビデオ フレーム レート
*)
(* 使わない値
########metadata(NSArray)
log ocidReadAsset's metadata() as list
log ocidReadAsset's commonMetadata() as list
log ocidReadAsset's availableMetadataFormats() as list
########creationDate
##log ((ocidReadAsset's creationDate)'s dateValue()) as date
########Accessing Suitabilityできる事
log ocidReadAsset's playable as boolean
log ocidReadAsset's exportable as boolean
log ocidReadAsset's readable as boolean
##log ocidReadAsset's rcomposable
log ocidReadAsset's compatibleWithAirPlayVideo as boolean
log ocidReadAsset's compatibleWithSavedPhotosAlbum as boolean
if (ocidReadAsset's exportable as boolean) is false then
log "このビデオは書き出しできません"
return
end if
###Accessing Content Protections
log ocidReadAsset's hasProtectedContent as boolean
if (ocidReadAsset's hasProtectedContent as boolean) is true then
log "このビデオは保護されています"
return
end if
###Accessing Fragment Support
log ocidReadAsset's containsFragments as boolean
###CMTimeGetSecondsでNaNが戻るのは値が無い場合
log refMe's CMTime's CMTimeGetSeconds(ocidReadAsset's overallDurationHint)
-->例:NaN
log refMe's CMTime's CMTimeAbsoluteValue(ocidReadAsset's overallDurationHint)
--> (*value:0, timescale:0, flags:0, epoch:0*)
###Accessing Asset Preferences
#log ocidReadAsset's preferredRate
#log ocidReadAsset's preferredVolume
#log ocidReadAsset's preferredTransform
#log ocidReadAsset's preferredMediaSelection
#log ocidReadAsset's preferredDisplayCriteria
#log ocidReadAsset's AVDisplayCriteria
###Accessing Media Selections
#log ocidReadAsset's allMediaSelections as list
#log ocidReadAsset's availableMediaCharacteristicsWithMediaSelectionOptions as list
*)
log "##################AVAssetTrack"
set ocidReadAssetTrackArray to ocidReadAsset's tracks()
###トラック数
set numCntTrackNo to (count of ocidReadAssetTrackArray) as integer
log "トラック数は: " & numCntTrackNo
###ビデオトラックは0なので0を取得エラーすればビデオが無い音声ムービー
set ocidAssetTrackTrack to (ocidReadAssetTrackArray's objectAtIndex:0)
####trackID
set strTrackID to ocidAssetTrackTrack's trackID() as text
####mediaType
set strMediaType to ocidAssetTrackTrack's mediaType() as text
if strMediaType is "vide" then
log "MediaType: vide ビデオトラック:トラックIDは" & strTrackID
else if strMediaType is "soun" then
log "MediaType: soun サウンドトラック:トラックIDは" & strTrackID
else
log "MediaType: " & strMediaType
log "TrackID: " & strTrackID
end if
###データレンジ
##log ocidAssetTrackTrack's totalSampleDataLength()
###タイムレンジ
##アセットとトラックの長さが同じとも限らないのでこの値を使う
set listAssetTrackTimeRange to (ocidAssetTrackTrack's timeRange()) as list
log listAssetTrackTimeRange
set listTimeScale to item 1 of listAssetTrackTimeRange as list
set listDuration to item 2 of listAssetTrackTimeRange as list
##ビデオトラックDuration値
set ocidAssetTrackTimeScale to (item 2 of listTimeScale) as integer
##TimeScale
set numDuration to (item 1 of listDuration) as integer
###タイムスケールは別値を使う
##naturalTimeScaleの値を使うとうまくいかない『場合』があるので
#set ocidAssetTrackTimeScale to ocidAssetTrackTrack's naturalTimeScale()
#log ocidAssetTrackTimeScale
####ビデオの縦横サイズ
set ocidAssetTrackNaturalSize to ocidAssetTrackTrack's naturalSize()
log ocidAssetTrackNaturalSize
####
set numWidth to ocidAssetTrackNaturalSize's width as integer
set numHeight to ocidAssetTrackNaturalSize's height as integer
###今回は横3毎なので1/3の幅が個別のイメージサイズ
set nunTileScaleWidth to numWidth / 3 as integer
set nunTileScaleHeight to numHeight / 3 as integer

if nunTileScaleWidth > nunTileScaleHeight then
  set strTile to "3x10" as text
  ###切り出し間隔Duration
  ###通常横系動画
  ###横3枚縦10枚合計30点必要なので30で割る
  set numImageTime to numDuration / 30 as number
  set numImageTimeSec to numImageTime / ocidAssetTrackTimeScale as integer
log numImageTimeSec & "秒毎"
else
  set strTile to "3x5" as text
  ###切り出し間隔Duration
  ##縦長動画用
  ###横3枚縦10枚合計30点必要なので15で割る
  set numImageTime to numDuration / 15 as number
  set numImageTimeSec to numImageTime / ocidAssetTrackTimeScale as integer
log numImageTimeSec & "秒毎"
end if


####フレームレート
set numFps to ocidAssetTrackTrack's nominalFrameRate() as number
####毎秒×フレームレートで 何フレーム毎にイメージ作成すれば良いか?
set numTimeScale to (item 2 of ocidReadAssetDuration) as integer
set nunVideoRuraByFlame to (numImageTimeSec / numTimeScale) as number
set numImageToFps to nunVideoRuraByFlame * numFps as integer


#set numImageToFps to numImageTimeSec * numFps as integer
#log "numFps: " & numImageToFps


####
(* 使わない値

set ocidAssetTrackNaturalSize to ocidAssetTrackTrack's naturalSize()
log ocidAssetTrackNaturalSize
set ocidCMTimeFrameDura to ocidAssetTrackTrack's minFrameDuration()
log ocidCMTimeFrameDura as record
log ocidAssetTrackTrack's estimatedDataRate()


log ((ocidAssetTrackTrack's formatDescriptions())'s objectAtIndex:0)
log ocidAssetTrackTrack's isPlayable()
log ocidAssetTrackTrack's isDecodable()
log ocidAssetTrackTrack's isEnabled()
log ocidAssetTrackTrack's isSelfContained()
log ocidAssetTrackTrack's requiresFrameReordering() as boolean
log ocidAssetTrackTrack's metadata() as list
log ocidAssetTrackTrack's commonMetadata() as list
log ocidAssetTrackTrack's availableMetadataFormats() as list
log ocidAssetTrackTrack's segments() as list
log ocidAssetTrackTrack's availableTrackAssociationTypes() as list
log ocidAssetTrackTrack's preferredTransform()
log ocidAssetTrackTrack's preferredVolume()
log ocidAssetTrackTrack's languageCode() as text
log ocidAssetTrackTrack's extendedLanguageTag()
log ocidAssetTrackTrack's hasAudioSampleDependencies()
*)
#################
tell application "Terminal"
launch
activate
end tell
#################################
### layout, nb_frames, margin, padding, color
####コマンド整形
set strCommandText to "\"" & strBinPath & "\" -i \"" & strFilePath & "\" -vf select='not(mod(n\\," & numImageToFps & "))',scale=" & nunTileScaleWidth & ":" & nunTileScaleHeight & ",tile=" & strTile & " -frames:v 1 \"" & strSaveFilePath & "\"" as text
log strCommandText
tell application "Terminal"
launch
activate
  set objWindowID to (do script "\n\n")
delay 1
do script strCommandText in objWindowID
end tell

set ocidReadAssetTrackArray to ""
set ocidReadAsset to ""
return


|

ビデオからイメージシーケンス


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

#!/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

####################################
###設定項目
####################################
###ビデオの全長をX等分してそれ毎にキャプチャ
set numTotalImageCnt to 28 as integer

##########################################
###### ffmpeg 基本設定
##########################################
###ffmpeg へのパス
set strPathToFFMPEG to "/bin/echo $HOME/bin/ffmpeg.arm/ffmpeg" as text
set strPathToFFMPEG to (do shell script strPathToFFMPEG)
#普通はこちら
# strPathToFFMPEG to ("/usr/local/bin/ffmpeg")

####################################
####ダイアログ 入力ビデオ
####################################
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()
###総秒
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 & "時 " & numMinutes & "分 " & 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 ((item 1 of recordCMTimeFrameDura) / (item 2 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


##########################################
###### 時間処理
##########################################

###表示フォーマット
set ocidFormatter to refMe's NSDateFormatter's alloc()'s init()
ocidFormatter's setTimeStyle:(refMe's NSDateFormatterNoStyle)
ocidFormatter's setDateStyle:(refMe's NSDateFormatterNoStyle)
ocidFormatter's setDateFormat:("HH:mm:ss")
###ファイル名フォーマット
set ocidFileNameFormatter to refMe's NSDateFormatter's alloc()'s init()
ocidFileNameFormatter's setTimeStyle:(refMe's NSDateFormatterNoStyle)
ocidFileNameFormatter's setDateStyle:(refMe's NSDateFormatterNoStyle)
ocidFileNameFormatter's setDateFormat:("HH_mm_ss")
###開始時間 カレンダ
set ocidCalendar to refMe's NSCalendar's currentCalendar()
set ocidStartTimeComp to refMe's NSDateComponents's alloc()'s init()
ocidStartTimeComp's setHour:0
ocidStartTimeComp's setMinute:0
ocidStartTimeComp's setSecond:5
set ocidStartTime to ocidCalendar's dateFromComponents:(ocidStartTimeComp)
log (ocidFormatter's stringFromDate:(ocidStartTime)) as text
###インターバル秒
set intInterval to (cmTime / numTotalImageCnt) as integer
###インターバルカレンダ コンポーネント(何秒毎)
set ocidIntervalComp to refMe's NSDateComponents's alloc()'s init()
ocidIntervalComp's setSecond:(intInterval)
####ビデオの長さ
set ocidEndTimeComp to refMe's NSDateComponents's alloc()'s init()
ocidEndTimeComp's setHour:(numHours)
ocidEndTimeComp's setMinute:(numMinutes)
ocidEndTimeComp's setSecond:(numSec)
set ocidEndTime to ocidCalendar's dateFromComponents:(ocidEndTimeComp)
log (ocidFormatter's stringFromDate:(ocidEndTime)) as text

###スタート時間
set ocidCaptureTime to ocidStartTime

##########################################
###### 本処理
##########################################
###取得毎数分繰り返し
repeat numTotalImageCnt times
  ###画像を取り出す時間
  set ocidCaptureTime to ocidCalendar's dateByAddingComponents:(ocidIntervalComp) toDate:(ocidCaptureTime) options:(0)
  ###FFMPEG用の時間テキストに
  set strCaptureTime to (ocidFormatter's stringFromDate:(ocidCaptureTime)) as text
log strCaptureTime
  ###ファイル名用の時間テキスト
  set strFileNameTime to (ocidFileNameFormatter's stringFromDate:(ocidCaptureTime)) as text
  ###時間テキストをそのままファイル名にしてパスにしておく
  set strSaveFilePath to (strSaveDirPath & strFileNameTime & ".png") as text
  ###コマンド整形
  set strCommandText to (strPathToFFMPEG & " -ss " & strCaptureTime & " -i \"" & strFilePath & "\" -frames:v 1 \"" & strSaveFilePath & "\"") as text
log strCommandText
  ###コマンド実行
do shell script strCommandText
  ###1秒まって次の処理
delay 1
end repeat



return







##1秒毎
set strCommandText to (strPathToFFMPEG & " -i \"" & strFilePath & "\" -vf fps=1 \"" & strSaveDirPath & "%04d.png\"") as text


##10秒毎
set strCommandText to (strPathToFFMPEG & " -i \"" & strFilePath & "\" -vf fps=1/10 \"" & strSaveDirPath & "%04d.png\"") as text

##ビデオの長さの24等分毎に
set intInterval to (cmTime / 24) as integer
set numInterval to (1 / intInterval) as number
set strCommandText to (strPathToFFMPEG & " -i \"" & strFilePath & "\" -vf fps=" & numInterval & " \"" & strSaveDirPath & "%04d.png\"") as text



##############################
##新規ウィンドウ
tell application "Terminal"
  set objNewWindow to (do script "\n")
end tell
##############################
## コマンド実行
tell application "Terminal"
do script strCommandText in objNewWindow
end tell

return
######AVMetadataItem
set ocidReadAssetMetadataArray to ocidReadAsset's metadata()
log "メタデータの数: " & ((ocidReadAssetMetadataArray count) as integer) as text
repeat with itemMetaData in ocidReadAssetMetadataArray
log itemMetaData's identifier() as text
log itemMetaData's dataType() as text
log itemMetaData's |key|() as text
log itemMetaData's keySpace() as text
log itemMetaData's stringValue() as text
end repeat

######BOOL値が戻り
log ocidReadAsset's isPlayable()
log ocidReadAsset's isExportable()
log ocidReadAsset's isReadable()
log ocidReadAsset's isComposable()
log ocidReadAsset's isCompatibleWithAirPlayVideo()
log ocidReadAsset's isCompatibleWithSavedPhotosAlbum()
log ocidReadAsset's hasProtectedContent()



|

[ffmpeg]ムービーファイルをイメージシーケンス画像にする

 

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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
# ###FFMPEGのインストールが別途必要です
# https://ffmpeg.org/
# fps 50の場合 1秒分で 50ファイル出来ますので留意ください
#
# 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

#
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
###デスクトップにファイル名のフォルダ作って
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 strSaveSequenceDirPathURL to (ocidSaveDirPathURL's |path|()) as text


##イメージシーケンス生成
set strCommandText to ("pushd \"" & strSaveSequenceDirPathURL & "\" && " & strBinPath & " -i \"" & strFilePathURL & "\" frame%04d.png") as text
do shell script strCommandText
##



|

[AppleScript]ffmpegインストール(野良)

野良のバイナリーをインストールしますので
不安な方は非推奨です
(とはいえ、現時点での公式に近い位置のバイナリです)

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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#com.cocolog-nifty.quicktimer.icefloe
(*
解凍に7zzを利用します
未インストールの場合はエラーになります
7zzインストール
https://quicktimer.cocolog-nifty.com/icefloe/2024/01/post-01fee7.html
*)
#
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application

set strURL1 to ("https://evermeet.cx/ffmpeg/ffmpeg-6.1.1.7z") as text
set strURL2 to ("https://evermeet.cx/ffmpeg/ffprobe-6.1.1.7z") as text
set strURL3 to ("https://evermeet.cx/ffmpeg/ffplay-6.1.1.7z") as text

###設定項目
set str7zzPath to ("~/bin/7zip/7zz") as text


set ocid7zzFilePathStr to refMe's NSString's stringWithString:(str7zzPath)
set ocid7zzFilePath to ocid7zzFilePathStr's stringByStandardizingPath()
set ocid7zzFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocid7zzFilePath) isDirectory:false)
set str7zzFilePathURL to (ocid7zzFilePathURL's |path|()) as text
################################################
###### データ保存
################################################
###ディレクトリ
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidTempDirURL to appFileManager's temporaryDirectory()
set ocidUUID to refMe's NSUUID's alloc()'s init()
set ocidUUIDString to ocidUUID's UUIDString
set ocidSaveDirPathURL to ocidTempDirURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:true
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
# 777-->511 755-->493 700-->448 766-->502
ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions)
set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
################################################
###### 展開
################################################
###展開先
set ocidHomeDirURL to appFileManager's homeDirectoryForCurrentUser()
set ocidInstallDirPathURL to ocidHomeDirURL's URLByAppendingPathComponent:("bin/ffmpeg") isDirectory:true
set strInstallDirPathURL to (ocidInstallDirPathURL's |path|()) as text
###フォルダ作る
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
# 777-->511 755-->493 700-->448 766-->502
ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions)
set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidInstallDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
################################################
###### ダウンロード
################################################
###URL1
set coidBaseURLStr to refMe's NSString's stringWithString:(strURL1)
set ocidBaseURL to refMe's NSURL's URLWithString:(coidBaseURLStr)
set ocidFileName to ocidBaseURL's lastPathComponent()
set ocidSaveFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(ocidFileName) isDirectory:false
set strSaveFilePath to ocidSaveFilePathURL's |path|() as text
#ダウンロード
set strCommandText to ("/usr/bin/curl -L \"" & strURL1 & "\" -o \"" & strSaveFilePath & "\" --connect-timeout 20")
do shell script strCommandText
#解凍
set strCommandText to ("\"" & str7zzFilePathURL & "\" x \"" & strSaveFilePath & "\" -aoa -o\"$HOME/bin/ffmpeg\"") as text
set strResponse to (do shell script strCommandText) as text
###URL2
set coidBaseURLStr to refMe's NSString's stringWithString:(strURL2)
set ocidBaseURL to refMe's NSURL's URLWithString:(coidBaseURLStr)
set ocidFileName to ocidBaseURL's lastPathComponent()
set ocidSaveFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(ocidFileName) isDirectory:false
set strSaveFilePath to ocidSaveFilePathURL's |path|() as text
#ダウンロード
set strCommandText to ("/usr/bin/curl -L \"" & strURL2 & "\" -o \"" & strSaveFilePath & "\" --connect-timeout 20")
do shell script strCommandText
#解凍
set strCommandText to ("\"" & str7zzFilePathURL & "\" x \"" & strSaveFilePath & "\" -aoa -o\"$HOME/bin/ffmpeg\"") as text
set strResponse to (do shell script strCommandText) as text
###URL3
set coidBaseURLStr to refMe's NSString's stringWithString:(strURL3)
set ocidBaseURL to refMe's NSURL's URLWithString:(coidBaseURLStr)
set ocidFileName to ocidBaseURL's lastPathComponent()
set ocidSaveFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(ocidFileName) isDirectory:false
set strSaveFilePath to ocidSaveFilePathURL's |path|() as text
#ダウンロード
set strCommandText to ("/usr/bin/curl -L \"" & strURL3 & "\" -o \"" & strSaveFilePath & "\" --connect-timeout 20")
do shell script strCommandText
#解凍
set strCommandText to ("\"" & str7zzFilePathURL & "\" x \"" & strSaveFilePath & "\" -aoa -o\"$HOME/bin/ffmpeg\"") as text
set strResponse to (do shell script strCommandText) as text


###################################
###保存先を開く
###################################
set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
set boolDone to appSharedWorkspace's openURL:(ocidInstallDirPathURL)
if boolDone is false then
  set aliasFilePathURL to (ocidInstallDirPathURL's absoluteURL()) as alias
  set boolResults to (appShardWorkspace's openURL:ocidCloudStorageDirURL)
  if boolResults is false then
    tell application "Finder"
make new Finder window to aliasFilePathURL
    end tell
  end if
end if




|

[ffmpeg] エンコードを変えずにそのままmp4に


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
# リサイズ設定無し エンコード同じでmp4に
#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 strFilePath to ("/usr/local/bin/ffmpeg") as text
#私用
set strFilePath to "~/bin/ffmpeg/ffmpeg" as text

################################
####BINPATH
################################
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 strPathToFFMPEG to (ocidFilePathURL's |path|()) as text

################################
#####書き出し先パス
################################
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSMoviesDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidMoviesDirPathURL to ocidURLsArray's firstObject()
set ocidSaveDirPathURL to (ocidMoviesDirPathURL's URLByAppendingPathComponent:("_FFMPEG書出"))
##
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
# 777-->511 755-->493 700-->448 766-->502
ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions)
set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
################################
#####ダイアログを前面に
################################
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 listAliasFile to (choose file "ファイルを選んでください" with prompt "ファイルを選んでください" default location (path to desktop folder from user domain) of type {"com.apple.quicktime-movie", "public.movie"} with invisibles, showing package contents and multiple selections allowed) as list

repeat with itemAliasFile in listAliasFile
  set aliasFile to itemAliasFile as alias
  set strFilePath to (POSIX path of aliasFile) 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 ocidBaseFilePathURL to ocidFilePathURL's URLByDeletingPathExtension()
  set strBaeFileFileName to (ocidBaseFilePathURL's lastPathComponent()) as text
  ##保存ファイル名
  set strSaveFileName to (strBaeFileFileName & ".mp4") as text
  ##保存URL
  set ocidSaveFilePathURL to (ocidSaveDirPathURL's URLByAppendingPathComponent:(strSaveFileName))
  set strSaveFilePath to ocidSaveFilePathURL's |path| as text
  (*
################ ビデオ
### bitrate
-vb 720k
-vb 3600k
-vb 7200k
-vb 1080k
### FPS
-r 23.9
-r 24
-r 30
-r 50
-r 60
-r 120
###
-codec:v libx264
-codec:v libx265
-codec:v h264_videotoolbox
###
-profile:v baseline
-profile:v main
-profile:v high
-profile:v high10
-profile:v high422
-profile:v high444
###
-tune film
-tune animation
-tune grain
-tune stillimage
-tune fastdecode
-tune zerolatency
###
-preset ultrafast
-preset superfast
-preset veryfast
-preset faster
-preset fast
-preset medium
-preset slow
-preset slower
-preset veryslow
###
-crf 0
-crf 22
-crf 28
-crf 63
### Pillarbox
-vf "scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:-1:-1:color=black"
### crop
-vf "scale=1280:720:force_original_aspect_ratio=increase, crop=1280:720"
### 幅合わせ  高自動 
-vf "scale=1280:-2"
###高さ合わせ 幅自動
-vf "scale=-2:720"
################ オーディオ
###
-codec:a copy
-codec:a aac
-codec:a aac_at
-codec:a libfdk_aac
-codec:a libmp3lame
### ビットレート bitrates
-b:a 32k
-b:a 96k
-b:a 128k
-b:a 256k
-b:a 320k
-b:a 512k
###サンプルレート Samplerate
-r:a 16K
-r:a 22050
-r:a 32K
-r:a 44100
-r:a 48K
-r:a 96K
-r:a 192K
###
-codec:a libmp3lame -ar 48K -ab 320k
-codec:a aac -ar 32K -ab 128k -aac_coder twoloop
*)
  
  ##set strCommandText to ("\"" & strPathToFFMPEG & "\" -i '" & strFilePath & "' -codec:v libx264 -profile:v baseline -tune film -crf 28 -codec:a aac -r:a 44100 -b:a 320k '" & strSaveFilePath & "'") as text
  set strCommandText to ("\"" & strPathToFFMPEG & "\" -i \"" & strFilePath & "\" -codec:v copy -codec:a copy \"" & strSaveFilePath & "\"") as text
  
  tell application "Terminal"
launch
activate
    set objWindowID to (do script "\n\n")
delay 1
do script strCommandText in objWindowID
    
  end tell
  
end repeat

###################################
###保存先を開く
###################################
set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
set boolDone to appSharedWorkspace's openURL:(ocidSaveDirPathURL)
if boolDone is false then
  set aliasFilePathURL to (ocidSaveDirPathURL's absoluteURL()) as alias
  set boolResults to (appShardWorkspace's openURL:ocidCloudStorageDirURL)
  if boolResults is false then
    tell application "Finder"
make new Finder window to aliasFilePathURL
    end tell
  end if
end if


################################
# 日付 doGetDateNo(argDateFormat,argCalendarNO)
# argCalendarNO 1 NSCalendarIdentifierGregorian 西暦
# argCalendarNO 2 NSCalendarIdentifierJapanese 和暦
################################
to doGetDateNo({argDateFormat, argCalendarNO})
  ##渡された値をテキストで確定させて
  set strDateFormat to argDateFormat as text
  set intCalendarNO to argCalendarNO as integer
  ###日付情報の取得
  set ocidDate to current application's NSDate's |date|()
  ###日付のフォーマットを定義(日本語)
  set ocidFormatterJP to current application's NSDateFormatter's alloc()'s init()
  ###和暦 西暦 カレンダー分岐
  if intCalendarNO = 1 then
    set ocidCalendarID to (current application's NSCalendarIdentifierGregorian)
  else if intCalendarNO = 2 then
    set ocidCalendarID to (current application's NSCalendarIdentifierJapanese)
  else
    set ocidCalendarID to (current application's NSCalendarIdentifierISO8601)
  end if
  set ocidCalendarJP to current application's NSCalendar's alloc()'s initWithCalendarIdentifier:(ocidCalendarID)
  set ocidTimezoneJP to current application's NSTimeZone's alloc()'s initWithName:("Asia/Tokyo")
  set ocidLocaleJP to current application's NSLocale's alloc()'s initWithLocaleIdentifier:("ja_JP_POSIX")
  ###設定
ocidFormatterJP's setTimeZone:(ocidTimezoneJP)
ocidFormatterJP's setLocale:(ocidLocaleJP)
ocidFormatterJP's setCalendar:(ocidCalendarJP)
  # ocidFormatterJP's setDateStyle:(current application's NSDateFormatterNoStyle)
  # ocidFormatterJP's setDateStyle:(current application's NSDateFormatterShortStyle)
  # ocidFormatterJP's setDateStyle:(current application's NSDateFormatterMediumStyle)
  # ocidFormatterJP's setDateStyle:(current application's NSDateFormatterLongStyle)
ocidFormatterJP's setDateStyle:(current application's NSDateFormatterFullStyle)
  ###渡された値でフォーマット定義
ocidFormatterJP's setDateFormat:(strDateFormat)
  ###フォーマット適応
  set ocidDateAndTime to ocidFormatterJP's stringFromDate:(ocidDate)
  ###テキストで戻す
  set strDateAndTime to ocidDateAndTime as text
return strDateAndTime
end doGetDateNo


|

[Bash]ffmpegインストール


#!/bin/bash
#com.cocolog-nifty.quicktimer.icefloe
#ユーザード $HOME/binにインストールする
#解凍に7zzを使用します
########################################
### 設定項目
STR_URL_FFMPEG="https://evermeet.cx/ffmpeg/ffmpeg-6.1.1.7z"
STR_URL_FFPROBE="https://evermeet.cx/ffmpeg/ffprobe-6.1.1.7z"
STR_URL_FFPLAY="https://evermeet.cx/ffmpeg/ffplay-6.1.1.7z"

########################################
###管理者インストールしているか?チェック
USER_WHOAMI=$(/usr/bin/whoami)
/bin/echo "実行ユーザーは:$USER_WHOAMI"
###実行しているユーザー名
CONSOLE_USER=$(/bin/echo "show State:/Users/ConsoleUser" | /usr/sbin/scutil | /usr/bin/awk '/Name :/ { print $3 }')
/bin/echo "コンソールユーザー:$CONSOLE_USER"
###ログイン名ユーザー名※Visual Studio Codeの出力パネルではrootになる設定がある
LOGIN_NAME=$(/usr/bin/logname)
/bin/echo "ログイン名:$LOGIN_NAME"
###UID
USER_NAME=$(/usr/bin/id -un)
/bin/echo "ユーザー名:$USER_NAME"
###SUDOUSER
/bin/echo "SUDO_USER: $SUDO_USER"
########################################
##OS
PLIST_PATH="/System/Library/CoreServices/SystemVersion.plist"
STR_OS_VER=$(/usr/bin/defaults read "$PLIST_PATH" ProductVersion)
/bin/echo "OS VERSION :" "$STR_OS_VER"
STR_MAJOR_VERSION="${STR_OS_VER%%.*}"
/bin/echo "STR_MAJOR_VERSION :" "$STR_MAJOR_VERSION"
STR_MINOR_VERSION="${STR_OS_VER#*.}"
/bin/echo "STR_MINOR_VERSION :" "$STR_MINOR_VERSION"
########################################
###ダウンロード起動時に削除する項目
USER_TEMP_DIR=$(/usr/bin/mktemp -d)
/bin/echo "起動時に削除されるディレクトリ:" "$USER_TEMP_DIR"
############################################################
############################################################
###BIN
/bin/mkdir -p "/Users/$CONSOLE_USER/bin/"
for ((numTimes = 1; numTimes <= 3; numTimes++)); do
sleep 1
/bin/mkdir -p "/Users/$CONSOLE_USER/bin/ffmpeg"
/usr/bin/touch "/Users/$CONSOLE_USER/bin/ffmpeg"
/usr/sbin/chown "$CONSOLE_USER" "/Users/$CONSOLE_USER/bin/ffmpeg"
/bin/chmod 700 "/Users/$CONSOLE_USER/bin/ffmpeg"
done

###ダウンロードSTR_URL_FFMPEG
DL_FILE_NAME="FFMPEG.7z"
if ! /usr/bin/curl -L -o "$USER_TEMP_DIR/$DL_FILE_NAME" "$STR_URL_FFMPEG" --connect-timeout 20; then
/bin/echo "ファイルのダウンロードに失敗しました HTTP1.1で再トライします"
  if ! /usr/bin/curl -L -o "$USER_TEMP_DIR/$DL_FILE_NAME" "$STR_URL_FFMPEG" --http1.1 --connect-timeout 20; then
/bin/echo "ファイルのダウンロードに失敗しました"
exit 1
  fi
fi
###旧バージョンをゴミ箱に
USER_TRASH_DIR=$(/usr/bin/mktemp -d "$HOME/.Trash/FFMPEG.XXXXXXXX")
/bin/mv "/Users/$CONSOLE_USER/bin/ffmpeg/ffmpeg" "$USER_TRASH_DIR"
##移動して
/bin/mv -f "$USER_TEMP_DIR/$DL_FILE_NAME" "/Users/$CONSOLE_USER/bin/ffmpeg"
/Users/"$CONSOLE_USER"/bin/7zip/7zz x "/Users/$CONSOLE_USER/bin/ffmpeg/$DL_FILE_NAME" -o"/Users/$CONSOLE_USER/bin/ffmpeg"
/bin/mv "/Users/$CONSOLE_USER/bin/ffmpeg/$DL_FILE_NAME" "$USER_TRASH_DIR"
###ダウンロードSTR_URL_FFMPEG
DL_FILE_NAME="FFPROBE.7z"
if ! /usr/bin/curl -L -o "$USER_TEMP_DIR/$DL_FILE_NAME" "$STR_URL_FFPROBE" --connect-timeout 20; then
/bin/echo "ファイルのダウンロードに失敗しました HTTP1.1で再トライします"
  if ! /usr/bin/curl -L -o "$USER_TEMP_DIR/$DL_FILE_NAME" "$STR_URL_FFPROBE" --http1.1 --connect-timeout 20; then
/bin/echo "ファイルのダウンロードに失敗しました"
exit 1
  fi
fi
###旧バージョンをゴミ箱に
USER_TRASH_DIR=$(/usr/bin/mktemp -d "$HOME/.Trash/FFMPEG.XXXXXXXX")
/bin/mv "/Users/$CONSOLE_USER/bin/ffmpeg/ffprobe" "$USER_TRASH_DIR"
/bin/mv -f "$USER_TEMP_DIR/$DL_FILE_NAME" "/Users/$CONSOLE_USER/bin/ffmpeg"
/Users/"$CONSOLE_USER"/bin/7zip/7zz x "/Users/$CONSOLE_USER/bin/ffmpeg/$DL_FILE_NAME" -o"/Users/$CONSOLE_USER/bin/ffmpeg"
/bin/mv "/Users/$CONSOLE_USER/bin/ffmpeg/$DL_FILE_NAME" "$USER_TRASH_DIR"
###ダウンロードSTR_URL_FFPLAY
DL_FILE_NAME="FFPLAY.7z"
if ! /usr/bin/curl -L -o "$USER_TEMP_DIR/$DL_FILE_NAME" "$STR_URL_FFPLAY" --connect-timeout 20; then
/bin/echo "ファイルのダウンロードに失敗しました HTTP1.1で再トライします"
  if ! /usr/bin/curl -L -o "$USER_TEMP_DIR/$DL_FILE_NAME" "$STR_URL_FFPLAY" --http1.1 --connect-timeout 20; then
/bin/echo "ファイルのダウンロードに失敗しました"
exit 1
  fi
fi
###旧バージョンをゴミ箱に
USER_TRASH_DIR=$(/usr/bin/mktemp -d "$HOME/.Trash/FFMPEG.XXXXXXXX")
/bin/mv "/Users/$CONSOLE_USER/bin/ffmpeg/ffplay" "$USER_TRASH_DIR"
/bin/mv -f "$USER_TEMP_DIR/$DL_FILE_NAME" "/Users/$CONSOLE_USER/bin/ffmpeg"
/Users/"$CONSOLE_USER"/bin/7zip/7zz x "/Users/$CONSOLE_USER/bin/ffmpeg/$DL_FILE_NAME" -o"/Users/$CONSOLE_USER/bin/ffmpeg"
/bin/mv "/Users/$CONSOLE_USER/bin/ffmpeg/$DL_FILE_NAME" "$USER_TRASH_DIR"
############################################################
###
/usr/bin/open "/Users/$CONSOLE_USER/bin/ffmpeg"


|

[ffmpeg]ムービーファイルをGIFにする


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
# ###FFMPEGのインストールが別途必要です
# https://ffmpeg.org/
# fps 50の場合 1秒分で 50ファイル出来ますので留意ください
#
# 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 text


###デスクトップにファイル名のフォルダ作って
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 & ".gif") 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 & ",split[v0][v1];[v0]palettegen[p];[v1][p]paletteuse\" -loop 0 \"" & strSaveFilePathURL & "\"") as text
do shell script strCommandText



|

[ffmpeg] GIFアニメーションをmp4に変換する


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
(* FFMPEGのインストールが別途必要です
[AppleScript]ffmpegインストール
https://quicktimer.cocolog-nifty.com/icefloe/2024/01/post-1ce12f.html
*)
# 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 scripting additions

property refMe : a reference to current application

###【設定項目】バイナリーへのパス
set strBinPath to ("~/bin/ffmpeg/ffmpeg") as text
###【設定項目】何回ループさせるか?
set numLoopTime to ("5") 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
tell application "Finder"
  set aliasDesktopFolder to (path to desktop folder from user domain) as alias
end tell
####ファイル選択ダイアログ
set aliasFilePath to (choose file with prompt "Gifファイルを選んでください" default location aliasDesktopFolder of type {"com.compuserve.gif"} 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 aliasTempDirPath to (path to temporary items folder from user domain) as alias
end tell
##UUIDを生成
set ocidUUID to refMe's NSUUID's alloc()'s init()
set strUUID to ocidUUID's UUIDString as text
###フォルダを作る
tell application "Finder"
make new folder at aliasTempDirPath with properties {name:strUUID}
  set aliasTempSaveDirPath to (folder strUUID of folder aliasTempDirPath) as alias
end tell
set strTempSaveDirPath to (POSIX path of aliasTempSaveDirPath) as text
set strTempFilePath to (strTempSaveDirPath & "tmp.gif")

############################
####まずはループムービーを作成する
############################
if numLoopTime is not "0" then
  set strCommandText to ("\"" & strBinPath & "\" -stream_loop " & numLoopTime & " -i \"" & strFilePath & "\" \"" & strTempFilePath & "\"") as text
  set strResponse to (do shell script strCommandText) as text
else
  set strCommandText to ("\"/usr/bin/ditto\" \"" & strFilePath & "\" \"" & strTempFilePath & "\"") as text
  set strResponse to (do shell script strCommandText) as text
end if
set strTempMp4FilePath to (strTempSaveDirPath & "tmp.mp4")
############################
####ループムービーをmp4に変換
############################
set strCommandText to ("\"" & strBinPath & "\" -f gif -i \"" & strTempFilePath & "\" -codec:v libx264 -tune animation \"" & strTempMp4FilePath & "\" -y") as text
set strResponse to (do shell script strCommandText) 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
  try
make new folder at aliasContainerDirPath with properties {name:strSaveDirName}
  end try
  set aliasSaveDirPath to (folder strSaveDirName of folder aliasContainerDirPath) as alias
end tell

##出力用のディレクトリのパス
set strSaveDirPath to (POSIX path of aliasSaveDirPath) as text
set strSaveFilePath to (strSaveDirPath & strInputFileName & ".mp4")
############################
####ループムービーをmp4に変換
############################
set strCommandText to ("\"" & strBinPath & "\" -i \"" & strTempMp4FilePath & "\" -strict -2 -codec:v libopenh264 -tune animation -filter:v fps=24 \"" & strSaveFilePath & "\" -y") as text
set strResponse to (do shell script strCommandText) as text



|

その他のカテゴリー

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