AppleScript AVURLAsset

ビデオのリネーム(縦横FPS分数を付与)


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

#!/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 "AppKit"
use framework "UniformTypeIdentifiers"
use framework "AVFoundation"
use scripting additions

property refMe : a reference to current application

#ファイル名と付与する値の区切り文字
property strSeparateStr : ("@") as text

######### on run
-->ダブルクリックしたら
on run
  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 aliasIconPass to (POSIX file "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/SidebarMoviesFolder.icns") as alias
  set strDialogText to "ファイルをドロップしても利用できます"
  set strTitleText to "ムービーファイルを選んでください"
  set listButton to {"ファイルを選びます", "キャンセル"} as list
display dialog strDialogText buttons listButton default button 1 cancel button 2 with title strTitleText with icon aliasIconPass giving up after 1 with hidden answer
  
  set aliasDefaultLocation to (path to desktop folder from user domain) as alias
  set listUTI to {"public.mpeg-4", "public.mpeg-2-transport-stream", "com.apple.quicktime-movie", "public.movie"} as list
  set strPromptText to "ファイルを選んでください" as text
  
  set listAliasFilePath to (choose file with prompt strPromptText default location (aliasDefaultLocation) of type listUTI with multiple selections allowed without showing package contents and invisibles) as list
  
  -->値をOpenに渡たす
open listAliasFilePath
end run

