2012-09-03 95 views
3

我一直試圖讓MediaRecorder到以下官方例如工作,雖然我能,使其順時針旋轉90度一檔...的Android MediaRecorder使旋轉視頻

現在,我想在這肖像模式,並確實旋轉預覽表面90度,並將其鎖定到肖像模式...

我不知道如何解決這個問題,並得到一個面向人像的視頻,並嘗試了與此主題相關的無數解決方案沒有用...

代碼:

public class CameraRecorder { 

private Camera cam; 
private MediaRecorder mMediaRecorder; 
private CameraPreview mPreview; 
private static Context mContext; 

public CameraRecorder(CameraPreview preview, Context context){ 

    mPreview = preview; 
    cam = mPreview.getCamera(); 
    //cam.getParameters().setRotation(0); 
    mContext = context; 

} 

public boolean prep(){ 


    mMediaRecorder = new MediaRecorder(); 
    //mMediaRecorder.setOrientationHint(90); 

    // Step 1: Unlock and set camera to MediaRecorder 
    cam.unlock(); 
    mMediaRecorder.setCamera(cam); 

    // Step 2: Set sources 
    //mMediaRecorder.setAudioSource(mContext.openFileInput()); 
    mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); 


    // Step 3: Set a CamcorderProfile (requires API Level 8 or higher) 
    mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); 
    //mMediaRecorder.setVideoSize(mPreview.getMeasuredWidth(), mPreview.getMeasuredHeight()); 
    mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP); 

    //mMediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_LOW)); 

    // Step 4: Set output file 
    mMediaRecorder.setOutputFile(getOutputMediaFile().toString()); 

    // Step 5: Set the preview output 
    mMediaRecorder.setPreviewDisplay(mPreview.getHolder().getSurface()); 

    // Step 6: Prepare configured MediaRecorder 
    try { 
     mMediaRecorder.prepare(); 
    } catch (IllegalStateException e) { 
     Log.d("Exception", "IllegalStateException preparing MediaRecorder: " + e.getMessage()); 
     releaseMediaRecorder(); 
     return false; 
    } catch (IOException e) { 
     Log.d("Exception", "IOException preparing MediaRecorder: " + e.getMessage()); 
     releaseMediaRecorder(); 
     return false; 
    } catch (Exception e) { 
     Log.d("Exception", "Exception preparing MediaRecorder: " + e.getMessage()); 
     return false; 
    } 
    return true; 

} 

public static File getOutputMediaFile(){ 

    File mediaFile; 

    mediaFile = new File(mContext.getCacheDir() + File.separator + "vid.mp4"); 

    return mediaFile; 


} 

public void releaseMediaRecorder(){ 

    if (mMediaRecorder != null) { 
     mMediaRecorder.reset(); // clear recorder configuration 
     mMediaRecorder.release(); // release the recorder object 
     mMediaRecorder = null; 
     cam.lock();   // lock camera for later use 
    } 

} 

public void startRecording(){ 

    mMediaRecorder.start(); 

} 

public void stopRecording(){ 

    try { 
     mMediaRecorder.stop(); // stop the recording 
     releaseMediaRecorder(); // release the MediaRecorder object 
     cam.lock(); 
    } catch (Exception e) { 
     Log.d("Exception","Exiting with exception: " + e.getMessage()); 
    } 



} 



} 

我試過各種組合的評論方法,沒有結果(設置特定的視頻尺寸導致「嘗試刪除破損的文件」錯誤「,所以我已經離開了那個單獨)... 我是有意無視音頻源,因爲我只需要視頻(我需要稍後進行音頻拼接,並且確實沒有好主意從哪裏開始)

任何提示,想法或指針都非常感謝!

回答

1

您無法旋轉視頻。只是預覽表面或靜止圖像。但不是視頻流。

+0

哦,歡呼聲...任何方式可以在保存後旋轉文件?也許添加一個自定義的音軌? (一個正確的方向是我需要的) – user1504495

+0

當然,你可以後處理它,但注意它不是輕任務 - 旋轉可能需要一些時間(甚至不是實時)的計算能力,並可能吃電池,但是,它是可行的。只是谷歌的「Java視頻後期處理」或「視頻效果」或「重新編碼」等 –

+1

再次感謝,我會接受你的答案,並希望我會管理:) – user1504495