20260518

[ffmpeg]メタデータの設定

[ffmpeg]メタデータの設定

NOTE記事一覧ですnote.com

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

メタデータを設定する.applescript.scpt
ソース
001#!/usr/bin/env osascript
002#coding: utf-8
003----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
004(*
005
006FFMEPGでメタデータをセットする
007https://note.com/quicktimer/n/n50092fdb55fc
008
009FFMPEGのインストールはこちらをみてください
010https://note.com/quicktimer/n/n1712711c41cd
011
012
013
014
015com.cocolog-nifty.quicktimer.icefloe *)
016----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
017use AppleScript version "2.8"
018use framework "Foundation"
019use framework "AppKit"
020use scripting additions
021property refMe : a reference to current application
022set appFileManager to refMe's NSFileManager's defaultManager()
023
024################################
025#設定項目
026#一般的にはこちら
027#set strFfmpegFilePath to ("/usr/local/bin/ffmpeg") as text
028#################################
029#ffmpeg へのパス
030set strFfmpegFilePath to ("~/Library/Application Support/bin/ffmpeg/ffmpeg") as text
031set ocidFfmpegFilePathStr to refMe's NSString's stringWithString:(strFfmpegFilePath)
032set ocidFfmpegFilePathStr to ocidFfmpegFilePathStr's precomposedStringWithCanonicalMapping()
033set ocidFfmpegFilePath to ocidFfmpegFilePathStr's stringByStandardizingPath()
034set ocidFfmpegFilePath to ocidFfmpegFilePath's stringByExpandingTildeInPath()
035set ocidFfmpegFilePathURL to refMe's NSURL's fileURLWithPath:(ocidFfmpegFilePath) isDirectory:(false)
036set strFfmpegFilePath to ocidFfmpegFilePathURL's |path|()
037
038#################################
039#ffprobe へのパス
040#一般的にはこちら
041#set strFfprobeFilePath to ("/usr/local/bin/ffprobe") as text
042set strFfprobeFilePath to ("~/Library/Application Support/bin/ffmpeg/ffprobe") as text
043set ocidFfprobeFilePathStr to refMe's NSString's stringWithString:(strFfprobeFilePath)
044set ocidFilePathStr to ocidFfprobeFilePathStr's precomposedStringWithCanonicalMapping()
045set ocidFfprobeFilePath to ocidFfprobeFilePathStr's stringByStandardizingPath()
046set ocidFfprobeFilePath to ocidFfprobeFilePath's stringByExpandingTildeInPath()
047set ocidFfprobeFilePathURL to refMe's NSURL's fileURLWithPath:(ocidFfprobeFilePath) isDirectory:(false)
048set ocidFfprobeFilePath to ocidFfprobeFilePathURL's |path|()
049
050
051################################
052####BINPATH  ffmpegのパス
053################################
054#有無チェック
055set boolExists to appFileManager's fileExistsAtPath:(ocidFfmpegFilePath) isDirectory:(false)
056if boolExists is true then
057   log "【OK】指定のパスにFFMPEGがあります"
058else if boolExists is false then
059   return "【NG】指定のパスにFFMPEGがありません"
060end if
061
062################################
063#####書き出し先パス Moviesフォルダ内へ
064################################
065set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSMoviesDirectory) inDomains:(refMe's NSUserDomainMask))
066set ocidMoviesDirPathURL to ocidURLsArray's firstObject()
067set ocidSaveDirPathURL to (ocidMoviesDirPathURL's URLByAppendingPathComponent:("_FFMPEG書出"))
068set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s init()
069ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions)
070set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
071################################
072#####ダイアログを前面に
073################################
074tell current application
075   set strName to name as text
076end tell
077if strName is "osascript" then
078   tell application "Finder" to activate
079else
080   tell current application to activate
081end if
082
083tell application "Finder"
084   set aliasDefaultLocation to container of (path to me) as alias
085end tell
086
087tell application "SystemUIServer"
088   activate
089   set aliasFilePath to (choose file with prompt "ファイルを選んでください" default location (aliasDefaultLocation) of type {"public.movie"} with invisibles and showing package contents without multiple selections allowed) as alias
090end tell
091##
092set strFilePath to (POSIX path of aliasFilePath) as text
093set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
094set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
095set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
096#保存先
097set ocidFileName to ocidFilePathURL's lastPathComponent()
098set ocidSaveFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(ocidFileName)
099set ocidSaveFilePath to ocidSaveFilePathURL's |path|()
100##ファイル名を取得(拡張子を除く)
101set ocidBaseFilePathURL to ocidFilePathURL's URLByDeletingPathExtension()
102set strFileName to ocidBaseFilePathURL's lastPathComponent() as text
103#
104set strSetBinFilePath to doPathEscape(strFfmpegFilePath)
105set strSetFilePath to doPathEscape(strFilePath)
106set strSetSaveFilePathURL to doPathEscape(ocidSaveFilePath)
107set strSetFileName to doPathEscape(strFileName)
108########################################
109#タイトルを入力して行う場合(全てハイフンを入れてメタを削除するサンプル)
110set strMetaTitle to ("-metadata title=\"-\"") as text
111set strSetMeta to ("" & strMetaTitle & " " & "-metadata artist=\"-\"") as text
112set strSetMeta to ("" & strSetMeta & " " & "-metadata album=\"-\"") as text
113set strSetMeta to ("" & strSetMeta & " " & "-metadata copyright=\"-\"") as text
114set strSetMeta to ("" & strSetMeta & " " & "-metadata comment=\"-\"") as text
115set strSetMeta to ("" & strSetMeta & " " & "-metadata author=\"-\"") as text
116set strSetMeta to ("" & strSetMeta & " " & "-metadata genre=\"-\"") as text
117set strSetMeta to ("" & strSetMeta & " " & "-metadata description=\"-\"") as text
118##入力して設定する場合
119set strCmd to ("\"" & strSetBinFilePath & "\" -i \"" & strSetFilePath & "\" " & strSetMeta & " -codec:v copy -codec:a copy   \"" & strSetSaveFilePathURL & "\"") as text
120
121do shell script strCmd
122
123#保存先を開く
124set appShardWorkspace to refMe's NSWorkspace's sharedWorkspace()
125set listDone to appShardWorkspace's openURL:(ocidSaveDirPathURL)
126set appFinderArray to refMe's NSRunningApplication's runningApplicationsWithBundleIdentifier:("com.apple.finder")
127set appFinder to appFinderArray's firstObject()
128set boolDone to appFinder's activateWithOptions:(refMe's NSApplicationActivateIgnoringOtherApps)
129return boolDone
130
131
132########################
133#パスのエスケープ
134to doPathEscape(strFilePath)
135   set strFilePath to strFilePath as text
136   set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
137   set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
138   set ocidFilePathURL to refMe's NSURL's fileURLWithPath:(ocidFilePath) isDirectory:(false)
139   set listEscChar to {"\\", "\"", "$", "`"} as list
140   repeat with itemEscChar in listEscChar
141      set ocidFilePath to (ocidFilePath's stringByReplacingOccurrencesOfString:(itemEscChar) withString:("\\" & itemEscChar & ""))
142   end repeat
143   set ocidFilePath to (ocidFilePath's stringByReplacingOccurrencesOfString:("!") withString:("\"'!'\""))
144   
145   return ocidFilePath
146end doPathEscape
AppleScriptで生成しました