I am using getFrameAtTime() method of MediaMetadataRetriever class to get a frame located at a particular time in a video(mp4). This works fine when the video is of low resolution say 480 x 270. But if I use HD version (1280 x 720) of same video then it gives error. Is there any way out ?
Logcat:
06-11 08:24:45.714: D/dalvikvm(511): GC_EXTERNAL_ALLOC freed 41K, 53% free 2550K/5379K, external 1625K/2137K, paused 120ms
06-11 08:24:46.974: E/MediaMetadataRetrieverJNI(511): getFrameAtTime: videoFrame is a NULL pointer
Code is this:
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();
}
}
}
It was my mistake. I was using videos downloaded from internet. But if you use videos shot by mobile it will work.