-
Notifications
You must be signed in to change notification settings - Fork 3
/
wacaw.m
740 lines (614 loc) · 23.9 KB
/
wacaw.m
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
//
// wacaw.m
//
// Created by HXR on 3/7/06.
// Copyright (C) 2006 HXR ([email protected]).
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
//
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <string.h>
#include <assert.h>
#import <Foundation/Foundation.h>
#import <QuickTime/QuickTime.h>
#import <CoreServices/CoreServices.h>
#import <Carbon/Carbon.h>
#include "base64.h"
// Globals
#define FILENAME_BUFFER_SIZE 1024
const double BASE64_ENCODE_SIZE_FACTOR = (1.0/3.0+1.0);
static char * versionString = "version 0.40";
static int verboseFlag = 0;
static int videoFlag = 0;
static int noAudioFlag = 0;
static int toClipboardFlag= 0;
static int continuousFlag = 0;
static char * filename = NULL;
static int imageWidth = 640;
static int imageHeight = 480;
static int imageFormat = kQTFileTypeJPEG;
static int numberOfCaptures = 1;
static int delay = 0;
// QSIF as standard video size (reduces video size dramatically *g*)
static int videoWidth = 160;
static int videoHeight = 120;
static int videoFormat = kQTFileTypeAVI;
static int duration = 15;
static int filenameNecessary = 1;
static int listDevices = 0;
static int selectedVideoDevice = -1;
static int selectedVideoInput = -1;
// QT data reference
static Handle dataRef;
static OSType dataTypeRef;
// Information about options
static struct option longOptions[] =
{
// These options set a flag.
{"verbose", no_argument, &verboseFlag, 1},
{"brief", no_argument, &verboseFlag, 0},
{"jpeg", no_argument, &imageFormat, kQTFileTypeJPEG},
{"tiff", no_argument, &imageFormat, kQTFileTypeTIFF},
{"png", no_argument, &imageFormat, kQTFileTypePNG},
{"gif", no_argument, &imageFormat, kQTFileTypeGIF},
{"bmp", no_argument, &imageFormat, kQTFileTypeBMP},
{"pict", no_argument, &imageFormat, kQTFileTypePicture},
{"video", no_argument, &videoFlag, 1},
{"no-audio",no_argument, &noAudioFlag, 1},
{"to-clipboard",no_argument, &toClipboardFlag, 1},
{"continous",no_argument, &continuousFlag, 1},
// These options don't set a flag.
// We distinguish them by their indices.
{"help", no_argument, 0, 'h'},
{"usage", no_argument, 0, 'h'},
{"version", no_argument, 0, 'v'},
{"width", required_argument, 0, 'x'},
{"height", required_argument, 0, 'y'},
{"SQSIF", no_argument, 0, '1'},
{"QSIF", no_argument, 0, '2'},
{"QCIF", no_argument, 0, '3'},
{"SIF", no_argument, 0, '4'},
{"CIF", no_argument, 0, '5'},
{"VGA", no_argument, 0, '6'},
{"SVGA", no_argument, 0, '7'},
{"list-devices", no_argument, 0, 'L'},
{"video-device", required_argument, 0, 'd'},
{"video-input", required_argument, 0, 'i'},
{"num-frames", required_argument, 0, 'n'},
{"duration", required_argument, 0, 'D'},
{"delay", required_argument, 0, 't'},
{0, 0, 0, 0}
};
// Shouldn't usage just read from the longOptions?
static void usage(char * argv[])
{
printf("%s\n", versionString);
printf("Usage: %s [-h] [options] [filename]\n", argv[0]);
printf(" -h / --help : print this help message\n");
printf(" --usage : print this help message\n");
printf(" -v / --version : prints out version information\n");
printf(" --verbose : more messages about what is going on\n");
printf(" --brief : fewer messages about what is going on (default)\n");
printf(" --video : record a video\n");
printf(" --continous : keep saving frames\n");
printf(" -t / --delay : delay between captures (only used if continous is specified)\n");
printf(" --no-audio : do not record audio\n");
printf(" -D / --duration <#>: specify the duration of the video (default: 15 sec.)\n");
printf(" --to-clipboard: copy image just taken to clipboard\n");
printf(" --jpeg : save image in JPEG format (default)\n");
printf(" --tiff : save image in TIFF format\n");
printf(" --png : save image in PNG format\n");
printf(" --gif : save image in GIF format\n");
printf(" --bmp : save image in BMP format\n");
printf(" --pict : save image in PICT format\n");
printf(" -x / --width <#> : specify the width of the image / video \n");
printf(" -y / --height <#> : specify the height of the image / video \n");
printf(" --SVGA : the image / video should have 'SVGA' size (800x600)\n");
printf(" --VGA : the image / video should have 'VGA' size (640x480)\n");
printf(" --CIF : the image / video should have 'CIF' size (352x288)\n");
printf(" --SIF : the image / video should have 'SIF' size (320x240)\n");
printf(" --QCIF : the image / video should have 'QCIF' size (176x144)\n");
printf(" --QSIF : the image / video should have 'QSIF' size (160x120)\n");
printf(" --SQSIF : the image / video should have 'SQSIF' size (160x96)\n");
printf(" -L / --list-devices : list the devices available\n");
printf(" -d / --video-device <#> : specify which device should be used\n");
printf(" -i / --video-input <#> : specify which input should be used (must specify device)\n");
printf(" -n / --num-frames <#> : specify how many pictures to take before\n");
printf(" final image is captured (picture mode only)\n");
printf(" filename : needed unless only listing available devices (-L) or using help (-h)\n");
}
static char * getFiletypeExtension(int format)
{
if (format == kQTFileTypeJPEG)
return "jpeg";
if (format == kQTFileTypeTIFF)
return "tiff";
if (format == kQTFileTypePNG)
return "png";
if (format == kQTFileTypeGIF)
return "gif";
if (format == kQTFileTypeBMP)
return "bmp";
if (format == kQTFileTypePicture)
return "pict";
if (format == kQTFileTypeAVI)
return "avi";
return "unknown";
}
static void processArguments(int argc, char * argv[])
{
int c, optionIndex = 0;
// Process command-line arguments
while ((c = getopt_long(argc, argv, "hvx:y:Ld:i:n:t:", longOptions, &optionIndex)) != -1)
{
switch (c)
{
case 0:
// If this option set a flag, do nothing else now.
if (longOptions[optionIndex].flag != 0)
break;
printf("option %s", longOptions[optionIndex].name);
if (optarg)
printf(" with arg %s", optarg);
printf("\n");
break;
case '1':
imageWidth = videoWidth = 128;
imageHeight = videoHeight = 96;
break;
case '2':
imageWidth = videoWidth = 160;
imageHeight = videoHeight = 120;
break;
case '3':
imageWidth = videoWidth = 176;
imageHeight = videoHeight = 144;
break;
case '4':
imageWidth = videoWidth = 320;
imageHeight = videoHeight = 240;
break;
case '5':
imageWidth = videoWidth = 352;
imageHeight = videoHeight = 288;
break;
case '6':
imageWidth = videoWidth = 640;
imageHeight = videoHeight = 480;
break;
case '7':
imageWidth = videoWidth = 800;
imageHeight = videoHeight = 600;
break;
case 'x':
imageWidth = videoWidth = atoi(optarg);
break;
case 'y':
imageHeight = videoHeight = atoi(optarg);
break;
case 'L':
listDevices = 1;
filenameNecessary = 0;
break;
case 'd':
selectedVideoDevice = atoi(optarg);
break;
case 'n':
numberOfCaptures = atoi(optarg);
break;
case 't':
delay = atoi(optarg);
break;
case 'i':
selectedVideoInput = atoi(optarg);
break;
case 'v':
printf("%s: %s\n", argv[0], versionString);
break;
case 'D':
duration = atoi(optarg);
break;
case '?':
// getopt_long already printed an error message.
// unknown or ambiguous option
case ':':
// getopt_long already printed an error message.
// missing argument
case 'h':
default:
filenameNecessary = 0;
usage(argv);
exit(0);
}
}
// Instead of reporting `--verbose'
// and `--brief' as they are encountered,
// we report the final status resulting from them.
if (verboseFlag)
{
puts("verbose flag is set");
if (videoFlag)
puts("video flag is set");
}
// Save the filename if there is one
if (optind < argc)
{
filename = argv[optind++];
}
else if (filenameNecessary) // thie is the normal case
{
printf("You must specify a filename for the image! [see '%s --help' for assistance]\n", argv[0]);
exit(0);
}
// Print any remaining command line arguments (not options).
if (optind < argc)
{
printf("non-option ARGV-elements: ");
while (optind < argc)
printf("%s ", argv[optind++]);
putchar('\n');
}
}
/// characterizes a given POSIX-path
enum ePathType { fileOnly = 1, relativeDir, absoluteDir };
/// returns type of given POSIX path
static enum ePathType checkPathType(const char* path)
{
assert(path != NULL);
// has to include a directory, absolute path if it starts with /
return (strchr(path, '/') != NULL ? (path[0] == '/' ? absoluteDir : relativeDir) : fileOnly);
}
/// extends a given POSIX-path to a fully qualified path
static void extendToFullPosixPath(const char * path, char * fullPath)
{
/*
// get current path via main bundle
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef url = CFBundleCopyBundleURL(mainBundle);
// get POSIX-path from bundle URL
CFStringRef sr = CFURLCopyFileSystemPath(url, kCFURLPOSIXPathStyle);
*/
enum ePathType pathType = checkPathType(path); // check path type of given path
assert(strlen(path) < FILENAME_BUFFER_SIZE);
if (pathType == relativeDir || pathType == fileOnly)
{
char location[FILENAME_BUFFER_SIZE];
if (getcwd(location, FILENAME_BUFFER_SIZE) == NULL)
{
fprintf(stderr, "error in call to getcwd() - errno = %d\n", errno);
exit(errno);
}
assert(strlen(location) + strlen(path) < FILENAME_BUFFER_SIZE);
sprintf(fullPath, "%s/%s", location, path); // append path to cwd
}
else // full path
{
sprintf(fullPath, "%s", path); // just copy
}
}
static char* getFullFilename( const char* fn, int fileIndex )
{
char buffer[FILENAME_BUFFER_SIZE];
char* extPath = malloc(FILENAME_BUFFER_SIZE); // temporary filename storage
if (fileIndex == 0)
{
// need to set extension based on image_format / videoFormat
sprintf(buffer, "%s.%s", (fn) ? fn : "wacaw-capture", getFiletypeExtension(videoFlag ? videoFormat : imageFormat));
}
else
{
// need to set extension based on image_format / videoFormat
sprintf(buffer, "%s_%05d.%s", (fn) ? fn : "wacaw-capture", fileIndex, getFiletypeExtension(videoFlag ? videoFormat : imageFormat));
}
// tzeeniewheenie: now extend buffer to fully qualified path
extendToFullPosixPath(&buffer[0], extPath);
return extPath;
}
BOOL fileIndexExists(const char* fn, int fileIndex)
{
char* actualName = getFullFilename(fn, fileIndex);
NSString* nameString = [[NSString alloc] initWithCString: actualName encoding: NSASCIIStringEncoding];
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:nameString];
[nameString release];
return fileExists;
}
static unsigned char* readFile( const char* fn, int* size )
{
// open and count size
FILE* file = fopen(fn, "r");
*size = 0;
while(!feof(file))
{
fgetc(file);
(*size)++;
}
rewind(file);
// now return data
unsigned char* data = malloc(*size);
*size = 0;
while(!feof(file))
{
data[*size] = fgetc(file);
(*size)++;
}
fclose(file);
return data;
}
int main(int argc, char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
OSErr error = noErr;
ComponentResult result = 0;
SeqGrabComponent sequenceGrabber = NULL;
PicHandle picture = NULL;
GraphicsExportComponent graphicsExporter = NULL;
Rect bounds;
processArguments(argc, argv);
error = EnterMovies();
if (error)
{
printf("Error: EnterMovies() returned error %d!\n", error);
return 1;
}
sequenceGrabber = OpenDefaultComponent(SeqGrabComponentType, 0); // open the default sequence grabber
if (!sequenceGrabber)
{
printf("Error: OpenDefaultComponent() returned no sequence grabber component!\n");
return 2;
}
error = SGInitialize(sequenceGrabber); // initialize the sequence grabber
SeqGrabFrameInfo info;
SGDeviceList list = NULL;
int i, j;
bounds.top = 0;
bounds.left = 0;
// if video flag is set, use video values; this is only to preserve different defaults
// for video and pictures
bounds.right = videoFlag ? videoWidth : imageWidth;
bounds.bottom = videoFlag ? videoHeight : imageHeight;
// initializes channels
result = SGNewChannel(sequenceGrabber, VideoMediaType, &info.frameChannel);
if(verboseFlag && result != noErr)
printf("SGNewChannel failed for VideoMediaType.\n");
result = SGSetChannelBounds(info.frameChannel, &bounds);
if(verboseFlag && result != noErr)
printf("SGSetChannelBounds failed.\n");
result = SGSetChannelUsage(info.frameChannel, seqGrabRecord);
if(verboseFlag && result != noErr)
printf("SGSetChannelUsage failed.\n");
// nErr =SGSetChannelUsage(*sgchanVideo, lUsage | seqGrabPlayDuringRecord);
if (listDevices || (selectedVideoDevice >= 0))
{
result = SGGetChannelDeviceList(info.frameChannel, sgDeviceListDontCheckAvailability | sgDeviceListIncludeInputs, &list);
if (verboseFlag && (result != noErr))
printf("SGGetChannelDeviceList failed (%ld).\n", result);
}
// listing devices is now a standalone option, unless a filename *is* specified
if (listDevices)
{
if (list == NULL)
{
printf("The list is empty.\n");
}
else
{
printf("There are %d devices in the list.\n", (**list).count);
printf("The current selection is %d.\n", (**list).selectedIndex);
for (i = 0; i < (**list).count; i++)
{
CFStringRef buffer = CFStringCreateWithPascalString(kCFAllocatorDefault, (**list).entry[i].name, kCFStringEncodingASCII);
printf(" %d - %s [%s] [%s]\n", i, [(NSString *)buffer cString],
((**list).entry[i].flags & sgDeviceNameFlagDeviceUnavailable) ? "is not available" : "is available",
((**list).entry[i].flags & sgDeviceNameFlagShowInputsAsDevices) ? "has inputs" : "has no inputs");
SGDeviceInputList inputList = (**list).entry[i].inputs;
if (inputList != NULL)
{
printf(" There are %d inputs for this device (%d).\n", (**inputList).count, i);
printf(" The current selection is %d.\n", (**inputList).selectedIndex);
for (j = 0; j < (**inputList).count; j++)
{
buffer = CFStringCreateWithPascalString(kCFAllocatorDefault, (**inputList).entry[j].name, kCFStringEncodingASCII);
printf(" %d - %s [%s]\n", j, [(NSString *) buffer cString],
((**inputList).entry[j].flags & sgDeviceInputNameFlagInputUnavailable) ? "is not available" : "is available");
}
}
}
}
if (filename == NULL)
{
SGDisposeDeviceList(sequenceGrabber, list);
CloseComponent(sequenceGrabber);
exit(0);
}
}
if ((selectedVideoDevice >= 0) && (list != NULL))
{
result = SGSetChannelDevice(info.frameChannel, (**list).entry[selectedVideoDevice].name);
if (verboseFlag && (result != noErr))
printf("SGSetChannelDevice failed for the selected device (%ld).\n", result);
else
if (selectedVideoInput >= 0)
{
result = SGSetChannelDeviceInput(info.frameChannel, selectedVideoInput);
if (verboseFlag && (result != noErr))
printf("SGSetChannelDeviceInput failed for the selected input (%ld).\n", result);
}
}
if (list != NULL)
result = SGDisposeDeviceList(sequenceGrabber, list);
if(!noAudioFlag && videoFlag)
{
// Set up the sound-channel, for video recording
SGChannel soundComponent;
result = SGNewChannel(sequenceGrabber, SoundMediaType, &soundComponent);
if (verboseFlag && result != noErr)
printf("SGNewChannel failed for SoundMediaType.\n");
result = SGSetChannelUsage(soundComponent, seqGrabRecord);
if(verboseFlag && result != noErr)
printf("SGSetChannelUsage failed.\n");
}
if (!videoFlag) // Capture an image
{
int fileIndex = 1;
while (fileIndexExists(filename, fileIndex))
{
fileIndex++;
}
printf("Next free index is %d\n", fileIndex);
// no video flag; take a picture
do
{
// Create a QT data reference from the filename
char* extPath = getFullFilename(filename, fileIndex);
CFStringRef pathRef = CFStringCreateWithCString(kCFAllocatorDefault, extPath, kCFStringEncodingASCII);
result = QTNewDataReferenceFromFullPathCFString(pathRef,
kQTNativeDefaultPathStyle, 0, &dataRef, &dataTypeRef);
free(extPath);
CFRelease(pathRef);
if (result != noErr)
{
printf("Error: could not create a data reference:\nfilename: %s\n", extPath);
return -1;
}
for (i = 0; i < numberOfCaptures; i++)
{
result = SGGrabPict(sequenceGrabber, &picture, &bounds, 0, grabPictOffScreen);
if (result)
{
printf("Error: SGGrabPict() returned error %ld!\n", (long) result);
// couldntGetRequiredComponent
return 3;
}
}
// save picture to file
printf("Saving to %s_%d\n", filename, fileIndex);
OpenADefaultComponent(GraphicsExporterComponentType, imageFormat, &graphicsExporter);
if (!graphicsExporter)
{
printf("Error: OpenADefaultComponent() returned no graphics export component!\n");
return 4;
}
result = GraphicsExportSetInputPicture(graphicsExporter, picture);
// use data reference for output
result = GraphicsExportSetOutputDataReference(graphicsExporter, dataRef, dataTypeRef);
GraphicsExportDoExport(graphicsExporter, NULL);
if (toClipboardFlag)
{
// FEATURE REQUEST: copy to clipboard
// UPDATE: learned some more about using CF version of Pasteboard;
// The CFPasteboardRef & Co. as such are only 10.4+, some useful functions
// even 10.5+. So I did some research on how to do this for at least 10.1+.
// Solution: Scrap Manager. Nice warnings about coding deprecated stuff. :p
// Uses carbon framework.
OSStatus err;
ScrapRef currScrap;
err = ClearCurrentScrap();
if(err != noErr)
printf("Error: Clearing clipboard failed.");
else
{
err = GetCurrentScrap( &currScrap );
if(err != noErr)
printf("Error: Getting the clipboard failed.");
else
{
// we can use the PicHandle we got from SGGrabPict
err = PutScrapFlavor( currScrap, kScrapFlavorTypePicture,
kScrapFlavorMaskNone, GetHandleSize((Handle)picture),
*picture );
if( err != noErr )
printf("Error: Putting image to clipboard failed.");
int size = 0;
char* fn = getFullFilename(filename, 0);
unsigned char* picData = readFile(fn, &size);
free(fn);
// get bytes and stuff'em into new array
// size and data for base64 encoding
unsigned char* b64d = malloc((int)round(size * BASE64_ENCODE_SIZE_FACTOR));
int b64l;
encodeBase64( (unsigned char*)picData, size, b64d, &b64l );
free(picData);
err = PutScrapFlavor( currScrap, kScrapFlavorTypeText,
kScrapFlavorMaskNone, b64l, b64d );
free(b64d);
if( err != noErr )
printf("Error: Putting base64 encoded image to clipboard failed.");
}
}
}
fileIndex++;
if (continuousFlag == 1 && delay)
{
sleep(delay);
}
DisposeHandle((Handle)picture);
DisposeHandle(dataRef);
CloseComponent(graphicsExporter);
[pool drain];
} while (continuousFlag == 1);
CloseComponent(sequenceGrabber);
}
else // Record the video
{
// Create a QT data reference from the filename
char* extPath = getFullFilename(filename, 0);
CFStringRef pathRef = CFStringCreateWithCString(kCFAllocatorDefault, extPath, kCFStringEncodingASCII);
result = QTNewDataReferenceFromFullPathCFString(pathRef,
kQTNativeDefaultPathStyle, 0, &dataRef, &dataTypeRef);
free(extPath);
CFRelease(pathRef);
if (result != noErr)
{
printf("Error: could not create a data reference:\nfilename: %s\n", extPath);
return -1;
}
// video flag is set; so we start off a x sec. video
// graphics world has to be set or port error (-903) will be raised
SGSetGWorld(sequenceGrabber, NULL, NULL);
if (verboseFlag)
{
printf("video size: (%d x %d)\n", videoWidth, videoHeight);
printf("duration: %d seconds\n", duration);
}
// set the output file with grab-to-disk option
if( SGSetDataRef(sequenceGrabber, dataRef, dataTypeRef, seqGrabRecord | seqGrabToDisk) != noErr )
printf("Error: Couldn't set data ref.\n");
// prepare recording
result = SGPrepare(sequenceGrabber, false, true);
if( result != noErr )
printf("Error: SGPrepare failed (%d).\n", (int)result);
// set recording time
SGSetMaximumRecordTime(sequenceGrabber, duration * 60 /* convert to ticks */);
// unsigned int stops = 10;
// while (stops > 0) {
if( SGStartRecord(sequenceGrabber) != noErr )
printf("Error: SGStartRecord failed.\n");
// grab until sequence grabber terminates itself due to time limit
while(SGIdle(sequenceGrabber) == noErr);
result = SGStop(sequenceGrabber);
// stops--;
// sleep(1);
// }
if( result != noErr )
printf("Error: SGStop failed (%d).\n", (int)result);
result = CloseComponent(sequenceGrabber);
if( result != noErr )
printf("Error: CloseComponent failed (%d).\n", (int)result);
}
[pool release];
return 0;
}