Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to merge two video with transparency

I have successfully merge video-1 and video-2, over each other with video-2 being transparent using AVFoundation framework but after merging below video(video-1) is not displayed only video-2 is visible but when I use below code

AVMutableVideoCompositionLayerInstruction *SecondlayerInstruction =[AVMutableVideoCompositionLayerInstruction videoCompositionLayerInstructionWithAssetTrack:secondTrack];
[SecondlayerInstruction setOpacity:0.6 atTime:kCMTimeZero];

its set opacity on video-2 layer.But here actual problem is, there are some content over video-2 layer which is not transparent and here after applying opacity over video-2 layer it also apply over that content which is not transparent.
I am adding two image here which describe both scenario after set opacity using AVMutableVideoCompositionLayerInstruction

enter image description here enter image description here

  • as in image after merging transparent area is black and when I set opacity over second layer whole the video-2 goes transparent now but the content also become transparent.
  • but my question is that how to play transparent video over another video after merging.I already checked video-2 is transparent as it proper play in android platform.

Edited-1 : I also try to set a background color on myVideoCompositionInstructionwhich also not helped. taking reference from this old question link

Edited-2 : In AVVideoComposition.h, I found

Indicates the background color of the composition. Solid BGRA colors only are supported; patterns and other color refs that are not supported will be ignored. If the background color is not specified the video compositor will use a default backgroundColor of opaque black. If the rendered pixel buffer does not have alpha, the alpha value of the backgroundColor will be ignored.

What it means, I didn't get it.can any one help?

like image 990
pramod Avatar asked Dec 01 '16 07:12

pramod


People also ask

How to merge two or more video files?

Step 1. Import the Source Video Files Download, install and open VideoProc Converter; Click the Video icon on its interface to show the Video screen; Click the + Video icon and select the video you want to merge, or directly drag and drop files into the screen. Step 2.

How to use the video merger tool?

How to use the video merger 1 Upload files. Choose the videos and photos you would like to merge. ... 2 Join videos and other files. Rearrange them using drag-and-drop until they're the desired order. For images, you can set duration. 3 Download the merged video. Once your files have been merged, watch the preview. ...

How to combine videos without losing quality?

To combine videos without losing quality, you need a video merger that can accomplish the task without re-encoding or re-compressing. It simply stitches the video files together, and put them into to the container in original quality. The tool in method 1 allows you to tick auto-copy to merge video without re-encoding. Final Words

How to combine two videos side-by-side?

Step 1 Go to the online collage maker in your web browser, you can choose the favorite collage template that you want to combine two videos side-by-side before clicking the Get started button. Step 2 Click the Replace icon inside the box to import the videos, and then you can resize the videos by dragging the blue corner dots and choose fill.


1 Answers

Instead of opacity, you can set the alpha of video.

Explanation : Alpha sets the opacity value for an element and all of its children, While opacity sets the opacity value only for a single component.

enter link description here

like image 94
dahiya_boy Avatar answered Sep 19 '22 21:09

dahiya_boy