0
我正在使用getFrameAtTime()
方法MediaMetadataRetriever
类来获取位于视频(mp4)中特定时间的帧。当视频的分辨率为480x270时,这个效果很好。但是如果我使用高清版本(1280x720)的相同视频,那么它会给出错误。有什么出路吗?无法从视频中检索图像
logcat的:
8月6日至一十一日:24:45.714:d/dalvikvm(511):GC_EXTERNAL_ALLOC释放41K,53%的游离2550K/5379K,外部1625K/2137K,暂停120毫秒
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();
}
}
}