2

只是寻找如何使用可可以编程方式向视频添加水印或某种覆盖。不是一步一步地寻找(虽然那会很棒),而是或多或少地寻找我应该从哪里开始寻找学习方法。是否有为此开发的框架。想要可可、objective-c 或 c 原生的东西,因为我想最终在 iPhone 上试一试。任何帮助都会很棒。

4

1 回答 1

3

我不确定您的意思是仅用于播放,还是要导出带有水印的视频,该水印会显示在其他播放器上。

如果您只是为了播放,您可能只需在 Mac 和 iPhone 上的播放器视图顶部添加一个包含水印的视图。

如果您想在视频本身上加水印,这在 Mac 上很难,在 iPhone 上可能是不可能的,除非基本上重写 QuickTime。

在 Mac 上,代码可能如下所示(需要导入 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);

......就是这样!您的电影现在有了水印,您可以将其导出到文件中。

于 2009-10-20T13:10:36.883 回答