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

有帮助吗?

解决方案

我不确定您的意思是否只是为了播放,或者您是否想导出带有水印的视频,该水印会显示在其他播放器上。

如果您的意思只是为了播放,您可能只需在 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);

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top