如何在 Objective C/Cocoa 中获取 QuickTime 视频的编解码器信息? (没有 FFMPEG)

发布于 2024-11-23 15:39:11 字数 244 浏览 3 评论 0原文

您好,感谢您抽出时间, 我正在创建一个应用程序,可以移动视频文件以供其他应用程序处理。过去,我在 ruby​​ 中使用 mediainfo 和 ffmpeg 来获取每个文件的编解码器信息。然而,我想将所有这些转移到一个漂亮的可可应用程序中。我搜索了又搜索,但仍然找不到如何执行此操作的解决方案(不使用 ffmpeg)。我基本上正在寻找与您在 QuickTime 视频检查器窗口(Apple + i)中获得的完全相同的信息。 任何帮助将不胜感激,示例代码,更是如此。 谢谢。

Hello and thanks for your time,
I am creating an application that moves video files around to be processed by other applications. In the past, I have used mediainfo, and ffmpeg, in ruby to obtain codec information about each file. I would however like to transfer all of this into one beautiful cocoa app. I have searched and searched and still can't find a solution (without using ffmpeg) on how to do this. I am basically looking for the exact same info you get in the quicktime video inspector window (apple + i).
Any help would be greatly appreciated, sample code, even more so.
Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

您可以使用 Spotlight 查询 (NSMetadataQuery),如 mdls 命令:

> mdls ~/Music/iTunes/iTunes\ Media/iTunes\ U/WWDC\ 2011\ Session\ Videos\ -\ HD/1-01\ Apple\ Platforms\ Kickoff.m4v 
kMDItemAudioBitRate            = 103
kMDItemAudioChannelCount       = 2
kMDItemCodecs                  = (
    AAC,
    "H.264"
)
kMDItemContentCreationDate     = 2011-07-01 15:49:56 +0000
kMDItemContentModificationDate = 2011-07-01 16:13:39 +0000
kMDItemContentType             = "com.apple.m4v-video"
kMDItemContentTypeTree         = (
    "com.apple.m4v-video",
    "public.movie",
    "public.audiovisual-content",
    "public.data",
    "public.item",
    "public.content"
)
kMDItemDateAdded               = 2011-07-01 16:13:39 +0000
kMDItemDisplayName             = "1-01 Apple Platforms Kickoff.m4v"
kMDItemDurationSeconds         = 2787.754421087755
kMDItemFSContentChangeDate     = 2011-07-01 16:13:39 +0000
kMDItemFSCreationDate          = 2011-07-01 15:49:56 +0000
kMDItemFSCreatorCode           = "hook"
kMDItemFSFinderFlags           = 0
kMDItemFSHasCustomIcon         = 0
kMDItemFSInvisible             = 0
kMDItemFSIsExtensionHidden     = 0
kMDItemFSIsStationery          = 0
kMDItemFSLabel                 = 0
kMDItemFSName                  = "1-01 Apple Platforms Kickoff.m4v
kMDItemFSNodeCount             = 1147843844
kMDItemFSOwnerGroupID          = 20
kMDItemFSOwnerUserID           = 502
kMDItemFSSize                  = 1147843844
kMDItemFSTypeCode              = ""
kMDItemKind                    = "Video Media"
kMDItemLogicalSize             = 1147843844
kMDItemMediaTypes              = (
    Sound,
    Video
)
kMDItemPhysicalSize            = 1147846656
kMDItemPixelHeight             = 540
kMDItemPixelWidth              = 958
kMDItemProfileName             = "HD (1-1-1)"
kMDItemStreamable              = 0
kMDItemTotalBitRate            = 3287
kMDItemVideoBitRate            = 3184

或者您可以检查 AVFoundation 框架。

示例代码:

 -(NSDictionary *) metadataForFileAtPath:(NSString *) path {
    NSURL *url = [[[NSURL alloc] initFileURLWithPath:path] autorelease];

    MDItemRef itemRef = MDItemCreateWithURL(NULL, (CFURLRef)url);
    NSArray *attributeNames = (NSArray *)MDItemCopyAttributeNames(itemRef);
    NSDictionary *attributes = (NSDictionary *) MDItemCopyAttributes(itemRef, (CFArrayRef) attributeNames);
    CFRelease(itemRef);

    // probably it is leaking memory (attributeNames and attributes), better check with Instruments

    return attributes;
}

You can use Spotlight Queries (NSMetadataQuery), like the mdls command do :

> mdls ~/Music/iTunes/iTunes\ Media/iTunes\ U/WWDC\ 2011\ Session\ Videos\ -\ HD/1-01\ Apple\ Platforms\ Kickoff.m4v 
kMDItemAudioBitRate            = 103
kMDItemAudioChannelCount       = 2
kMDItemCodecs                  = (
    AAC,
    "H.264"
)
kMDItemContentCreationDate     = 2011-07-01 15:49:56 +0000
kMDItemContentModificationDate = 2011-07-01 16:13:39 +0000
kMDItemContentType             = "com.apple.m4v-video"
kMDItemContentTypeTree         = (
    "com.apple.m4v-video",
    "public.movie",
    "public.audiovisual-content",
    "public.data",
    "public.item",
    "public.content"
)
kMDItemDateAdded               = 2011-07-01 16:13:39 +0000
kMDItemDisplayName             = "1-01 Apple Platforms Kickoff.m4v"
kMDItemDurationSeconds         = 2787.754421087755
kMDItemFSContentChangeDate     = 2011-07-01 16:13:39 +0000
kMDItemFSCreationDate          = 2011-07-01 15:49:56 +0000
kMDItemFSCreatorCode           = "hook"
kMDItemFSFinderFlags           = 0
kMDItemFSHasCustomIcon         = 0
kMDItemFSInvisible             = 0
kMDItemFSIsExtensionHidden     = 0
kMDItemFSIsStationery          = 0
kMDItemFSLabel                 = 0
kMDItemFSName                  = "1-01 Apple Platforms Kickoff.m4v
kMDItemFSNodeCount             = 1147843844
kMDItemFSOwnerGroupID          = 20
kMDItemFSOwnerUserID           = 502
kMDItemFSSize                  = 1147843844
kMDItemFSTypeCode              = ""
kMDItemKind                    = "Video Media"
kMDItemLogicalSize             = 1147843844
kMDItemMediaTypes              = (
    Sound,
    Video
)
kMDItemPhysicalSize            = 1147846656
kMDItemPixelHeight             = 540
kMDItemPixelWidth              = 958
kMDItemProfileName             = "HD (1-1-1)"
kMDItemStreamable              = 0
kMDItemTotalBitRate            = 3287
kMDItemVideoBitRate            = 3184

Or you can check the AVFoundation framework.

Sample code:

 -(NSDictionary *) metadataForFileAtPath:(NSString *) path {
    NSURL *url = [[[NSURL alloc] initFileURLWithPath:path] autorelease];

    MDItemRef itemRef = MDItemCreateWithURL(NULL, (CFURLRef)url);
    NSArray *attributeNames = (NSArray *)MDItemCopyAttributeNames(itemRef);
    NSDictionary *attributes = (NSDictionary *) MDItemCopyAttributes(itemRef, (CFArrayRef) attributeNames);
    CFRelease(itemRef);

    // probably it is leaking memory (attributeNames and attributes), better check with Instruments

    return attributes;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文