20260523

[applescript] ビデオのpxサイズ取得 QuickTime Player

[applescript] ビデオのpxサイズ取得 QuickTime Player を使う

NOTE記事一覧ですnote.com
 

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

ビデオのpxサイズ取得QuickTime.scpt.scpt
ソース
001#!/usr/bin/env osascript
002#coding: utf-8
003----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
004(*
005
006クイックタイムプレイヤーを使う
007
008com.cocolog-nifty.quicktimer.icefloe *)
009----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
010use AppleScript version "2.8"
011use scripting additions
012
013
014
015#############################
016###入力ファイル
017#############################
018tell current application
019   set strName to name as text
020end tell
021if strName is "osascript" then
022   tell application "Finder" to activate
023else
024   tell current application to activate
025end if
026#デスクトップ
027set aliasDesktopDirPath to (path to desktop from user domain) as alias
028set listUTI to {"public.movie"} as list
029set strTitle to ("ファイル選択") as text
030set strPrompt to ("ムービーファイルを選んでください") as text
031tell application "SystemUIServer"
032   activate
033   set listAliasFilePath to (choose file with prompt (strPrompt) default location (aliasDesktopDirPath) of type (listUTI) with invisibles, showing package contents and multiple selections allowed) as list
034end tell
035
036#ソート 名前順
037tell application "Finder"
038   set listSortedFilePath to (sort of listAliasFilePath by name) as alias list
039end tell
040
041#エイリアスリストの中のパスの数
042set numCntList to (count of listSortedFilePath) as integer
043
044repeat with itemIntNo from 1 to numCntList by 1
045   #開くムービーのエイリアス・パスをエイリアスリストから取得して
046   set aliasItemFilePath to (item itemIntNo of listSortedFilePath) as alias
047   #ムービーを開く
048   tell application "QuickTime Player"
049      set refOpenDoc to open file aliasItemFilePath
050   end tell
051   #ロード待ち最大5秒
052   repeat 10 times
053      tell application "QuickTime Player"
054         tell refOpenDoc
055            set strFileName to (its name) as text
056         end tell
057      end tell
058      if strFileName = (missing value) then
059         delay 0.5
060      else
061         exit repeat
062      end if
063   end repeat
064   #値の取得
065   tell application "QuickTime Player"
066      tell refOpenDoc
067         set numSize to (its data size) as number
068         set numDuration to (its duration) as number
069         set numDataRate to (its data rate) as number
070         set listDimensions to (its natural dimensions) as list
071      end tell
072   end tell
073   #値の整形 データサイズ
074   set numSize to (numSize / (1000 * 1000)) as integer
075   if numSize > 1000 then
076      set strFileSize to ((numSize / 100) & " GB") as text
077   else
078      set strFileSize to ((numSize) & " MB") as text
079   end if
080   #値の整形 duration 分数
081   #小数点以下
082   set numMilliSec to (numDuration mod 1) as number
083   set numSec to (numDuration - numMilliSec) as integer
084   set numMin to (round (numSec / 60) rounding down) as integer
085   set strMin to ("" & numMin & " MIN") as text
086   
087   #値の整形 縦横PXサイズ
088   set numWpx to (first item of listDimensions) as integer
089   set numHpx to (last item of listDimensions) as integer
090   
091   
092   
093   #開いたビデオを閉じる
094   tell application "QuickTime Player"
095      close refOpenDoc saving no
096   end tell
097   log numWpx
098   log numHpx
099end repeat
100
101
102return
AppleScriptで生成しました