2

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 recordToOutputFileURL:nil];
}
Oscar Del Ben
  • 4,485
  • 1
  • 27
  • 41
  • I know this is late, and it's just a thought ... perhaps you can specify a different compression (eg. same compression as the movie is using), when adding the image ? –  Sep 22 '15 at 03:07

1 Answers1

1

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.

Peter DeWeese
  • 18,141
  • 8
  • 79
  • 101
  • Unfortunately using a different qttime such as QTMakeTime(1200, 600) doesn't seem to work. Instead of showing the image the VLC player just quicks (right before opening a new window containing the image for a tenth of a second). – Oscar Del Ben Jun 21 '11 at 21:29