'Android MediaCodec output frame distorted

I am creating an application that has some encoding work on the raw video received from the camera, and then it gets saved on a file. The cameraPreview while recording is fine but after saving the video I can find artefacts or distorted frames. I am following the basic video encoding. I can't be sharing the code publicly, so ask me for specific snippets and I will be able to share them, I am using a textureView with a surfaceTexture and when there is a frame on the surface I draw it twice, once on the preview of the camera like any normal camera app would do and then take that frame encode it and save it for later use, and it gets saved fine. The issue is on older phones(specially at the beginning) it shows some broken frames but not only at the beginning if the phone is not very good it shows a smeared frame from time to time some rarer times it happens on some good phones. Sorry if the question is not very well formatted but I really need help at this.

To make the question more specific, is there a way to know if the frame encoded is distorted or smeared, I can then drop it but unfortunately there is no codec exception thrown and the codec thinks it has encoded the frame successfully, so I don't know a way of knowing this.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source