Javacv: frame image data Incomplete :-)

Created on 6 May 2020  路  2Comments  路  Source: bytedeco/javacv

type:{[VIDEO]}, timestamp:{1200000}, h:{360}, w:{640}, buff:{1}, channel:{1}

FFmpegFrameGrabber grabber =
new FFmpegFrameGrabber(
"/home/tanxw/Documents/trtc_6.5.40/examples/resource/ruguo-640x360.mp4");

grabber.setVideoCodec(avcodec.AV_CODEC_ID_H264);
grabber.setPixelFormat(avutil.AV_PIX_FMT_YUVA420P);
grabber.start();

frame = grabber.grab();
var buff = (ByteBuffer) frame.image[0];

limit:230400 capacity: 345600? why? Why the data is incomplete Only Y

bug

Most helpful comment

Thank you for your answer

var buff = (ByteBuffer) frame.image[0];
var byteBuff = new byte[buff.capacity()];
buff.limit(buff.capacity()); // edit limit to capacity size
buff.get(byteBuff, buff.position(), buff.capacity());
buff.rewind();

Problem solved

All 2 comments

The limit is set with whatever stride we get, but in the case of planar formats like this, it looks like we only get a value for the first plane... Just ignore it, use capacity.

Thank you for your answer

var buff = (ByteBuffer) frame.image[0];
var byteBuff = new byte[buff.capacity()];
buff.limit(buff.capacity()); // edit limit to capacity size
buff.get(byteBuff, buff.position(), buff.capacity());
buff.rewind();

Problem solved

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Maleandr picture Maleandr  路  3Comments

kongqw picture kongqw  路  4Comments

RaGreen picture RaGreen  路  4Comments

The-Crocop picture The-Crocop  路  5Comments

eldhosengeorge picture eldhosengeorge  路  3Comments