int bitrate = mediaformat.getInteger(MediaFormat.KEY_BIT_RATE) is returning NullPointerException

432 Views Asked by At

I am new to mediaCodec and using MediaFormat for extracting the video information. I am using:

int width = format.getInteger(MediaFormat.KEY_WIDTH);
int height  = format.getInteger(MediaFormat.KEY_HEIGHT);
int bitrate = format.getInteger(MediaFormat.KEY_BIT_RATE);

Height and Width are OK, I am getting correct height and width but the bitrate part is throwing an NullPointerException.

java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference

1

There are 1 best solutions below

0
Mohan On BEST ANSWER

Fixed this issue using

MediaMetadataRetriever class.

MediaMetadataRetriever m = new MediaMetadataRetriever();
m.setDataSource(filepath);
int bitrate = Integer.valueOf(m.extractMetadata(MediaMetadataRetriever.METADATA_KEY_BITRATE));

This worked