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

♀尐吖头ヾ 提交于 2019-12-01 18:18:40

问题


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


回答1:


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



回答2:


In my experience, the built in MediaMetadataRetriver rarely works in general. Try something like this instead.



来源:https://stackoverflow.com/questions/28019511/mediametadataretrieverjni14060-getframeattime-videoframe-is-a-null-pointera

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!