Silence-GitHub / BBMetalImage

A high performance Swift library for GPU-accelerated image/video processing based on Metal.
MIT License
985 stars 125 forks source link

VideoFilterVC2: Video gets pixelated in iOS 13 #18

Closed sebastianroth1 closed 4 years ago

sebastianroth1 commented 5 years ago

When you filter the video in VideoFilterVC2.swift with iPhone 11 (iOS 13), the video falters during playback and becomes partially pixelated. Everything works fine on an iPhone 6 (iOS 12.1). I used the current demo version for this test.

Silence-GitHub commented 4 years ago

Is there any log in the console for iPhone 11 (iOS 13)?

sebastianroth1 commented 4 years ago

The console displays the error "Asset writer or video input is not ready for writing this frame" several times. Here I uploaded a screen recording of the error as GIF: http://gifsstore.com/public/upload/gifs/15691318361569131822.gif

Silence-GitHub commented 4 years ago

Try to sleep some time in the video source progress callback. If there is still the same error ("Asset writer or video input is not ready for writing this frame"), try to sleep for a longer duration.

videoSource.start(progress: { (_) in
    usleep(5 * 1000)
}) { (_) in
    // Completion
}
sebastianroth1 commented 4 years ago

That worked. The error no longer occurs. Thank you very much for your help.

Silence-GitHub commented 4 years ago

I guess the reason of the error is that, GPU is much faster than CPU for some iPhones. So the video writer gets too many frames to write. Some frames are dropped because video writer is not ready to write. If I don't drop the video frames, there may be memory issue. Sleeping to wait is the solution. You can test different devices to determine the sleep duration.