I am using NDKMediaCodec to encode video in H264 in below resolutions 240 * 426, 360 * 640, 480 * 854, 720 * 1280
Everything was working earlier to android R, But on android R there is an issue in encoding 360 * 640. I have tested on Pixel 3,Pixel 4 and Pixel 5.
I am creating encoder using
encoder = AMediaCodec_createCodecByName("OMX.qcom.video.encoder.avc"); //i have also tried AMediaCodec_createEncoderByType("video/avc");
And configuring it as
AMediaFormat *format = createMediaFormat(width, height);
AMediaFormat_setString(format, "mime", "video/avc");
AMediaFormat_setInt32(format, "i-frame-interval", IFrameDuration);
AMediaFormat_setInt32(format, "bitrate", bps);
AMediaFormat_setInt32(format, "frame-rate", fps);
AMediaFormat_setInt32(format, "bitrate-mode", 1);
AMediaFormat_setInt32(format, "profile", 1); // AVCProfileBaseline
AMediaFormat_setInt32(format, "level", 512); // AVCLevel31
if (FORMAT_21_REQUIRED) {
AMediaFormat_setInt32(format, "color-format", 21);
}
else {
AMediaFormat_setInt32(format, "color-format", 19);
}
if ((status = AMediaCodec_configure(encoder, format, NULL, NULL, AMEDIACODEC_CONFIGURE_FLAG_ENCODE)) == AMEDIA_OK) {
if ((status = AMediaCodec_start(nativeCodec_data->enc_Amedia)) != AMEDIA_OK) {
//error handle
}
}
else {
//error handle
}
AMediaFormat_delete(format);
If i create encoder like this on earlier versions of android R, it chooses OMX.qcom.video.encoder.avc. But in android R it chooses c2.qti.avc.encoder, even if i specify qcom video encoder.
For 360 * 640 configuration, encoder is producing corrupted image. From SPS and PPS, i can see encoder is generating 368 * 640 resolution with no cropping. If i create encoder with 368 * 640, then there is no issue observed.
If i use OMX.google.h264.encoder, then everything works fine even for 360 * 640. Only problem is with using OMX.qcom.video.encoder.avc and 360 * 640 as resolution.
I am not using any surface, and encoding by passing YUV buffers directly, I have dumped the YUV to file and checked, there is no issue with YUV
ibufidx = AMediaCodec_dequeueInputBuffer(encoder, 0);
AMediaCodec_queueInputBuffer(encoder, ibufidx, 0, bufsize,timeStamp,flags);
I want to achieve 360 * 640 encoding with OMX.qcom.video.encoder.avc on android R. Anyone faced this issue or any suggestions?
I am observing issue on pixel 3, pixel 4 and pixel 5 with android R. I have tested on wide range of devices from embedded devices to samsung latest flagship devices upto android Q. So far tested only pixel devices with android R and observing the issue.