Hello and thanks for your time, I am creating a开发者_运维技巧n 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.
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;
}
精彩评论