Reputation: 913
So I have a video that I want to know the length, the resolution and the framerate of. Using methods like:
tell application "System Events" to return info for "/path/to/my/video"
doesn't return either of those three. I'm aware that all of these can be found using FFMPEG, but if possible, I want to avoid that.
Upvotes: 2
Views: 889
Reputation: 7555
I like using ExifTool over Spotlight (mdls
) because I keep a lot of items on volumes that are not indexed, and ExifTool reads the meta-data directly from the file.
In Terminal, e.g.:
% exiftool -Duration -ImageSize -VideoFrameRate '/path/to/video.mkv'
Duration : 0:48:49
Image Size : 712x480
Video Frame Rate : 29.97
%
Using AppleScript, here is an example using the -T
option.
set foo to do shell script "/usr/local/bin/exiftool -T -Duration -ImageSize -VideoFrameRate '/path/to/video.mkv'"
set AppleScript's text item delimiters to tab
set duration to first text item of foo
set resolution to second text item of foo
set frameRate to third text item of foo
set AppleScript's text item delimiters to ""
log duration
log resolution
log frameRate
Output in the Messages tab of the Log pane of Script Editor:
(*0:48:49*)
(*712x480*)
(*29.97*)
The actual value of the variable does not contain (*
and *)
, as that is just how it get logged.
Notes:
There are may options that can be invoked, so you'll need to read its manual page.
The web site itself has a wealth of information too.
mdls
For macOS native mdls
in Terminal:
% mdls -name kMDItemDurationSeconds -name kMDItemPixelHeight -name kMDItemPixelWidth -name kMDItemVideoBitRate '/path/to/video.mp4'
kMDItemDurationSeconds = 2650.582
kMDItemPixelHeight = 406
kMDItemPixelWidth = 720
kMDItemVideoBitRate = 891
%
You could use the do shell script
command in AppleScript to glean the info and then parse is to fit your needs.
Example AppleScript code:
set foo to paragraphs of (do shell script "mdls -name kMDItemDurationSeconds -name kMDItemPixelHeight -name kMDItemPixelWidth -name kMDItemVideoBitRate /path/to/video.mp4")
set AppleScript's text item delimiters to "= "
set duration to second text item of first item of foo
set resHeight to second text item of second item of foo
set resWidth to second text item of third item of foo
set bitRate to second text item of fourth item of foo
set AppleScript's text item delimiters to ""
set resolution to resWidth & "x" & resHeight
log duration
log resolution
log bitRate
Output in the Messages tab of the Log pane of Script Editor:
(*2650.582*)
(*720x406*)
(*891*)
The actual value of the variable does not contain (*
and *)
, as that is just how it get logged.
Notes:
You may find that even on indexed volumes some information will not be available to mdls
where it may/will be with ExifTool.
I did not see anything in the files I tested with mdls
that said frame rate, so I added kMDItemVideoBitRate
to the example shell script command.
Upvotes: 4