###### open
--> ドロップされたら
on open listAliasFilePath
  ##########################
  ##処理対象となるUTI
  set listUTI to {"public.mpeg-4", "public.mpeg-2-transport-stream", "com.apple.quicktime-movie", "public.movie"} as list
  set ocidUTIarray to (refMe's NSArray's arrayWithArray:(listUTI))
  ##処理対象のURLだけ格納するARRAY
  set ocidFilePathURLArray to (refMe's NSMutableArray's alloc()'s initWithCapacity:(0))
  #対象ファイルのみ収集
  repeat with itemAliasFilePath in listAliasFilePath
    ####まずはUNIXパスにして
    set strFilePath to (POSIX path of itemAliasFilePath) as text
    ####NSStringパスにします
    set ocidFilePath to (refMe's NSString's stringWithString:(strFilePath))
    ###NSURLにしたら
    set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath))
    ##対象ファイルか?getResourceValueを取得
    set listResourceValue to (ocidFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLContentTypeKey) |error|:(reference))
    set ocidContentType to (item 2 of listResourceValue)
    set ocidUTI to ocidContentType's identifier()
    set boolContain to (ocidUTIarray's containsObject:(ocidUTI)) as boolean
    ##対象ファイルのみ収集
    if boolContain is true then
(ocidFilePathURLArray's addObject:(ocidFilePathURL))
    end if
  end repeat
  
  ##########################
  #ソート
  set ocidDescriptor to refMe's NSSortDescriptor's sortDescriptorWithKey:("absoluteString") ascending:(yes) selector:("localizedStandardCompare:")
  set ocidDescriptorArray to refMe's NSArray's arrayWithObject:(ocidDescriptor)
  set ocidSortedArray to ocidFilePathURLArray's sortedArrayUsingDescriptors:(ocidDescriptorArray)
  
  ##########################
  #本処理
  repeat with itemFilePathURL in ocidSortedArray
    ####ファイル名を取得
    set ocidFileName to itemFilePathURL's lastPathComponent()
    -->(*NSPathStore2*)
    ####拡張子を取得
    set ocidFileExtension to itemFilePathURL's pathExtension()
    -->(*NSPathStore2*)
    ####ファイル名から拡張子を取っていわゆるベースファイル名を取得
    set ocidPrefixName to ocidFileName's stringByDeletingPathExtension
    ####コンテナディレクトリを取得
    set ocidContainerDirURL to ocidFilePathURL's URLByDeletingLastPathComponent()
    ####AVAssetに格納して
    set ocidReadAsset to (refMe's AVURLAsset's alloc()'s initWithURL:(itemFilePathURL) options:(missing value))
    ####AVAssetのビデオトラックを取り出します
    set ocidReadAssetArray to (ocidReadAsset's tracksWithMediaType:(refMe's AVMediaTypeVideo))
    set ocidTrack to (ocidReadAssetArray's objectAtIndex:(0))
    ###ビデオの縦横幅 Px
    set ocidBounds to ocidTrack's naturalSize()
    set numWidthPx to (ocidBounds's width) as integer
    set numHeightPx to (ocidBounds's height) as integer
    ####フレームレートFPS 小数点以下2位で切り捨て
    set ocidFrameRate to (ocidTrack's nominalFrameRate()) as text
    set ocidDecimalNumber to (refMe's NSDecimalNumber's decimalNumberWithString:(ocidFrameRate))
    set ocidFormatter to refMe's NSNumberFormatter's alloc()'s init()
(ocidFormatter's setMaximumFractionDigits:(2))
(ocidFormatter's setRoundingMode:(refMe's NSNumberFormatterRoundHalfDown))
    set ocidFrameRateStr to (ocidFormatter's stringFromNumber:(ocidDecimalNumber))
    set strFrameRate to ocidFrameRateStr as text
    ##ファイルの長さ
    set ocidReadAssetDuration to ocidReadAsset's duration()
    set numTimeValue to (item 1 of ocidReadAssetDuration) as integer
    set numTimeScall to (item 2 of ocidReadAssetDuration) as integer
    ##トラックの長さ
    # set ocidTimeRange to ocidTrack's timeRange()
    # set numTimeValue to (item 1 of (item 2 of ocidTimeRange)) as integer
    # set numTimeScall to (item 2 of (item 2 of ocidTimeRange)) as integer
    ##分数 と 秒数
    # set numSec to (numTimeValue / numTimeScall) as number
    set numMin to ((numTimeValue / numTimeScall) / 60) as integer
    ####追加名称
    # set strAddFileName to ("@" & numWidthPx & "x" & numHeightPx & "_" & strFrameRate & "fps") as text
    set strAddFileName to (strSeparateStr & numWidthPx & "x" & numHeightPx & "_" & strFrameRate & "fps" & numMin & "m") as text
    ####拡張子を加えて新しいファイル名
    set ocidSaveFileName to ((ocidPrefixName as text) & strAddFileName & "." & (ocidFileExtension as text)) as text
    ####コンテナディレクトリURLに新しいファイル名を加えて新しいURL
    set ocidSaveFilePathURL to (ocidContainerDirURL's URLByAppendingPathComponent:(ocidSaveFileName))
    set ocidSaveFilePath to ocidSaveFilePathURL's |path|()
    ####################同名のファイルの有無を確認
    set numRepeatTime to 1 as integer
    set boolFileExists to true as boolean
    set appFileManager to refMe's NSFileManager's defaultManager()
    repeat while boolFileExists = false
      ###ファイルパスに同名のファイルがあるか?
      set boolFileExists to (appFileManager's fileExistsAtPath:(ocidSaveFilePath) isDirectory:false) as boolean
      ###同名のファイルがある場合は数字をつける
      if boolFileExists is true then
        #####変更後のファイル名
        set strAddFileName to (strAddFileName & " " & numRepeatTime) as text
        set ocidSaveFileName to ((ocidPrefixName as text) & strAddFileName & "." & (ocidFileExtension as text)) as text
        set ocidSaveFilePathURL to (ocidContainerDirURL's URLByAppendingPathComponent:(ocidSaveFileName))
        set ocidSaveFilePath to ocidSaveFilePathURL's |path|()
      end if
      set numRepeatTime to (numRepeatTime + 1) as integer
    end repeat
    ###リネーム
    set listDone to (appFileManager's moveItemAtURL:(itemFilePathURL) toURL:(ocidSaveFilePathURL) |error|:(reference))
    if (item 1 of listDone) is false then
log "失敗しました"
    end if
  end repeat
end open



|

[AVMetadataItem]音楽ファイルのアーティスト名を取得する

#!/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 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
set objFileManager to refMe's NSFileManager's defaultManager()



set ocidUserDesktopPath to (objFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set aliasDefaultLocation to ocidUserDesktopPath as alias

tell application "Finder"
    ##    set aliasDefaultLocation to container of (path to me) as alias
end tell

set listChooseFileUTI to {"public.mp3", "com.apple.m4a-audio"}

set strPromptText to "音楽ファイルを選んでください" as text

set aliasFilePath to (choose file with prompt strPromptText default location (aliasDefaultLocation) of type listChooseFileUTI with invisibles and showing package contents without multiple selections allowed) as alias
-->alias

###パス
set strFilePath to POSIX path of aliasFilePath
set ocidFilePath to refNSString's stringWithString:strFilePath
set ocidFilePath to ocidFilePath's stringByExpandingTildeInPath()
set ocidFilePathURL to refNSURL's alloc()'s initFileURLWithPath:ocidFilePath isDirectory:false



log doGetArtistName(ocidFilePathURL) as text

return doGetArtistName(ocidFilePathURL) as text

###########################################
### アーティスト名を読み取るサブ
###########################################

to doGetArtistName(argURL)
    ###URLアセットを取得
    set ocidAVURLAsset to refMe's AVURLAsset's URLAssetWithURL:argURL options:(missing value)
    ###メタデータを取得
    set ocidCommonMetadata to ocidAVURLAsset's commonMetadata()
    ###AVMetadataCommonKeyArtistメタデータを取得
    set ocidTitleArray to refMe's AVMetadataItem's metadataItemsFromArray:ocidCommonMetadata withKey:(refMe's AVMetadataCommonKeyArtist) keySpace:(refMe's AVMetadataKeySpaceCommon)
    set ocidMetaArtist to ocidTitleArray's objectAtIndex:0
    set strMetaArtist to ocidMetaArtist's value() as text
    return (strMetaArtist)
end doGetArtistName


|

[AVFoundation]ビデオの書き出し

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
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
property refAVAssetExportSession : a reference to refMe's AVAssetExportSession
set objFileManager to refMe's NSFileManager's defaultManager()

###入力
set strRelativePath to ("~/Desktop/a.mov") as text
set ocidRelativePath to refNSString's stringWithString:strRelativePath
set ocidFullPath to ocidRelativePath's stringByStandardizingPath()
set ocidFullPathURL to refMe's NSURL's fileURLWithPath:ocidFullPath
###出力
set strRelativeDistPath to ("~/Desktop/Dist.mov") as text
set ocidRelativeDistPath to refNSString's stringWithString:strRelativeDistPath
set ocidFullDistPath to ocidRelativeDistPath's stringByStandardizingPath()
set ocidFullDistPathURL to refMe's NSURL's fileURLWithPath:ocidFullDistPath
###書き出し中間ファイルの書き出し先
set strTmpPath to ("/private/tmp/AVAssetExportSession") as text
set ocidTmpPath to refNSString's stringWithString:strTmpPath
set ocidFullTmpPath to ocidTmpPath's stringByStandardizingPath()
set ocidFullTmpPathURL to refMe's NSURL's fileURLWithPath:ocidFullTmpPath
####TMPフォルダを作成
objFileManager's createDirectoryAtURL:ocidFullTmpPathURL withIntermediateDirectories:true attributes:(missing value) |error|:(missing value)


log "######AVAsset"
set ocidReadAsset to refAVAsset's assetWithURL:ocidFullPathURL
log className() of ocidReadAsset as text

set ocidReadAssetDuration to ocidReadAsset's duration()
log ocidReadAssetDuration
log "######AVAssetTrack"
set ocidReadAssetTrackArray to ocidReadAsset's tracks()
set numCntTrackNo to (count of ocidReadAssetTrackArray) as integer
log "トラック数は: " & numCntTrackNo
set numCntTrak to numCntTrackNo - 1
repeat numCntTrackNo times
log "--------"
set ocidTrack to (ocidReadAssetTrackArray's objectAtIndex:numCntTrak)
log className() of ocidTrack as text
set strTrackID to ocidTrack's trackID() as text
set strMediaType to ocidTrack'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 (ocidTrack's formatDescriptions()'s objectAtIndex:0)
-->NSCFType
log ocidTrack's isPlayable()
log ocidTrack's isDecodable()
log ocidTrack's isEnabled()
log ocidTrack's isSelfContained()
log ocidTrack's totalSampleDataLength()
##log ocidTrack's hasMediaCharacteristic()
log "->"
set ocidAssetTrackTimeRange to ocidTrack's timeRange()
log ocidAssetTrackTimeRange
set ocidAssetTrackTimeScale to ocidTrack's naturalTimeScale()
log ocidAssetTrackTimeScale
set ocidAssetTrackNaturalSize to ocidTrack's naturalSize()
log ocidAssetTrackNaturalSize
set ocidCMTimeFrameDura to ocidTrack's minFrameDuration()
log ocidCMTimeFrameDura as record
log "-->"
log ocidTrack's nominalFrameRate() as number

log ocidTrack's requiresFrameReordering() as boolean
log ocidTrack's metadata() as list
log ocidTrack's commonMetadata() as list
log ocidTrack's availableMetadataFormats() as list
log ocidTrack's segments() as list
log ocidTrack's availableTrackAssociationTypes() as list
log "--->"
log ocidTrack's preferredTransform()
log ocidTrack's preferredVolume()
log ocidTrack's estimatedDataRate()
log ocidTrack's languageCode() as text
log ocidTrack's extendedLanguageTag()
log ocidTrack's hasAudioSampleDependencies()
set numCntTrak to numCntTrak - 1

end repeat


set ocidExportPreset to refMe's AVAssetExportPreset1920x1080
(*
AVAssetExportPresetLowQuality
AVAssetExportPresetMediumQuality
AVAssetExportPresetHighestQuality
AVAssetExportPresetHEVCHighestQuality
AVAssetExportPresetHEVCHighestQualityWithAlpha

AVAssetExportPreset640x480
AVAssetExportPreset960x540
AVAssetExportPreset1280x720
AVAssetExportPreset1920x1080
AVAssetExportPreset3840x2160

AVAssetExportPresetHEVC1920x1080
AVAssetExportPresetHEVC3840x2160
AVAssetExportPresetHEVC1920x1080WithAlpha
AVAssetExportPresetHEVC3840x2160WithAlpha
AVAssetExportPresetHEVC7680x4320

AVAssetExportPresetAppleM4V480pSD
AVAssetExportPresetAppleM4V720pHD
AVAssetExportPresetAppleM4V1080pHD
AVAssetExportPresetAppleM4ViPod
AVAssetExportPresetAppleM4VAppleTV
AVAssetExportPresetAppleM4VCellular
AVAssetExportPresetAppleM4VWiFi

AVAssetExportPresetAppleProRes422LPCM
AVAssetExportPresetAppleProRes4444LPCM

AVAssetExportPresetPassthrough
AVAssetExportPresetAppleM4A
*)

set ocidExSession to refAVAssetExportSession's alloc()'s initWithAsset:ocidReadAsset presetName:ocidExportPreset

ocidExSession's setOutputURL:ocidFullDistPathURL
ocidExSession's setOutputFileType:(refMe's AVFileTypeQuickTimeMovie)
ocidExSession's setTimeRange:ocidAssetTrackTimeRange
#ocidExSession's setFileLengthLimit:(missing value)
ocidExSession's setShouldOptimizeForNetworkUse:false
ocidExSession's setCanPerformMultiplePassesOverSourceMediaData:true
ocidExSession's setDirectoryForTemporaryFiles:ocidFullTmpPathURL
ocidExSession's exportAsynchronouslyWithCompletionHandler:(missing value)
(*
AVFileTypeAC3
AVFileTypeAIFC
AVFileTypeAIFF
AVFileTypeAMR
AVFileTypeAppleiTT
AVFileTypeSunAU
AVFileTypeAVCI
AVFileTypeCoreAudioFormat
AVFileTypeDNG
AVFileTypeEnhancedAC3
AVFileTypeHEIC
AVFileTypeHEIF
AVFileTypeJPEG
AVFileTypeAppleM4A
AVFileTypeAppleM4V
AVFileType3GPP
AVFileType3GPP2
AVFileTypeQuickTimeMovie
AVFileTypeMPEGLayer3
AVFileTypeMPEG4
AVFileTypeSCC
AVFileTypeTIFF
AVFileTypeWAVE
*)
log "########################################"
set numStatusNo to ocidExSession's status()
log "status:\t" & numStatusNo
(*
AVAssetExportSessionStatusUnknown:0
AVAssetExportSessionStatusWaiting:1
AVAssetExportSessionStatusExporting:2
AVAssetExportSessionStatusCompleted:3
AVAssetExportSessionStatusFailed:4
AVAssetExportSessionStatusCancelled:5
*)
set progress total steps to 1
set progress completed steps to 0
set progress description to "書出"

repeat
set numProgress to ocidExSession's progress()
set numProgressPer to numProgress * 100 as integer
set progress additional description to "状況:" & numProgressPer & "%"
set progress completed steps to numProgress
set numStatusNo to ocidExSession's status()
if numStatusNo > 2 then
exit repeat
end if
delay 1
end repeat
log "status:\t" & numStatusNo


ocidReadAsset's release()
objFileManager's release()
ocidExSession's release()

|

[AVURLAsset]ビデオファイルのリネーム(fps入り)

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions



property objMe : a reference to current application
property objNSString : a reference to objMe's NSString
property objNSURL : a reference to objMe's NSURL
property objNSArray : a reference to objMe's NSArray
property objAVURLAsset : a reference to objMe's AVURLAsset
property objAVMediaTypeVideo : a reference to objMe's AVMediaTypeVideo

property objNSNotFound : a reference to 9.22337203685477E+18 + 5807


property listUTI : {"com.apple.quicktime-movie", "public.mpeg-4", "public.mpeg-2-transport-stream"}



on run
######ログ表示
doLogView()
###選択ダイアログのデフォルトパス
tell application "Finder"
set aliasDefaultLocation to (path to desktop folder from user domain) as alias
log aliasDefaultLocation as alias
end tell
###複数選択可能なダイアログを出す--> 戻り値はリストで格納されます
set listChooseFile to (choose file with prompt "ムービーファイルを選んでください" default location aliasDefaultLocation of type listUTI with invisibles and multiple selections allowed without showing package contents) as list
log listChooseFile as list
open listChooseFile
end run


on open listChooseFile

log "DDD" & listChooseFile
###listChooseFileに入ってるエリアス分だけ繰り返す
repeat with objFile in listChooseFile
############まずは、ファイルパス関連を取得
###UNIXパス
set strFilePath to POSIX path of objFile as text
####ファイルエイリアス
set aliasFilePath to objFile as alias
####ファイルのコンテナ(ファイルのあるディレクトリ)のエイリアス
tell application "Finder"
set aliasContainerDirPath to container of aliasFilePath as alias
end tell
###ファイルのあるコンテナのユニックスパス
set strContainerDirPath to POSIX path of aliasContainerDirPath as text

############ファイル名と拡張子
tell application "Finder"
####ファイルINFOを取得
set objInfo to info for objFile
####ファイル名
set strFileName to name of objInfo as text
####拡張子名
set strExtension to name extension of objInfo as text
end tell
#####ファイル名から拡張子を取り除く(UNIXBasename)
set AppleScript's text item delimiters to "."
set listFileName to every text item of strFileName
set AppleScript's text item delimiters to ""
set numCntDot to (count of listFileName) as number
set strShortFileName to (item 1 of listFileName) as text

############確認用にログ出します
log "###Input"
log "Alias: " & aliasFilePath as text
log "POSIX: " & strFilePath as text
log "alias Container" & aliasContainerDirPath as text
log "POSIX Container" & strContainerDirPath as text
log "FileName: " & strFileName as text
log "Extension: " & strExtension as text
log "ShortFileName: " & strShortFileName as text
####################
##NSURL
set ocidNSURL to (objNSURL's fileURLWithPath:strFilePath)
log className() of ocidNSURL as text

####AVURLAsset取得
set ocidAVURLAsset to (objMe's AVURLAsset's alloc()'s initWithURL:ocidNSURL options:(missing value))
log className() of ocidAVURLAsset as text

####AVURLAssetのビデオ部分を取得
set ocidVideoAssetTrack to (ocidAVURLAsset's tracksWithMediaType:(objMe's AVMediaTypeVideo))
log className() of ocidVideoAssetTrack as text

####取得したビデオトラック(Arrayで入るので)の最初のトラック
set ocidAsset to (ocidVideoAssetTrack's objectAtIndex:0)
log ocidAsset as list
log className() of ocidAsset as text

####サイズ
set ocidBounds to ocidAsset's naturalSize()
log ocidBounds as record
log class of ocidBounds as text

set numDimensionsW to width of ocidBounds as integer
set numDimensionsH to height of ocidBounds as integer
set strDimensionsW to numDimensionsW as text
set strDimensionsH to numDimensionsH as text

####フレームレートFPS
set ocidFrameRate to ocidAsset's nominalFrameRate()
log ocidFrameRate as real
log class of ocidFrameRate as text

####整数にしてテキスト化
##set strFPS to (ocidFrameRate as integer) as text
set strFPS to ocidFrameRate as text
log strFPS

set ocidMinFrameDuration to ocidAsset's minFrameDuration()
log ocidMinFrameDuration as record
log class of ocidMinFrameDuration as text

set ocidRequiresFrameReordering to ocidAsset's requiresFrameReordering()
log ocidRequiresFrameReordering as boolean
log class of ocidRequiresFrameReordering as text


set ocidFrameDuration to ocidAsset's minFrameDuration()
log ocidFrameDuration
log class of ocidFrameDuration as text

set boolFrameReordering to ocidAsset's requiresFrameReordering()
log boolFrameReordering
log class of boolFrameReordering as text


set ocidFormatDescriptions to ocidAsset's formatDescriptions()
log (ocidFormatDescriptions's objectAtIndex:0)
log className() of ocidFormatDescriptions as text


set boolIsPlayable to ocidAsset's isPlayable()
log boolIsPlayable
log class of boolIsPlayable

###注意戻り値がNSCFBoolean
set boolIsDecodable to ocidAsset's isDecodable
log boolIsDecodable as boolean
log className() of boolIsDecodable as text

set boolIsEnabled to ocidAsset's isEnabled()
log boolIsEnabled
log class of boolIsEnabled

set boolSelfContained to ocidAsset's isSelfContained()
log boolSelfContained
log class of boolSelfContained


set ocidTotalSampleDataLength to ocidAsset's totalSampleDataLength()
log ocidTotalSampleDataLength
log class of ocidTotalSampleDataLength


###戻り値 NSArray
set ocidMediaCharacteristics to ocidAsset's mediaCharacteristics()
log ocidMediaCharacteristics as list
log className() of ocidMediaCharacteristics as text

###Rangeと言いながら戻り値LIST
set ocidTimeRange to ocidAsset's timeRange()
log ocidTimeRange as list
log class of ocidTimeRange as text


set ocidNaturalTimeScale to ocidAsset's naturalTimeScale()
log ocidNaturalTimeScale as integer
log class of ocidNaturalTimeScale as text


set ocidEstimatedDataRate to ocidAsset's estimatedDataRate()
log ocidEstimatedDataRate as real
log class of ocidEstimatedDataRate as text


set ocidLanguageCode to ocidAsset's languageCode()
log ocidLanguageCode as text
log className() of ocidLanguageCode as text

set ocidExtendedLanguageTag to ocidAsset's extendedLanguageTag()
log ocidExtendedLanguageTag as text
log class of ocidExtendedLanguageTag as text

set ocidPreferredTransform to ocidAsset's preferredTransform()
log ocidPreferredTransform as list
log class of ocidPreferredTransform as text

set ocidPreferredVolume to ocidAsset's preferredVolume()
log ocidPreferredVolume as real
log class of ocidPreferredVolume as text


set ocidHasAudioSampleDependencies to ocidAsset's hasAudioSampleDependencies()
log ocidHasAudioSampleDependencies as boolean
log class of ocidHasAudioSampleDependencies as text
############
##戻り値NSArray
set ocidMetadata to ocidAsset's metadata()
log ocidMetadata as list
log className() of ocidMetadata as text
##戻り値NSArray
set ocidCommonMetadata to ocidAsset's commonMetadata()
log ocidCommonMetadata as list
log className() of ocidCommonMetadata as text
##戻り値NSArray
set ocidAvailableMetadataFormats to ocidAsset's availableMetadataFormats()
log ocidAvailableMetadataFormats as list
log className() of ocidAvailableMetadataFormats as text

##############
##戻り値NSArray
set ocidSegments to ocidAsset's segments()
log ocidSegments as list
log className() of ocidSegments as text

##############
##戻り値NSArray
set ocidSegments to ocidAsset's segments()
log ocidSegments as list
log className() of ocidSegments as text


set ocidAvailableTrackAssociationTypes to ocidAsset's availableTrackAssociationTypes()
log ocidAvailableTrackAssociationTypes as list
log className() of ocidAvailableTrackAssociationTypes as text

set ocidCanProvideSampleCursors to ocidAsset's canProvideSampleCursors()
log ocidCanProvideSampleCursors as boolean
log class of ocidCanProvideSampleCursors as text


return



log "###############"
###################小数点以下がある場合は2桁に整形
if strFPS contains "." then
####NSDecimalNumber
set ocidDecimalNumber to (objMe's NSDecimalNumber's decimalNumberWithString:strFPS)
log ocidDecimalNumber as text
log className() of ocidDecimalNumber as text

###NSNumberFormatterの初期化
set ocidNSNumberFormatter to objMe's NSNumberFormatter's alloc()'s init()
log ocidNSNumberFormatter
log className() of ocidNSNumberFormatter as text
###小数点以下2桁のフォーマット
(ocidNSNumberFormatter's setPositiveFormat:"##0.00")
####フォーマットを適応
set ocidDecimalNumber to (ocidNSNumberFormatter's stringFromNumber:ocidDecimalNumber)
log ocidDecimalNumber as text
log className() of ocidDecimalNumber as text
set strFPS to ocidDecimalNumber as text
end if
###################

#####変更後のファイル名
set strNewFileName to (strShortFileName & "." & strDimensionsW & "x" & strDimensionsH & "." & strFPS & "fps.mov") as text
#####変更後のファイルパス
set strNewFilePath to (strContainerDirPath & strNewFileName) as text
log "###OutPut"
log "AliasOutPutDir: " & aliasContainerDirPath
log "NewFileName: " & strNewFileName
log "NewFilePath: " & strNewFilePath

####################同名のファイルの有無を確認
#####NSFileManager定義
set objFileManager to objMe's NSFileManager's defaultManager()
#####保存先のdファイルパス
set ocidDistFilePath to (objNSString's stringWithString:strNewFilePath)
###ファイルパスに同名のファイルがあるか?
set boolFileExists to (objFileManager's fileExistsAtPath:ocidDistFilePath isDirectory:false)
log boolFileExists
###同名のファイルがある場合は1をつける
if boolFileExists is true then
#####変更後のファイル名
set strNewFileName to (strShortFileName & "." & strDimensionsW & "x" & strDimensionsH & "." & strFPS & "fps.1.mov") as text
#####変更後のファイルパス
set strNewFilePath to (strContainerDirPath & strNewFileName) as text
####リネーム後のファイルパスをNSString
set ocidDistFilePath to (objNSString's stringWithString:strNewFilePath)
end if
####オリジナルのファイルパスをNSString
set ocidOrgFilePath to (objNSString's stringWithString:strFilePath)



end repeat




end open




#########################ログ表示
to doLogView()

tell application "System Events"
set listAppList to title of (every process where background only is false)
end tell
repeat with objAppList in listAppList
set strAppList to objAppList as text
if strAppList is "スクリプトエディタ" then
tell application "Script Editor"
if frontmost is true then
try
tell application "System Events" to click menu item "ログを表示" of menu "表示" of menu bar item "表示" of menu bar 1 of application process "Script Editor"
end try
end if
end tell
tell application "Script Editor"
tell application "System Events"
tell process "Script Editor"
tell window 1
tell splitter group 1
tell splitter group 1
tell group 1
tell checkbox "返された値"
set boolValue to value as boolean
end tell
if boolValue is false then
click checkbox "返された値"
end if
end tell
end tell
end tell
end tell
end tell
end tell
end tell
end if
end repeat

end doLogView
#########################

|

[AVURLAsset]ムービーファイルのリネーム 縦横FPS入り

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions



property objMe : a reference to current application
property objNSString : a reference to objMe's NSString
property objNSURL : a reference to objMe's NSURL
property objNSArray : a reference to objMe's NSArray
property objAVURLAsset : a reference to objMe's AVURLAsset
property objAVMediaTypeVideo : a reference to objMe's AVMediaTypeVideo

property objNSNotFound : a reference to 9.22337203685477E+18 + 5807


property listUTI : {"com.apple.quicktime-movie", "public.mpeg-4", "public.mpeg-2-transport-stream"}



on run
######ログ表示
doLogView()
###選択ダイアログのデフォルトパス
tell application "Finder"
set aliasDefaultLocation to (path to desktop folder from user domain) as alias
log aliasDefaultLocation as alias
end tell
###複数選択可能なダイアログを出す--> 戻り値はリストで格納されます
set listChooseFile to (choose file with prompt "ムービーファイルを選んでください" default location aliasDefaultLocation of type listUTI with invisibles and multiple selections allowed without showing package contents) as list
log listChooseFile as list
open listChooseFile
end run


on open listChooseFile

log "DDD" & listChooseFile
###listChooseFileに入ってるエリアス分だけ繰り返す
repeat with objFile in listChooseFile
############まずは、ファイルパス関連を取得
###UNIXパス
set strFilePath to POSIX path of objFile as text
####ファイルエイリアス
set aliasFilePath to objFile as alias
####ファイルのコンテナ(ファイルのあるディレクトリ)のエイリアス
tell application "Finder"
set aliasContainerDirPath to container of aliasFilePath as alias
end tell
###ファイルのあるコンテナのユニックスパス
set strContainerDirPath to POSIX path of aliasContainerDirPath as text

############ファイル名と拡張子
tell application "Finder"
####ファイルINFOを取得
set objInfo to info for objFile
####ファイル名
set strFileName to name of objInfo as text
####拡張子名
set strExtension to name extension of objInfo as text
end tell
#####ファイル名から拡張子を取り除く(UNIXBasename)
set AppleScript's text item delimiters to "."
set listFileName to every text item of strFileName
set AppleScript's text item delimiters to ""
set numCntDot to (count of listFileName) as number
set strShortFileName to (item 1 of listFileName) as text

############確認用にログ出します
log "###Input"
log "Alias: " & aliasFilePath as text
log "POSIX: " & strFilePath as text
log "alias Container" & aliasContainerDirPath as text
log "POSIX Container" & strContainerDirPath as text
log "FileName: " & strFileName as text
log "Extension: " & strExtension as text
log "ShortFileName: " & strShortFileName as text
####################
##NSURL
set ocidNSURL to (objNSURL's fileURLWithPath:strFilePath)
log className() of ocidNSURL as text

####AVURLAsset取得
set ocidAVURLAsset to (objMe's AVURLAsset's alloc()'s initWithURL:ocidNSURL options:(missing value))
log className() of ocidAVURLAsset as text

####AVURLAssetのビデオ部分を取得
set ocidVideoAssetTrack to (ocidAVURLAsset's tracksWithMediaType:(objMe's AVMediaTypeVideo))
log className() of ocidVideoAssetTrack as text

####取得したビデオトラック(Arrayで入るので)の最初のトラック
set ocidAsset to (ocidVideoAssetTrack's objectAtIndex:0)
log ocidAsset as list
log className() of ocidAsset as text

####サイズ
set ocidBounds to ocidAsset's naturalSize()
log ocidBounds as record
log class of ocidBounds as text

set numDimensionsW to width of ocidBounds as integer
set numDimensionsH to height of ocidBounds as integer
set strDimensionsW to numDimensionsW as text
set strDimensionsH to numDimensionsH as text

####フレームレートFPS
set ocidFrameRate to ocidAsset's nominalFrameRate()
log ocidFrameRate as real
log class of ocidFrameRate as text

####整数にしてテキスト化
##set strFPS to (ocidFrameRate as integer) as text
set strFPS to ocidFrameRate as text
log strFPS

###################小数点以下がある場合は2桁に整形
if strFPS contains "." then
####NSDecimalNumber
set ocidDecimalNumber to (objMe's NSDecimalNumber's decimalNumberWithString:strFPS)
log ocidDecimalNumber as text
log className() of ocidDecimalNumber as text

###NSNumberFormatterの初期化
set ocidNSNumberFormatter to objMe's NSNumberFormatter's alloc()'s init()
log ocidNSNumberFormatter
log className() of ocidNSNumberFormatter as text
###小数点以下2桁のフォーマット
(ocidNSNumberFormatter's setPositiveFormat:"##0.00")
####フォーマットを適応
set ocidDecimalNumber to (ocidNSNumberFormatter's stringFromNumber:ocidDecimalNumber)
log ocidDecimalNumber as text
log className() of ocidDecimalNumber as text
set strFPS to ocidDecimalNumber as text
end if
###################

#####変更後のファイル名
set strNewFileName to (strShortFileName & "." & strDimensionsW & "x" & strDimensionsH & "." & strFPS & "fps.mov") as text
#####変更後のファイルパス
set strNewFilePath to (strContainerDirPath & strNewFileName) as text
log "###OutPut"
log "AliasOutPutDir: " & aliasContainerDirPath
log "NewFileName: " & strNewFileName
log "NewFilePath: " & strNewFilePath

####################同名のファイルの有無を確認
#####NSFileManager定義
set objFileManager to objMe's NSFileManager's defaultManager()
#####保存先のdファイルパス
set ocidDistFilePath to (objNSString's stringWithString:strNewFilePath)
###ファイルパスに同名のファイルがあるか?
set boolFileExists to (objFileManager's fileExistsAtPath:ocidDistFilePath isDirectory:false)
log boolFileExists
###同名のファイルがある場合は1をつける
if boolFileExists is true then
#####変更後のファイル名
set strNewFileName to (strShortFileName & "." & strDimensionsW & "x" & strDimensionsH & "." & strFPS & "fps.1.mov") as text
#####変更後のファイルパス
set strNewFilePath to (strContainerDirPath & strNewFileName) as text
####リネーム後のファイルパスをNSString
set ocidDistFilePath to (objNSString's stringWithString:strNewFilePath)
end if
####オリジナルのファイルパスをNSString
set ocidOrgFilePath to (objNSString's stringWithString:strFilePath)

###リネーム
set boolMoveFileAndRename to (objFileManager's moveItemAtPath:ocidOrgFilePath toPath:ocidDistFilePath |error|:(missing value))

if boolMoveFileAndRename is false then
log "失敗しました"
end if

end repeat




end open




#########################ログ表示
to doLogView()

tell application "System Events"
set listAppList to title of (every process where background only is false)
end tell
repeat with objAppList in listAppList
set strAppList to objAppList as text
if strAppList is "スクリプトエディタ" then
tell application "Script Editor"
if frontmost is true then
try
tell application "System Events" to click menu item "ログを表示" of menu "表示" of menu bar item "表示" of menu bar 1 of application process "Script Editor"
end try
end if
end tell
tell application "Script Editor"
tell application "System Events"
tell process "Script Editor"
tell window 1
tell splitter group 1
tell splitter group 1
tell group 1
tell checkbox "返された値"
set boolValue to value as boolean
end tell
if boolValue is false then
click checkbox "返された値"
end if
end tell
end tell
end tell
end tell
end tell
end tell
end tell
end if
end repeat

end doLogView
#########################

|

[AVURLAsset] naturalSize ビデオの縦横pxサイズを取得する

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

######ログ表示
doLogView()

property objMe : a reference to current application
property objNSString : a reference to objMe's NSString
property objNSMutableString : a reference to objMe's NSMutableString
property objNSURL : a reference to objMe's NSURL


###ムービーファイルのUNIXパス
set strFilePath to "/Applications/Keynote.app/Contents/Resources/PlaceholderMovie.mov"

##NSURL
set ocidNSURL to objNSURL's fileURLWithPath:strFilePath
log className() of ocidNSURL as text

####AVURLAsset取得
set ocidAVURLAsset to objMe's AVURLAsset's alloc()'s initWithURL:ocidNSURL options:(missing value)
log className() of ocidAVURLAsset as text

####AVURLAssetのビデオ部分を取得
set ocidVideoAssetTrack to (ocidAVURLAsset's tracksWithMediaType:(objMe's AVMediaTypeVideo))
log className() of ocidVideoAssetTrack as text

####取得したビデオトラック(Arrayで入るので)の最初のトラック
set ocidAsset to ocidVideoAssetTrack's objectAtIndex:0
log ocidAsset as list
log className() of ocidAsset as text


####フレームレートFPS
set ocidFrameRate to ocidAsset's nominalFrameRate()
log ocidFrameRate as real
log class of ocidFrameRate as text


####縦横サイズ
set recordBounds to ocidAsset's naturalSize()
log recordBounds as record
log class of recordBounds as text

set numDimensionsW to width of recordBounds as integer
set numDimensionsH to height of recordBounds as integer
set strDimensionsW to numDimensionsW as text
set strDimensionsH to numDimensionsH as text
log "width: " & strDimensionsW
log "height: " & strDimensionsH







#########################ログ表示
to doLogView()

tell application "System Events"
set listAppList to title of (every process where background only is false)
end tell
repeat with objAppList in listAppList
set strAppList to objAppList as text
if strAppList is "スクリプトエディタ" then
tell application "Script Editor"
if frontmost is true then
try
tell application "System Events" to click menu item "ログを表示" of menu "表示" of menu bar item "表示" of menu bar 1 of application process "Script Editor"
end try
end if
end tell
tell application "Script Editor"
tell application "System Events"
tell process "Script Editor"
tell window 1
tell splitter group 1
tell splitter group 1
tell group 1
tell checkbox "返された値"
set boolValue to value as boolean
end tell
if boolValue is false then
click checkbox "返された値"
end if
end tell
end tell
end tell
end tell
end tell
end tell
end tell
end if
end repeat

end doLogView
#########################

|

[AVURLAsset] nominalFrameRate FPS フレームレートを取得する

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

######ログ表示
doLogView()

property objMe : a reference to current application
property objNSString : a reference to objMe's NSString
property objNSMutableString : a reference to objMe's NSMutableString
property objNSURL : a reference to objMe's NSURL


###ムービーファイルのUNIXパス
set strFilePath to "/Applications/Keynote.app/Contents/Resources/PlaceholderMovie.mov"

##NSURL
set ocidNSURL to objNSURL's fileURLWithPath:strFilePath
log className() of ocidNSURL as text

####AVURLAsset取得
set ocidAVURLAsset to objMe's AVURLAsset's alloc()'s initWithURL:ocidNSURL options:(missing value)
log className() of ocidAVURLAsset as text

####AVURLAssetのビデオ部分を取得
set ocidVideoAssetTrack to (ocidAVURLAsset's tracksWithMediaType:(objMe's AVMediaTypeVideo))
log className() of ocidVideoAssetTrack as text

####取得したビデオトラック(Arrayで入るので)の最初のトラック
set ocidAsset to ocidVideoAssetTrack's objectAtIndex:0
log ocidAsset as list
log className() of ocidAsset as text

####フレームレートFPS
set ocidFrameRate to ocidAsset's nominalFrameRate()
log ocidFrameRate as real
log class of ocidFrameRate as text






#########################ログ表示
to doLogView()

tell application "System Events"
set listAppList to title of (every process where background only is false)
end tell
repeat with objAppList in listAppList
set strAppList to objAppList as text
if strAppList is "スクリプトエディタ" then
tell application "Script Editor"
if frontmost is true then
try
tell application "System Events" to click menu item "ログを表示" of menu "表示" of menu bar item "表示" of menu bar 1 of application process "Script Editor"
end try
end if
end tell
tell application "Script Editor"
tell application "System Events"
tell process "Script Editor"
tell window 1
tell splitter group 1
tell splitter group 1
tell group 1
tell checkbox "返された値"
set boolValue to value as boolean
end tell
if boolValue is false then
click checkbox "返された値"
end if
end tell
end tell
end tell
end tell
end tell
end tell
end tell
end if
end repeat

end doLogView
#########################

|

その他のカテゴリー

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