开发者

Cocoa Add Image At End Of Video

I'm recording a video from the iSight camera using QTCaptureSession.

I would like to add an image at the end of the video, so I've implemented the didFinishRecordingToOutputFileAtURL delegate methods. Here's what I've done so far:

- (void)captureOutput:(QTCaptureFileOutput *)captureOutput didFinishRecordingToOutputFileAtURL:(NSURL *)outputFileURL forConnections:(NSArray *)connections dueToError:(NSError *)error
{

    // Prepare final video
    QTMovie *originalMovie = [QTMovie movieWithURL:outputFileURL error:nil];
    [originalMovie setAttribute:[NSNumber numberWithBool:YES] forKey:QTMovieEditableAttribute];

    NSImage *splashScreen = [NSImage imageNamed:@"video-ending.jpg"];

    NSImage *tiffImage = [[NSImage alloc] initWithData:[splashScreen TIFFRepresentation]];

    id attr = [NSDictionary dictionaryWithObjectsAndKeys:@"tiff",
               QTAddImageCodecType,
               [NSNumber numberWithLong:codecHighQuality], QTAddImageCodecQuality,
               nil];

    [originalMovie addImage:tiffImage forDuration:QTMakeTime(2, 1) withAttributes:attr];

    [tiffImage release];

    [originalMovie updateMovieFile];
}

The problem with this code is that while quicktime plays it nice, other players don't. I'm sure I'm missing something basic here.

It would also be cool to add the image to the video before it gets saved (to avoid during it two times). Here's how I stop recording right now:

- (void)stopRecording
{   
    // It would be cool to add an image here
    [mCaptureMovieFileOutput recordToOut开发者_JAVA技巧putFileURL:nil];
}


While I used Cocoa touch this might still apply. I have two tips based on my experience writing images to movies. First, while I'll bet that addImage:forDuration takes care of a lot of things that AVAssetExportSessions do not, I had to make sure that images were added more regularly than a couple times a second or they would not work well with all players. Second, if there is a network streaming option, such as the AVAssetExportSession shouldOptimizeForNetworkUse to move as much metadata and headers forward in the movie, I found that it made the video compatible with more players as well.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