i am using stagefright videoencoder to encode video in android 4.4;
sp<AMessage> format = new AMessage;
format->setInt32("width", 1080);
format->setInt32("height", 1920);
format->setString("mime", "video/avc");
format->setInt32("color-format", OMX_COLOR_FormatYUV420Planar);
format->setInt32("bitrate", 1000000);
format->setFloat("frame-rate", 25);
format->setInt32("i-frame-interval", 5);
sp<MediaCodec> videoEncoder = MediaCodec::CreateByType(looper, "video/avc", true);
videoEncoder->configure(format, NULL, NULL,MediaCodec::CONFIGURE_FLAG_ENCODE);
videoEncoder->start();
but when i called:
status_t err = gSpVideoEncoder->dequeueOutputBuffer(&bufIndex, &offset, &size, &ptsUsec, &flags, kTimeout);
i got:
err === INFO_FORMAT_CHANGED
next step, I called:
sp<AMessage> newFormat;
videoEncoder->getOutputFormat(&newFormat);
uint32_t width = 0, height = 0;
newFormat->findInt32("width", (int32_t *)(&width));
newFormat->findInt32("height", (int32_t *)(&height));
fprintf(stderr, "new width: %d, height: %d\n", width, height)
I got result:
new width: 1088, height: 1920
I am confused(not 1080x1920), whether i should provide new input frame(1088x1920) to videoEncoder?
Video coding requires the frame dimensions to be aligned to multiples of 16 i.e. macroblock dimensions. HD resolution i.e. 1920 x 1080 is a special case as 1080 is not a multiple of 16. The underlying encoder expects the client to provide an aligned boundary.
In this case, you could provide the data windowed as below. For Luma
, you will have to align to a multiple of 16 and for Chroma
, you will have to align to a multiple of 8. The remaining pixels could be prefilled with zeroes.
Please note: If the encoder is capable of handling 1920 x 1080 as an encoding resolution, the output should be fine. If the encoder encodes with 1920 x 1088, you will observe a green band at the bottom of the picture in the generated bitstream due to the zero padding.
---------------------------------------------
| |
| |
| |
| Luma |
| 1920 x 1080 |
| filled into |
| a buffer of |
| 1920 x 1088 |
| |
| Last 8 lines could |
| be filled with zeroes |
| |
---------------------------------------------
-----------------------
| Cb |
| 960 x 540 |
| filled into |
| a buffer of |
| 960 x 544 |
| |
-----------------------
-----------------------
| Cr |
| 960 x 540 |
| filled into |
| a buffer of |
| 960 x 544 |
| |
-----------------------