MediaMetadataRetriever.getFrameAtTime (long, option) failed

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);

//Create folder to store images
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); //Returns milliseconds - divide by 1,000
//Video length = 30037ms - result is 30.037s

for(int i = 0; i <= 10*vidLength; i++, image++) //10*vidLength since I'm getting frames every 1/10th sec
{
    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();

    //Don't seem to make a difference one way or the other
    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

+5
source share
6 answers

Have you tried using the FFmpegMediaMetadataRetriever lib instead of MediaMetadataRetriever?

Also, from this line on your logcat:

01-22 11: 59: 15.598: E / MediaMetadataRetrieverJNI (572): getFrameAtTime: videoFrame is a NULL pointer

for, Log.d( "MyApp", "Param of getFrameAtTime" + (100000 * i));

, , (19/20), , , (, Long int i?).

, , MediaMetadataRetriever.OPTION_CLOSEST_SYNC OPTION_CLOSEST?

+2

Evo V Android 4.0: , , MediaMetadataRetriever, .

: " MediaMetadataRetriever !"

, , , : MediaMetadataRetriever.OPTION_CLOSEST_SYNC OPTION_CLOSEST.

, OPTION_CLOSEST_SYNC.

, , " ". .

+1

, , . 1000, ...

MediaPlayer..

 file = new File(Environment.getExternalStorageDirectory(), "myvideo.mp4");
 MediaPlayer mp = MediaPlayer.create(MainActivity.this,Uri.parse(file.getAbsolutePath()));
            int duration = mp.getDuration();// it gives duration in milliseconds 
            mp.release();

duration*1000

,

     for(int i=0 ;i <5; i++)
                {
                  if(looper < duration *1000)
                  {
                      ImageView imageView = (ImageView)findViewById(ids_of_images[i]);


imageView.setImageBitmap(retriever.getFrameAtTime(looper,MediaMetadataRetriever.OPTION_CLOSEST));

                        looper +=1000000;  
                  }

                }
0

Android MediaMetadataRetriever.getFrameAtTime() failing/crashing. . Tesco HUDL 1.0 (HT7S3) Android 4.2.2.

.

        if( bmp == null){
            mMediaData = new MediaMetadataRetriever();
            mMediaData.setDataSource( /* same parameters as before */ );
            bmp = mMediaData.getFrameAtTime( /* same parameters */ );
        }

Android, , "" - .

, , , , , .

mediaRetriever 3 , 0,1 , .

0

OPTION_CLOSEST error reported, see https://code.google.com/p/android/issues/detail?id=193194

Google Response August 31, 2016

Hi, The development team fixed the problem that you reported, and it will be available in a future build thanks to Status: FutureRelease

0
source
public Bitmap getVideoFrame() {
        MediaMetadataRetriever retriever = new MediaMetadataRetriever();
        try {
            Uri data = Uri.parse(videoPath);=

            AssetFileDescriptor afd = getResources().openRawResourceFd(R.raw.testvid);
            if (afd != null) {
                retriever.setDataSource(afd.getFileDescriptor());
            }
            myVideoView.setVideoPath(videoPath);
            myVideoView.start();
            Bitmap tmp = retriever.getFrameAtTime();
                Log.e(TAG,"Retrievertmp " + tmp);

            return tmp;
        } catch (IllegalArgumentException ex) {
            ex.printStackTrace();
        } catch (RuntimeException ex) {
            ex.printStackTrace();
        } finally {
            try {
                retriever.release();
            } catch (RuntimeException ex) {
            }
        }
        return null;
    }

tmp is always zero.

Logs: MediaMetadataRetrieverJNI: getFrameAtTime: videoFrame is a null pointer

Can anyone help with this?

0
source

All Articles