Можно ли использовать CamcorderProfile без источника звука? - PullRequest
2 голосов
/ 02 апреля 2011

Мой код:

mediaRecorder = new MediaRecorder();
mediaRecorder.setCamera(camera);

mediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);

CamcorderProfile profile = CamcorderProfile.get(QUALITY_LOW);
mediaRecorder.setProfile(profile);

Работает.Но мне нужно записывать только видео.

И если я не использую mediaRecorder.setAudioSource (), mediaRecorder.setProfile () завершается с IllegalStateException.

Есть идеи?

Ответы [ 3 ]

5 голосов
/ 02 апреля 2011

С MediaRecord.setProfile :

public void setProfile (профиль CamcorderProfile)

Поскольку: Уровень API 8 использует настройкииз объекта CamcorderProfile для записи.Этот метод должен вызываться после установки видеоисточников И аудиоисточников и перед setOutputFile ().

Из Android - CamcorderProfile docs

Каждый профиль задает следующий набор параметров:

  • Формат вывода файла
  • Формат видеокодека
  • Скорость передачи видео в битах в секунду
  • Частота видеокадров в кадрах в секунду
  • Ширина и высота видеокадра,
  • Формат аудиокодека Скорость звука в битах в секунду
  • Частота дискретизации звука
  • Количество аудиоканалов для записи.

Я бы сказал, что вы можете прочитать соответствующие настройки, относящиеся к видео, из требуемого CamcorderProfile и установить их самостоятельно.

4 голосов
/ 15 апреля 2013

Метод setProfile () MediaRecorder

Implementation

мы можем увидеть, если:

profile.quality >= CamcorderProfile.QUALITY_TIME_LAPSE_LOW //1002
&&
profile.quality <= CamcorderProfile.QUALITY_TIME_LAPSE_QVGA //1007

там не будет setAudio * () Так что в вашемкод, который вы можете вручную установить profile.quality=[any int from 1002 to 1007] до setProfile().Это будет работать, я пытался.

Я нашел правильный ответ:

if (getIsMuteShooting()) { // with out audio                                     
    mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);                  
    mRecorder.setVideoFrameRate(profile.videoFrameRate);                
    mRecorder.setVideoSize(profile.videoFrameWidth, profile.videoFrameHeight);              
    mRecorder.setVideoEncodingBitRate(profile.videoBitRate);                
    mRecorder.setVideoEncoder(profile.videoCodec);
} else {
    mRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);              
    mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);               
    mRecorder.setVideoFrameRate(profile.videoFrameRate);                
    mRecorder.setVideoSize(profile.videoFrameWidth, profile.videoFrameHeight);              
    mRecorder.setVideoEncodingBitRate(profile.videoBitRate);                
    mRecorder.setAudioEncodingBitRate(profile.audioBitRate);                
    mRecorder.setAudioChannels(profile.audioChannels);              
    mRecorder.setAudioSamplingRate(profile.audioSampleRate);                
    mRecorder.setVideoEncoder(profile.videoCodec);              
    mRecorder.setAudioEncoder(profile.audioCodec);
}
0 голосов
/ 02 декабря 2015
mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);

CamcorderProfile profile = CamcorderProfile.get(CamcorderProfile.QUALITY_480P);
mediaRecorder.setOutputFormat(profile.fileFormat);
mediaRecorder.setVideoFrameRate(profile.videoFrameRate);
mediaRecorder.setVideoSize(profile.videoFrameWidth, profile.videoFrameHeight);
mediaRecorder.setVideoEncodingBitRate(profile.videoBitRate);
mediaRecorder.setVideoEncoder(profile.videoCodec);
...