Cocoa - Add Video Watermark General Info
Just find how to programmatically add a watermark or some kind of overlay to a video using cocoa. Not looking step by step (although that would be great), but more or less looking for where I should start looking, how to learn. Is there a framework designed for this. I wish there was something native to cocoa or objective-c or c, because I would like to render this to iPhone eventually. Any help would be great.
source to share
I'm not sure if you only mean playback, or if you want to export a watermarked video that will display on other players.
If you mean for playback only, you can simply add a view on top of the player view on Mac and iPhone that contains a watermark.
If you want a watermark on the video itself, it's tricky on a Mac and probably not possible on an iPhone without a substantial rewrite of QuickTime.
On Mac, the code might look like this (you need to import QTKit):
// Make a new movie so we don't destroy the existing one
QTMovie* movie = [[QTMovie alloc] initWithMovie:currentMovie
timeRange:QTMakeTimeRange(QTMakeTime(0,1000), [currentMovie duration])
error:nil];
// Make it editable
[movie setAttribute:[NSNumber numberWithBool:YES]
forKey:QTMovieEditableAttribute];
//Get the size
NSValue *value = [movie attributeForKey:QTMovieNaturalSizeAttribute];
NSSize size = [value sizeValue];
// Add a new track to the movie and make it the frontmost layer
QTTrack *track = [movie addVideoTrackWithSize:size];
[track setAttribute:[NSNumber numberWithShort:-1] forKey:QTTrackLayerAttribute];
// Create a codec dictionary for the image we're about to add
NSDictionary *imageDict = [NSDictionary dictionaryWithObjectsAndKeys:
@"tiff", QTAddImageCodecType,
[NSNumber numberWithLong:codecHighQuality], QTAddImageCodecQuality, nil];
// Get the video length in QT speak
QTTime qttime = [currentMovie duration];
NSTimeInterval reftime;
QTGetTimeInterval(qttime, &reftime);
//Add the image for the entire duration of the video
[track addImage:image forDuration:qttime withAttributes:imageDict];
// Finally, tell the track that it should use its alpha correctly
MediaHandler media = GetMediaHandler([[track media] quickTimeMedia]);
MediaSetGraphicsMode(media, graphicsModeStraightAlpha, NULL);
... And this! Your movie now has a watermark and you can export it to a file.
source to share