I have a loop where I try to extract a frame from a video every 1/10 of a second. But after 19 frames (1.9 with video), I get the following error in Logcat:
01-22 11:59:15.498: E/OMXCodec(38): [OMX.google.h264.decoder] Timed out waiting for output buffers: 0/0
01-22 11:59:15.598: E/MetadataRetrieverClient(38): failed to capture a video frame
01-22 11:59:15.598: E/MediaMetadataRetrieverJNI(572): getFrameAtTime: videoFrame is a NULL pointer
01-22 11:59:15.598: D/AndroidRuntime(572): Shutting down VM
01-22 11:59:15.598: W/dalvikvm(572): threadid=1: thread exiting with uncaught exception (group=0x409961f8)
01-22 11:59:15.608: E/AndroidRuntime(572): FATAL EXCEPTION: main
01-22 11:59:15.608: E/AndroidRuntime(572): java.lang.NullPointerException
This is the code I'm using:
File videoPath = new File(Environment.getExternalStorageDirectory(), "test.mp4");
String video = videoPath.getAbsolutePath();
MediaMetadataRetriever vidFile = new MediaMetadataRetriever();
vidFile.setDataSource(video);
String storageFolder = "/Storage";
String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
File newFolder = new File(extStorageDirectory + storageFolder);
newFolder.mkdir();
String value = vidFile.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
long vidLength = (Long.parseLong(value)/1000);
for(int i = 0; i <= 10*vidLength; i++, image++)
{
Bitmap bmp = vidFile.getFrameAtTime(100000*i, MediaMetadataRetriever.OPTION_CLOSEST);
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, bytes);
String imagename = String.format(Locale.ENGLISH, "%03d", image);
File f = new File(Environment.getExternalStorageDirectory() + storageFolder + File.separator + imagename + ".png");
f.createNewFile();
FileOutputStream fo = new FileOutputStream(f);
fo.write(bytes.toByteArray());
fo.close();
bytes.flush();
bytes.close();
}
As I said, it should get ~ 300 frames, but it only manages to extract 19 frames before the failure, but I don’t understand why the NULL pointer error occurs.
Thanks in advance
zodac source
share