-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimecodereader.m
More file actions
168 lines (129 loc) · 3.97 KB
/
Copy pathtimecodereader.m
File metadata and controls
168 lines (129 loc) · 3.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#import <Foundation/Foundation.h>
#import <QTKit/QTKit.h>
#import <AppKit/AppKit.h>
#import "NSString+Additions.h"
//------- @interface section -------
@interface QuicktimeController: NSObject
{
QTMovie *movie;
}
- (id)init;
- (BOOL)isQT:(NSString *)path;
-(void)dealloc;
@end
//------- @implementation section -------
@implementation QuicktimeController
- (id)init
{
self = [super init];
return self;
}
-(BOOL)setMovie:(NSString *)file
{
//NSURL *fileURL = [NSURL fileURLWithPath: file];
//NSLog(@"%@ url", fileURL);
if(movie){
[movie release];
}
if([QTMovie canInitWithFile:file]){
movie = [[QTMovie alloc] initWithFile:file error:NULL];
return TRUE;
}else{
return FALSE;
}
}
-(NSString *)getTimecodeInfo
{
NSString *result = @"<Unknown timecode>";
NSArray *tracks = [movie tracksOfMediaType:QTMediaTypeTimeCode];
if ([tracks count] > 0) {
QTMedia *media = [[tracks objectAtIndex:0] media];
TimeCodeDescriptionHandle desc =
(TimeCodeDescriptionHandle)NewHandleClear(sizeof(TimeCodeDescriptionHandle));
if (desc) {
OSErr err = GetMoviesError();
if (err == noErr) {
TimeCodeDef myTCDef;
TimeCodeRecord myTCRec;
err = TCGetCurrentTimeCode(GetMediaHandler([media quickTimeMedia]), NULL, &myTCDef, &myTCRec, NULL);
if (err == noErr) {
Str255 myString;
err = TCTimeCodeToString(GetMediaHandler([media quickTimeMedia]), &myTCDef, &myTCRec, myString);
if (err == noErr)
result = (NSString *)CFStringCreateWithPascalString(kCFAllocatorDefault, myString, CFStringGetSystemEncoding());
}
}
DisposeHandle((Handle)desc);
}
}
// NSLog(@"%@", result);
return result;
}
- (BOOL)isQT:(NSString *)path
{
BOOL display = FALSE;
MDItemRef item = MDItemCreate(kCFAllocatorDefault, (CFStringRef)path);
if(item)
{
CFTypeRef ref = MDItemCopyAttribute(item, CFSTR("kMDItemContentType"));
if (ref) {
if (UTTypeConformsTo(ref, CFSTR("com.apple.quicktime-movie"))) display = TRUE;
CFRelease(ref);
}
}
if (item) CFRelease(item);
return display;
}
-(void)dealloc
{
[movie release];
[super dealloc];
}
@end
void usage(){
printf("usage: use timecodereader to read timecode from QuickTime files, timecodereader accepts a single path arguement.\n");
}
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
QuicktimeController *qt =[[QuicktimeController alloc] init];
if(argc == 2){
NSArray *mountPoints = [[NSWorkspace sharedWorkspace]
mountedLocalVolumePaths];
//NSLog(@"mountPoints: %@", mountPoints);
NSString *path = [NSString stringWithUTF8String:argv[1]];
NSString *fullPath = [path stringByExpandingTildeInPath];
id mount;
NSEnumerator* myIterator = [mountPoints objectEnumerator];
while(mount = [myIterator nextObject])
{
NSArray *theComponents = [fullPath pathComponents];
NSString *firstPath = [theComponents objectAtIndex:1];
//NSLog(@"mount %@", mount);
//NSLog(@"firstPath: %@", firstPath);
if([mount containsString:firstPath] && ![firstPath isEqualToString:@"Volumes"])
{
NSString *appendedPath = [@"/Volumes" stringByAppendingPathComponent:fullPath];
fullPath = [NSString stringWithString: appendedPath];
break;
}
}
NSString *convertedPath = (NSString *)CFURLCreateStringByReplacingPercentEscapes(kCFAllocatorDefault, (CFStringRef)fullPath, (CFStringRef)@"");
if([qt isQT: convertedPath ])
{
BOOL isMovie = [qt setMovie: convertedPath ];
if(isMovie){
NSString *timecodeString = [qt getTimecodeInfo];
fprintf(stderr,"%s\n", [timecodeString fileSystemRepresentation]);
}else{
fprintf(stderr," unable to allocate memory for %s\n", [convertedPath fileSystemRepresentation]);
}
}else{
fprintf(stderr,"%s does not appear to be a QuickTime File.\n",[convertedPath fileSystemRepresentation]);
}
}else{
usage();
}
[pool release];
[qt release];
return 0;
}