Open pennywise94 opened 5 years ago
BBMetalVideoSource
has start(progress:completion:)
method. To loop the video, start the video source again in the completion callback.
func start() {
videoSource.start() { [weak self] (finish) in
guard let self = self else { return }
self.start()
}
}
For audio, I am still working on it. But I am not sure how long it will take. You can use AVPlayer
for audio.
Hi @Silence-GitHub, thank you for the quick reply. Will be looking into it just now, looping the video sounds logical indeed and should work. I'll try adding a separate AVPlayer and get this to work. I have an idea on how to implement it. Will start working on it now. Thanks again for the quick reply!
Is there a way to synchronize AVPlayer with the BBMetalView? For instance, is there any way I can know for sure the audio and video will be completely in sync, or should I hope for the best?
Synchronizing video and audio is the problem I have not solved when working on audio player. Sorry.
That's indeed the issue I am currently facing as well. I'm looking into it as we speak, if I find a solution I'll let you know. Does BBMetalImage
use a CADisplayLink or something similar to render the view? Do you know how much fps this represents or what the bitrate would be?
BBMetalVideoSource
dose not use CADisplayLink
. If you set playWithVideoRate
to true, it outputs video frames with the actual rate. However, the render view FPS is not exactly the same to the actual rate. Because the video source output frame is processed by filters and the filter process time is variable.
Do we have any way to know the "delay" caused by the filter process? E.g. the duration variable of the processing, for example? Can we do something with CACurrentMediaTime()
?
I have reached out on StackOverflow to see if someone has an idea on how to sync MTKView with AVPlayer, or if someone could suggest another approach in which we can sync the audio.
You might find the comments and answers on my StackOverflow post useful, @Silence-GitHub.
Also, would it be an idea to stop drawing in the MTKView, by setting isPaused to true, and then continuing when the processing of the chosen filter is done? This might add a couple of ms delay in the filter being applied, but I think that would be more acceptable than the audio being out of sync. Or am I missing something here and is this not possible, at all? For my suggestion we would need to be able to pause the MTKView, then get notified when the filter is processed and continue drawing in the MTKView.
Another interesting reference regarding this issue: https://github.com/MetalPetal/MetalPetal/issues/40
Hi @Silence-GitHub and @pennywise94, I post an answer here. It is just a work around solution but I think you should consider this to find the general solution.
The solution provided by @hoangdado worked for me. @Silence-GitHub I feel like this should be implemented in the project, as it works smoothly now for audio playback when showing video.
Hi @Silence-GitHub,
First of all, thank you for this wonderful library. I've been successfully using it for processing images, but now I want to use it for video. I have set up a BBMetalView successfully, which shows the video I want. However, two concerns:
I use BBMetalView because I want to give my users the ability to edit their video in real-time, when the video plays back to them. This works at the moment, but only within the first playback of the video (the video is usually 30 seconds long, or shorter), and there is no audio to be heard. Any ideas?
Current setup: