2010-10-10 15 views

risposta

16

fare riferimento a Camera.Parameters.setRotation() per ulteriori informazioni.

C'è un esempio lì e invece di chiamare setRotation (rotazione) tenta di chiamare mediaRecorder.setOrientationHint (rotazione) durante la registrazione di video.

+7

'mediaRecorder.setOrientationHint' cambia solo l'orientamento del video in uscita, non l'orientamento dell'anteprima. – Cat

+3

Inoltre, 'setOrientationHint' funziona solo per i flussi MPEG4. Altri (come MPEG2TS) non implementano questa opzione (viene silenziosamente ignorata). – Lekensteyn

+0

@Cat hai ragione, hai qualche idea su come sistemarlo nell'anteprima? !! –

6

Date un'occhiata alla documentazione qui

http://developer.android.com/guide/topics/media/camera.html#capture-video

L'insidia più comune con l'questo esempio è il setcamera(). È NECESSARIO IMPOSTARE IMMEDIATAMENTE LA VIDEOCAMERA DOPO AVER FATTO il MediaRecorder altrimenti si otterranno errori.

Camera mCamera = getCameraInstance(); 
    // adjust the camera the way you need 
    mCamera.setDisplayOrientation(90); 

    MediaRecorder recorder = new MediaRecorder(); 

    recorder.setCamera(mCamera); 

    recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT); 
    recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT); 
    recorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH)); 
    recorder.setOutputFile(filePath); 

    // add any limits 
    recorder.setMaxDuration(50000); // 50 seconds 
    recorder.setMaxFileSize(5000000); // Approximately 5 megabytes 

Spero che questo aiuti qualcuno. In bocca al lupo!!

+1

questo codice fallirà A MENO che chiami 'mCamera.unlock();' prima di 'recorder.setCamera (mCamera)': http://developer.android.com/reference/android/hardware/Camera.html#unlock() – Cat

3

Anch'io ho bloccato questo problema. Ho scoperto che è possibile utilizzare la funzione setOrientationHint (API 9). Chiamare questa funzione prima di chiamare MediaRecorder.prepare(). È possibile impostare il grado di orientamento per il video in uscita.

Spero che ti aiuti, buona fortuna!

+0

bello ... funziona bene! grazie! – Antonio

+2

in realtà non ruota il video per correggere l'orientamento, è solo una bandiera impostata su video che alcuni mediaplayer come vlc ignorano. – Nima

6

Aggiungere le seguenti due righe di codice:

Camera.setDisplayOrientation(90); // use for set the orientation of the preview 
mRecorder.setOrientationHint(90); // use for set the orientation of output video 

prima:

mRecorder.setCamera(mCamera); 

esempio completa:

mRecorder = new MediaRecorder(); 

// Both are required for Portrait Video 
mCamera.setDisplayOrientation(90); 
mRecorder.setOrientationHint(90); 

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

// Step 2: Set sources 
mRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT); 
mRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT); 

// Step 3: Set a CamcorderProfile (requires API Level 8 or higher) 
mRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_480P)); 
1
mMediaRecorder = new MediaRecorder(); 
     mServiceCamera.setDisplayOrientation(90); 
     mMediaRecorder.setOrientationHint(90); 
     mServiceCamera.unlock(); 
     mMediaRecorder.setCamera(mServiceCamera); 
     mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); 
     mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); 
     mMediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH)); 
Problemi correlati