- (void) startRecording
{
NSError * error;
NSMutableDictionary *compressionSettings = [[[NSMutableDictionary alloc] init] autorelease];
[compressionSettings setValue: [NSNumber numberWithDouble:24*(1024.0*1024.0)] forKey: AVVideoAverageBitRateKey];
[compressionSettings setValue: AVVideoProfileLevelH264Main41 forKey: AVVideoProfileLevelKey];
outputSettings = [[NSMutableDictionary alloc] init];
[outputSettings setValue: AVVideoCodecH264 forKey: AVVideoCodecKey];
[outputSettings setValue: [NSNumber numberWithInt: 1920] forKey: AVVideoWidthKey];
[outputSettings setValue: [NSNumber numberWithInt: 1080] forKey: AVVideoHeightKey];
[outputSettings setValue: compressionSettings forKey: AVVideoCompressionPropertiesKey];
inputWriterBuffer = [AVAssetWriterInput assetWriterInputWithMediaType: AVMediaTypeVideo outputSettings: outputSettings];
outputWriter = [AVAssetWriter assetWriterWithURL: [projectPaths movieURLPath] fileType: AVFileTypeQuickTimeMovie error: &error];
outputWriter.movieFragmentInterval = CMTimeMakeWithSeconds(1.0, theProject.frameRateVideoOutput.frameRateCMTime.timescale);
if ([outputWriter canAddInput: inputWriterBuffer]) [outputWriter addInput: inputWriterBuffer];
outputWriter.metadata = [self commonMetadata];
[outputWriter startWriting];
imageSourceTime = CMTimeMake( 0 ,theProject.frameRateVideoOutput.frameRateCMTime.timescale); //CMTimeMake(1,600);
[outputWriter startSessionAtSourceTime: imageSourceTime];
}
- (NSMutableArray *) commonMetadata
{
// QuickTime X, at least in Snow Leopard 10.6, does not display any of this metadata.
// To do so, seems to require that metadata be written to the base container track instead of to the video track like I'm doing here.
// Use command line tool "mdls" to see what the file metadata looks like.
// You cannot set this property after writing on the receivers asset writer has started.
// The array contains AVMetadataItem objects representing the collection of track-level metadata to be written in the output file.
NSMutableArray * myMetadata = [[NSMutableArray new] autorelease];
AVMutableMetadataItem * metadataItem;
// QT 7 displays in CMD-J window only.
metadataItem = [AVMutableMetadataItem metadataItem];
metadataItem.keySpace = AVMetadataKeySpaceCommon;
metadataItem.key = AVMetadataCommonKeySoftware;
metadataItem.value = @"CameraTime 1.1";
[myMetadata addObject: metadataItem];
return myMetadata;
}