-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Video overlay on top of live feed #26
Comments
|
@YuAo is there any sample on MetalPetal |
@isamercan No.
Is there anything that confuses you? |
@YuAo Thanks. I have made many variations by using examples and solutions from issues. But Could not make succeed on put two video sources (one of them should have MTIBlendFilter) |
@isamercan Oh, that is in fact simpler. You can follow the video processor example and refer to this thread: MetalPetal/MetalPetal#302 The pseudo code should be like: let composition = AVMutableComposition(...)
for video in yourVideos {
let videoTrack = composition.addMutableTrack(...)
let videoAsset = AVURLAsset(url: video.url, ...)
let originalVideoTrack = videoAsset.tracks(withMediaType: .video)[0] //load the original track
videoTrack.insertTimeRange(of: originalVideoTrack ...)
withExtendedLifetime(videoAsset, ...)
}
...
let videoComposition = MTIVideoComposition(asset: composition, context: renderContext, queue: DispatchQueue.main, filter: { request in
let images = request.sourceImages....
let filter = MultilayerCompositingFilter()
filter.layers = ... //create layers from images, apply blend modes
filter.backgroundImage = ....
return filter.outputImage!
})
// use videoComposition for play / export
... |
@YuAo you are the best. Thank you very much 🙏 |
@YuAo How can I apply blend mode for added second source? |
You can use the |
@YuAo Thanks I added like that. |
@YuAo When I use just one asset inside
|
@isamercan The player is not playing the two-track video. |
@YuAo I dont want to play 2 tracks. I want to apply second video as blend mode over mode. I could not add request.sourceimages[2] to filter.backgroundimage |
@isamercan I don't understand. If you are not going to give the player a two-track asset, how can it blend one track over another? The |
@YuAo I can. apply overlay image to video by using layer blend mode or MTIBlendFilter but when i want to apply overlay video asset to original video asset then I am not successful.
It does not return images |
@isamercan Because your player plays the one-track asset. It cannot get anything about the overlay track so there's only one item in the
You must understand that the In your case, the player should play |
@YuAo Thanks. for your great. help 🙏🏻. Thanks for your patience. It's done.🎉 MetalPetal and VideoIO are really great APIs. |
@YuAo is there any option to loop any one of the sources |
@isamercan Yes, you can compose that |
@YuAo but short duration source stops. how to start and loop until end of final time range? |
@isamercan I think you should read the "Editing" part of the AVFoundation Programming Guide. https://developer.apple.com/library/archive/documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/03_Editing.html#//apple_ref/doc/uid/TP40010188-CH8-SW1 You can also google for "AVMutableComposition loop" |
@YuAo Can you give a hint? |
I could able to add it as in the code line seen above. but Im now sure its the best way to set a end duration and looping? |
@isamercan I think you can refer to this answer: https://stackoverflow.com/questions/20211694/loop-avmutablecompositiontrack |
when I checked your example project that I found this block
I want to change the overlay video source while playing the BG video. |
@isamercan If you have a few overlay videos, you can add them all to the composition and use trackID to switch between them in the filter block. Most iOS device can handle compositions with 16 video tracks. If there are a lot of possible overlay videos or the video can be chosen by a user, you'll have to decode and synchronize the video playback yourself. This is beyond what |
@YuAo Yes that's right overlays can be chosen by users while playing composition. Could I change the overlay video by using this method?
|
@isamercan No. |
@YuAo so the Composition video will start beginning every time? |
|
@YuAo Thanks. I preferred the last one. |
Hi!
So what I'd like to is overlay a short looping video as a texture on top of the live feed previewImage (cgImage) from the CameraFilterView.swift example on MetalPetal, then export the recording later. I've noticed in other threads on here the mention of using PlayerVideoOutput to do so.
Is there a possible simple usage example on how this would work when the live feed is a cgImage rather than an AVPlayer?
Would this be a good way to do it? -
I think I'm confused on the implementation methods here though. Just want to live record with a looping MP4 playing on top.
The text was updated successfully, but these errors were encountered: