2012-06-11 117 views
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(); 
    } 



} 

}

回答

0

這是我的錯。我正在使用從互聯網上下載的視頻。但是,如果你使用手機拍攝的視頻,它將起作用。