Overlaying image on video reduces video resolution
You are setting your
layercomposition.renderSize = CGSize(width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height)
when it should be
layercomposition.renderSize = yourAsset.tracks(withMediaType: AVMediaTypeVideo)[0].naturalSize
What the first one does is set your resolution to your screen size and not the actual size of the original video. The 2nd one corrects it to setting the resolution of the original video.
Think of it this way - you don't want your resolution to be the size of your screen - that would be really small. You want it the size of some original video or the size of some commonly used video setting.
Overlaying a large image onto a small video like snapchat
You can pass the width and height of the output video.
by using pad attribute you can add a black area in the video if a video with height is small
ffmpeg -i intro-blur.mp4 -i 3.jpg -filter_complex "[0]scale=720:1280:force_original_aspect_ratio=decrease,pad=720:1280:(ow-iw)/2:(oh-ih)/2,setsar=1[backd],[backd][1]overlay" out_intro_blur.mp4
you can scale overlay image like "scale=1439x2559" here overlay image can be accessed by "[1]" if you want to scale overlay image you can use [1]scale=1439x2559[scaled_image] after that you can use [scaled_image] to overlay on video.
example below
ffmpeg -i intro-blur.mp4 -i 3.jpg -filter_complex "[0]scale=720:1280:force_original_aspect_ratio=decrease,pad=720:1280:(ow-iw)/2:(oh-ih)/2,setsar=1[backd],[1]scale=1439x2559[scaled_image],[backd][scaled_image]overlay" out_intro_blur.mp4
Overlay Image quality decreasing with every frame in Live Video Feed
It is happening at this line:
glasses = cv2.resize(glasses, (ew,eh), interpolation = cv2.INTER_AREA)
because you keep resizing the glasses up and down in size at every iteration overwriting the original, so the same pair of glasses gets made bigger, then smaller, then bigger.
Instead, you should start from the original, high-quality glasses rather than from the resized glasses from the previous frame. So, outside the loop, change this line:
glasses = cv2.imread('glasses.png', -1)
to
origGlasses = cv2.imread('glasses.png', -1)
And inside the loop, change this line:
glasses = cv2.resize(glasses, (ew,eh), interpolation = cv2.INTER_AREA)
to:
glasses = cv2.resize(origGlasses, (ew,eh), interpolation = cv2.INTER_AREA)
Bad quality when overlaying PNG with FFMpeg
Use the format
overlay option to avoid the default conversion to yuv420p in overlay filter.
overlay=10:10:format=auto
See the overlay filter documentation for other accepted values.
Related Topics
Prevent Nscollectionview 'Lifting' an Item During Drag
How to Use The Spritekit Method Body(At: Cgpoint)
Wkwebview Problems in Macos Mojave
How to Check for Self with Contains() in Swift
Getting an Ip Address and Port Number from a Sockaddr_In Struct in Swift
Validate Unicode Code Point in Swift
How to Pass Data Backwards to a View Controller After Passing Forward
How to Apply Impulse to The Node on Touch Angle
Wkwebview - Update HTML Tags from Swiftui Textfields
How to Convert Curl Request to Swift Using Alamofire
How to Get Parallax Effect on UIbutton in Tvos
Convert Data to Dispatchdata in Swift 4
Can't Update Label from Other Class in Swift
How to Reinterpret_Cast in Swift
How to Read a File from The Filesystem in a Swift Command Line App