2013-11-20 3 views
8

안드로이드의 이미지 시퀀스에서 비디오를 만들려면 javacv 0.6 라이브러리를 사용했지만 문제가 발생했습니다 : 일반적으로 htc Sensation (Android 4.0.1, 프로세서 유형 armv7) 및 htc Desire에서 작동합니다 (안드로이드 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(); 

    } 
} 

}

도 예외가 없습니다.

어떻게 해결할 수 있습니까?

2. 장치의 프로세서 유형에 문제가있는 버전이 있습니다.

내가 맞으면 어떻게 해결할 수 있습니까?

미리 감사드립니다.

답변

0

JavaCV는 Java에 의해 호출되는 일부 원시 C 코드를 포함합니다. ARMv7 용으로 컴파일되었지만 ARMv6 용으로 컴파일되지 않은 버전이있는 것처럼 보입니다.

작동 시키려면 대상으로 지정하려는 프로세서 (이 경우 ARMv6)에 대해 JavaCV 기본 비트를 다시 컴파일해야합니다. 일단이 작업을 마치면 제대로 작동하는 것입니다.

네이티브 코드는 고통이지만 매우 CPU 집약적 인 작업을하는 곳에서는 중요합니다.

관련 문제