0

I want to edit the camera preview stream, and directly show it on the screen. Now I can get the content through AVCaptureVideoDataOutput, but how can I edit it and use the edited stream instead of the original stream? I have tried convert the CMSampleBuffer to UIImage and show it in UIImageView, the speed is ok. But I wonder whether there is a better way to achieve it.

Thanks in advance!

daquexian
  • 169
  • 3
  • 17

1 Answers1

-1

I had to do something similar. In the end I just added a CALayer in the UIImageView on top of the video stream.

For example: add a watermark logo (Xamarin code - extension method) where parentLayer would be the UIImageView.Layer

    public static void AddWatermarkLayer(this CALayer parentLayer, string watermarkImagePath, nfloat watermark_border, nfloat watermark_size)
    {
        nfloat watermark_x = parentLayer.Frame.Width - (watermark_size + watermark_border);
        nfloat watermark_y = watermark_border;

        var watermarkImage = UIImage.FromFile(watermarkImagePath); //

        CALayer aLayer = new CALayer();
        aLayer.Contents = watermarkImage.CGImage;
        aLayer.Frame = new CGRect(watermark_x, watermark_y, watermark_size, watermark_size);
        aLayer.Opacity = 1f; 
        parentLayer.AddSublayer(aLayer);
    }

If you need to actually save this 'edited' stream, you'll have to use AVMutableVideoComposition to apply the changes that you want and save it to a file.

baberone
  • 124
  • 4