有没有办法使用 AppleScript 获取有关视频的信息?

Is there a way to get info about a video using AppleScript?

所以我有一个视频,我想知道它的长度、分辨率和帧率。使用如下方法:

tell application "System Events" to return info for "/path/to/my/video"

return 这三个都不是。我知道所有这些都可以使用 FFMPEG 找到,但如果可能的话,我想避免这种情况。

使用 ExifTool

我喜欢使用 ExifTool 而不是 Spotlight (mdls) 因为我在 卷 [=111= 上保留了很多项目] 没有索引,并且 ExifTool 直接从 文件 .[= 读取 元数据 29=]

终端,例如:

% exiftool -Duration -ImageSize -VideoFrameRate '/path/to/video.mkv'  
Duration                        : 0:48:49
Image Size                      : 712x480
Video Frame Rate                : 29.97
% 

使用 AppleScript,这是一个使用 -T 选项 示例 .

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

消息 选项卡 日志 窗格中输出 脚本编辑器:

(*0:48:49*)
(*712x480*)
(*29.97*)

变量的实际不包含(**) ,因为这就是它的记录方式。

备注:

可能有选项可以调用,因此您需要阅读它的手册页

网站本身也有丰富的信息。



使用mdls

对于 macOS 本机 mdlsTerminal:

% mdls -name kMDItemDurationSeconds -name kMDItemPixelHeight -name kMDItemPixelWidth -name kMDItemVideoBitRate '/path/to/video.mp4'
kMDItemDurationSeconds = 2650.582
kMDItemPixelHeight     = 406
kMDItemPixelWidth      = 720
kMDItemVideoBitRate    = 891
% 

您可以使用 AppleScript 中的 do shell script 命令 来收集信息,然后解析以满足您的需要。

示例 AppleScript 代码:

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

消息 选项卡 日志 窗格中输出 脚本编辑器:

(*2650.582*)
(*720x406*)
(*891*)

变量的实际不包含(**) ,因为这就是它的记录方式。

备注:

您可能会发现,即使在索引 上,某些信息也无法用于 mdls,其中 may/will 使用 ExifTool .

我在 文件 中没有看到任何内容,我用 mdls 测试过 帧速率 ,所以我添加了 kMDItemVideoBitRate 示例 shell 脚本 命令 .