It is now possible to encode frame without crashes. However the generated h264 stream still shows incorrect images.