2013-11-20 56 views
8

的序列創建視頻對於機器人創建從圖像序列的視頻我用javacv 0.6庫,但我滿足問題: 它通常工作在HTC感覺(4.0.1的Android,處理器類型的ARMv7)和HTC渴望(安卓2.3.3,處理器類型ARM7)手機,但它不會對HTC野火工作 (安卓2.3.5,處理器類型ARMv6的)電話特別是在代碼從圖像javacv

FFmpegFrameRecorder recorder = new FFmpegFrameRecorder(videoFilePath,  
TalkingPhotoConstants.VIDEO_FRAME_WIDTH,TalkingPhotoConstants.VIDEO_FRAME_HEIGHT); 

這部分失敗附上代碼。

public class MovieCreator extends AsyncTask<String, Void, Boolean> { 

private opencv_core.IplImage[] iplimage; 
private String audioFilePath; 


private ProgressDialog progressDialog; 
private Context context; 
private List<TalkFrame> frames; 

public MovieCreator(Context context, opencv_core.IplImage[] images, String audioFilePath,   
List<TalkFrame> frames) { 
    this.context = context; 
    this.iplimage = images; 
    this.audioFilePath = audioFilePath; 
    this.frames = frames; 

} 

private String createMovie() { 

    String videoName = TalkingPhotoConstants.TMP_VIDEO_NAME; 
    String path = TalkingPhotoConstants.RESOURCES_TMP_FOLDER; 
    String videoFilePath = path + videoName; 
    String finalVideoName = TalkingPhotoConstants.FINAL_VIDEO_NAME + 
    System.currentTimeMillis() + ".mp4"; 
    String finalVideoPath = TalkingPhotoConstants.RESOURCES_FOLDER + finalVideoName; 

    try { 

     FFmpegFrameRecorder recorder = new FFmpegFrameRecorder(videoFilePath, 
     TalkingPhotoConstants.VIDEO_FRAME_WIDTH,TalkingPhotoConstants.VIDEO_FRAME_HEIGHT); 


     //int frameCount = iplimage.length; 
     int frameCount = frames.size(); 
     recorder.setAudioCodec(AV_CODEC_ID_AMR_NB); 
     recorder.setVideoCodec(AV_CODEC_ID_MPEG4); 

     recorder.setVideoBitrate(120000); 
     recorder.setFrameRate(TalkingPhotoConstants.VIDEO_FRAME_RATE); 

     recorder.setPixelFormat(AV_PIX_FMT_YUV420P); 
     recorder.setFormat("mp4"); 

     recorder.start(); 


     for (int i = 0; i < frameCount; i++) { 
      TalkFrame currentFrame = frames.get(i); 
      long duration = currentFrame.getDuration(); 
      opencv_core.IplImage iplImage = cvLoadImage(currentFrame.getImageName()); 

      for (int j = 0; j < TalkingPhotoConstants.VIDEO_FRAME_RATE * duration; j++) { 
       recorder.record(iplImage); 

      } 

     } 

     recorder.stop(); 

     mergeAudioAndVideo(videoFilePath, audioFilePath, finalVideoPath); 

    } catch (Exception e) { 
     Log.e("problem", "problem", e); 
     finalVideoName = ""; 
    } 
    return finalVideoName; 
} 

private boolean mergeAudioAndVideo(String videoPath, String audioPath, String outPut) 
throws Exception { 
    boolean isCreated = true; 
    File file = new File(videoPath); 
    if (!file.exists()) { 
     return false; 
    } 


    FrameGrabber videoGrabber = new FFmpegFrameGrabber(videoPath); 
    FrameGrabber audioGrabber = new FFmpegFrameGrabber(audioPath); 

    videoGrabber.start(); 
    audioGrabber.start(); 
    FrameRecorder recorder = new FFmpegFrameRecorder(outPut, 
      videoGrabber.getImageWidth(), videoGrabber.getImageHeight(), 
      audioGrabber.getAudioChannels()); 


    recorder.setFrameRate(videoGrabber.getFrameRate()); 
    recorder.start(); 
    Frame videoFrame = null, audioFrame = null; 
    while ((audioFrame = audioGrabber.grabFrame()) != null) { 
     videoFrame = videoGrabber.grabFrame(); 
     if (videoFrame != null) { 
      recorder.record(videoFrame); 
     } 
     recorder.record(audioFrame); 

    } 
    recorder.stop(); 
    videoGrabber.stop(); 
    audioGrabber.stop(); 
    return isCreated; 
} 

@Override 
protected Boolean doInBackground(String... params) { 
    String fileName = createMovie(); 
    boolean result = fileName.isEmpty(); 
    if (!result) { 
     VideoDAO videoDAO = new VideoDAO(context); 
     videoDAO.open(); 
     videoDAO.createVideo(fileName); 
     videoDAO.close(); 
    } 
    //Utils.cleanTmpDir(); 
    return result; 
} 

@Override 
protected void onPreExecute() { 
    progressDialog = new ProgressDialog(context); 
    progressDialog.setTitle("Processing..."); 
    progressDialog.setMessage("Please wait."); 
    progressDialog.setCancelable(false); 
    progressDialog.setIndeterminate(true); 
    progressDialog.show(); 
} 

@Override 
protected void onPostExecute(Boolean result) { 
    if (progressDialog != null) { 
     progressDialog.dismiss(); 

    } 
} 

}

沒有例外。

1.how可以解決呢?

2.I存在這樣的問題與設備的處理器類型連接的版本。

如果我是正確的我該如何解決呢?

在此先感謝。

回答

0

JavaCV包含被由Java調用一些本地的C代碼。看起來好像你已經有了一個針對ARMv7而不是針對ARMv6編譯的版本。

爲了得到它的工作,你需要重新編譯JavaCV本土位,爲你想要的目標(在這種情況下的ARMv6)的處理器。一旦你做完了這個,你會發現它工作正常。

本地代碼是一種痛苦,但它是像這樣的地方在做一些非常CPU密集型的東西應用很重要。