我正在努力达到这个效果。您可以在 music.ly 应用程序中查看此效果(波纹效果)
https://drive.google.com/open?id=1uXExnmWQ7OfSGLFXdH7-5imay8tW87vO
这是我的方法。
我将渲染 alpha 和缩放图像到像素缓冲区我使用 AVSampleBufferDisplayLayer 显示所有样本缓冲区。我想展示这个动画 3 sec - 5sec 。一旦用户完成然后我将使用 AVAssetWriter 将其转换为 mp4 。
我无法将 alpha 图像添加到 cvpixelbuffer
如果有更好的方法来制作这个动画。请指导。
我使用 AVAssetReaderTrackOutput 获取所有样本缓冲区。
NSDictionary *readerOutputSettings = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:kCVPixelFormatType_32BGRA], kCVPixelBufferPixelFormatTypeKey, nil];
AVAssetReaderTrackOutput* readerOutput = [AVAssetReaderTrackOutput assetReaderTrackOutputWithTrack:videoTrack
outputSettings:readerOutputSettings];
[reader addOutput:readerOutput];
[reader startReading];
while ((sample = [readerOutput copyNextSampleBuffer]))
{
[samples addObject:(__bridge id)sample];
CFRelease(sample);
}
CVImageBufferRef pixelBuffer = CMSampleBufferGetImageBuffer((__bridge CMSampleBufferRef)[samples lastObject]);
CIImage *filteredImage = [CIImage imageWithCVPixelBuffer:pixelBuffer options:nil];
CIFilter* theFilter = [CIFilter filterWithName:@"CIColorMatrix"];
[theFilter setDefaults];
[theFilter setValue: filteredImage forKey: @"inputImage"];
CIVector *theRVector = [CIVector vectorWithX:1 Y:0 Z:0 W:0];
[theFilter setValue: theRVector forKey:@"inputRVector"];
CIVector *theGVector = [CIVector vectorWithX:0 Y:1 Z:0 W:0];
[theFilter setValue: theGVector forKey:@"inputGVector"];
CIVector *theBVector = [CIVector vectorWithX:0 Y:0 Z:1 W:0];
[theFilter setValue: theBVector forKey:@"inputBVector"];
CIVector *theAVector = [CIVector vectorWithX:0 Y:0 Z:0 W:0.5];
[theFilter setValue: theAVector forKey:@"inputAVector"];
CIVector *theBiasVector = [CIVector vectorWithX:0 Y:0 Z:0 W:0];
[theFilter setValue: theBiasVector forKey:@"inputBiasVector"];
CIImage* result = [theFilter valueForKey: @"outputImage"];
然后我减少了 ciimage 的 alpha 并渲染到第一个像素缓冲区
EAGLContext *eaglContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3];
CIContext *cicontext = [CIContext contextWithEAGLContext:eaglContext options:@{kCIContextWorkingColorSpace : [NSNull null]}];
[cicontext render:result toCVPixelBuffer:CMSampleBufferGetImageBuffer((__bridge CMSampleBufferRef)[samplebuffers firstObject]) bounds:CGRectMake(0, 0, [result extent].size.width,[result extent].size.height) colorSpace:CGColorSpaceCreateDeviceRGB()];
我得到了这个结果。
预期结果
提前致谢