Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MediaMetadataRetrieverJNI(14060): getFrameAtTime: videoFrame is a NULL pointer(Android)

I am creating thumbnails by videos frame using MediaMetadataRetriever but I am getting this message in Logcat:

E/MediaMetadataRetrieverJNI(14060): getFrameAtTime: videoFrame is a NULL pointer

Here is my code:

MediaMetadataRetriever retriever  = new MediaMetadataRetriever();
                    try {

                    Uri  videoURI = Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.video_one);
                    retriever = new MediaMetadataRetriever();
                    retriever.setDataSource(mContext, videoURI);
                    Bitmap bitmap = retriever.getFrameAtTime(100000,MediaMetadataRetriever.OPTION_CLOSEST_SYNC );
                    Drawable drawable = new BitmapDrawable(getResources(), bitmap);
                    holder.imageView.setImageDrawable(drawable);
                    holder.progressBar.setVisibility(View.INVISIBLE);

                } catch (Exception e) {
                    e.printStackTrace();
                }

Then I tried this FFmpegMediaMetadataRetriever Library but it produces this in Logcat:

01-19 12:38:33.371: D/dalvikvm(20821): Trying to load lib /data/data/wseemann.media.demo/lib/libavutil.so 0x41733c90
01-19 12:38:33.371: D/dalvikvm(20821): Added shared lib /data/data/wseemann.media.demo/lib/libavutil.so 0x41733c90
01-19 12:38:34.121: W/System.err(20821): java.lang.RuntimeException: setDataSource failed: status = 0xFFFFFFFF
01-19 12:38:34.121: W/System.err(20821):    at wseemann.media.FFmpegMediaMetadataRetriever.setDataSource(Native Method)
01-19 12:38:34.121: W/System.err(20821):    at wseemann.media.FFmpegMediaMetadataRetriever.setDataSource(FFmpegMediaMetadataRetriever.java:243)
01-19 12:38:34.121: W/System.err(20821):    at wseemann.media.demo.FMMRDemo.onCreate(FMMRDemo.java:50)
01-19 12:38:34.121: W/System.err(20821):    at android.app.Activity.performCreate(Activity.java:5188)
01-19 12:38:34.121: W/System.err(20821):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
01-19 12:38:34.121: W/System.err(20821):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2074)
01-19 12:38:34.121: W/System.err(20821):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
01-19 12:38:34.121: W/System.err(20821):    at android.app.ActivityThread.access$700(ActivityThread.java:140)
01-19 12:38:34.121: W/System.err(20821):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
01-19 12:38:34.121: W/System.err(20821):    at android.os.Handler.dispatchMessage(Handler.java:99)
01-19 12:38:34.121: W/System.err(20821):    at android.os.Looper.loop(Looper.java:137)
01-19 12:38:34.121: W/System.err(20821):    at android.app.ActivityThread.main(ActivityThread.java:4921)
01-19 12:38:34.121: W/System.err(20821):    at java.lang.reflect.Method.invokeNative(Native Method)
01-19 12:38:34.121: W/System.err(20821):    at java.lang.reflect.Method.invoke(Method.java:511)
01-19 12:38:34.121: W/System.err(20821):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
01-19 12:38:34.121: W/System.err(20821):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
01-19 12:38:34.121: W/System.err(20821):    at dalvik.system.NativeStart.main(Native Method)

Here is my code:

ImageView imageView= (ImageView) findViewById(R.id.imageView1);
    try {
        FFmpegMediaMetadataRetriever retriever = new  FFmpegMediaMetadataRetriever();
        AssetFileDescriptor afd;
        afd = getAssets().openFd("video_one.mp4");
        retriever.setDataSource(afd.getFileDescriptor(),afd.getStartOffset(),afd.getLength());
        Bitmap bitmap = retriever.getFrameAtTime(100000,FFmpegMediaMetadataRetriever.OPTION_CLOSEST_SYNC );
        Drawable drawable = new BitmapDrawable(getResources(), bitmap);
        imageView.setImageDrawable(drawable);
        retriever.release();
    } catch (Exception e) {
        e.printStackTrace();
    }

Next I tried with SDcard path but still same logcat

like image 879
User42590 Avatar asked Oct 20 '22 18:10

User42590


1 Answers

Try using MediaMetadataRetriever.OPTION_CLOSEST_SYNC instead of MediaMetadataRetriever.OPTION_NEXT_SYNC.

If that doesn't work, then you should try using FFmpegMediaMetadataRetriever library, since MediaMetadataRetriever is not compatible with all API's.

EDIT:

Try this for SD card files:

FFmpegMediaMetadataRetriever retriever = new  FFmpegMediaMetadataRetriever();
try {
retriever.setDataSource("mnt/sdcard/video.mp4"); //file's path
Bitmap bitmap = retriever.getFrameAtTime(100000,FFmpegMediaMetadataRetriever.OPTION_CLOSEST_SYNC );
Drawable drawable = new BitmapDrawable(getResources(), bitmap);
i.setImageDrawable(drawable);

} catch (Exception e) {
e.printStackTrace();
}
finally{
retriever.release();
}
like image 67
max59 Avatar answered Nov 02 '22 11:11

max59