无法从视频中检索图像

时间:2012-06-11 09:29:06

标签: android media

我正在使用getFrameAtTime()类的MediaMetadataRetriever方法来获取位于视频中特定时间的帧(mp4)。当视频分辨率低于480 x 270时,此功能正常。但如果我使用相同视频的高清版(1280 x 720)则会出错。有什么出路吗?

logcat的:

06-11 08:24:45.714:D / dalvikvm(511):GC_EXTERNAL_ALLOC释放41K,53%免费2550K / 5379K,外部1625K / 2137K,暂停120ms

06-11 08:24:46.974:E / MediaMetadataRetrieverJNI(511):getFrameAtTime:videoFrame是一个NULL指针

代码就是这样:

package com.asin.amit;

import java.io.BufferedOutputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;

import android.media.MediaMetadataRetriever;
import android.os.Bundle;
import android.util.Log;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class AsinActivity extends Activity {
/** Called when the activity is first created. */
private MediaMetadataRetriever mediam;
private Bitmap bmp;
private int g;

private ImageView myImageView;
private TextView tv ;

@Override


public void onCreate(Bundle savedInstanceState) {


    try {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        mediam = new MediaMetadataRetriever();
        String str= "/sdcard/DCIM/wdc.mp4";
        mediam.setDataSource(str);

    } catch (Exception e) {
        // handle any errors
        Log.e("HelloWorld", "1", e);  // log the error
        // Also let the user know something went wrong
        Toast.makeText(
                getApplicationContext(),
                e.getClass().getName() + " " + e.getMessage(),
                Toast.LENGTH_LONG).show();
    }

    try {
        bmp=mediam.getFrameAtTime();


    } catch (Exception e) {
        // handle any errors
        Log.e("HelloWorld", "2", e);  // log the error
        // Also let the user know something went wrong
        Toast.makeText(
                getApplicationContext(),
                e.getClass().getName() + " " + e.getMessage(),
                Toast.LENGTH_LONG).show();
    }



}

}

1 个答案:

答案 0 :(得分:0)

这是我的错。我正在使用从互联网上下载的视频。但如果您使用移动设备拍摄的视频,它将会有效。