I'm developing an application that has a feature that converts from an array list of Bitmap Images into MP4 video. I used MediaMuxer and MediaCodec to do this. Everything works fine on almost all devices except some Pixel Devices (e.g. Pixel 6 worked very well, but Pixel 3 can't). The result in Pixel 3 was a green stripe. I searched and read many articles but nothing related to this. Can someone suggest me a solution? Thanks
This is a screen shot of video exported in Pixel 3
This the config that I used:
MediaCodec videoCodec = MediaCodec.createEncoderByType(MIMETYPE_VIDEO_AVC);
MediaFormat videoFormat = MediaFormat.createVideoFormat(MIMETYPE_VIDEO_AVC, width, height);
videoFormat.setInteger(KEY_BIT_RATE, BIT_RATE);
videoFormat.setInteger(KEY_FRAME_RATE, FRAME_RATE);
videoFormat.setInteger(KEY_I_FRAME_INTERVAL, I_FRAME_INTERVAL);
videoFormat.setInteger(KEY_COLOR_FORMAT, COLOR_FormatYUV420Flexible);
videoFormat.setInteger(KEY_MAX_INPUT_SIZE, MAX_INPUT_SIZE);
videoCodec.configure(videoFormat, null, null, CONFIGURE_FLAG_ENCODE);
videoCodec.start();
mediaMuxer = new MediaMuxer(outputFilePath, MUXER_OUTPUT_MPEG_4);
Config value:
BIT_RATE = 1000000;
FRAME_RATE = 20;
I_FRAME_INTERVAL = 5;
MAX_INPUT_SIZE = 10485760; // 10 MB
Note: My boss don't want to use ffmpeg
I read and tried many solutions and finally solved this. Some note:
COLOR_FormatYUV420Planar
)Below is the solution that solved all the above problems created by combining 2 solutions in Stackoverflow thanks to @OldSchool4664, @shervinox(see this) and @monster-brain (see this)
Please read this for full usage, I only provide modified BitmapToVideoEncoder class