I want to use AVFoundation to add a logo to the video.

Asked 2 years ago, Updated 2 years ago, 79 views

I am creating a video editing application with swift.

Using AVFoundation, we create the ability to add logos to videos.

I was able to find some samples of objective-c, but
I don't have many samples with swift.
I try to rewrite the +objective-c sample to swift, but it doesn't work.

If anyone has a good sample, please let me know...

I am a beginner at heart less than a month after ios development.

ios swift avfoundation

2022-09-29 21:21

1 Answers

Now I can do it (Ob-C...)

 - (void) setLogo: (AVMutableVideoComposition*) videoComposition
{
    UIImage*logo= [UIImage imageNamed: @"watermark" ];
    CALayer*logoLayer= [CALayer layer];
    logoLayer.contents=(id)logo.CGImage;
    logoLayer.frame = CGRectMake (15, height-83, 67, 68);
    CALayer* parentLayer = [CALayer layer];
    CALayer* videoLayer= [CALayer layer];
    parentLayer.frame = CGRectMake(0,0, width, height);
    videoLayer.frame = CGRectMake(0,0, width, height);
    parentLayer addSublayer: videoLayer;
    parentLayer addSublayer:logoLayer;
    videoComposition.animationTool= [AVVideoCompositionCoreAnimationTool] VideoCompositionCoreAnimationToolWithPostProcessingAsVideoLayer: videoLayer
                                                                                                                                  inLayer:parentLayer];
}


2022-09-29 21:21

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.