ffmpeg를 사용하여 다양한 파일 형식의 오디오 샘플을 디코딩하려고합니다. 따라서이 토론의 코드를 기반으로 몇 가지 실험을 시작했습니다 : How to decode audio via FFmpeg in Android. 나는 최신 FFMPEG 릴리스 (1.0)를 사용하고 (https://github.com/halfninja/android-ffmpeg-x264libav/ffmpeg로 오디오 파일을 올바르게 엽니 다.
AVFormatContext * pFormatCtx;
avcodec_register_all();
av_register_all();
int lError;
if ((lError = avformat_open_input(&pFormatCtx, filename, NULL, 0))
!= 0) {
LOGE("Error open source file: %d", lError);
return;
}
if ((lError = avformat_find_stream_info(pFormatCtx, 0)) < 0) {
LOGE("Error find stream information: %d (Streams: %d)", lError, pFormatCtx->nb_streams);
return;
}
LOGE("audio format: %s", pFormatCtx->iformat->name);
LOGE("audio bitrate: %d", pFormatCtx->bit_rate);
audioStreamIndex = av_find_best_stream(pFormatCtx, AVMEDIA_TYPE_AUDIO,
-1, -1, &codec, 0);
//if (audioStreamIndex < 0 || audioStreamIndex >= pFormatCtx->nb_streams)
// audioStreamIndex = 0;
LOGE("Stream: %d (total: %d)", audioStreamIndex, pFormatCtx->nb_streams);
LOGE("audio codec: %s", codec->name);
FFMPEG 활성화 디코더 = MP1/MP2/MP3/OGG/Vorbis를/WAV/AAC/테오 라 (Theora)를 사용하여 컴파일
및 외부 라이브러리없이를 사용하여 컴파일
오디오 포맷 : MP3
오디오 B 예 libmp3lame, libtheora 등)하여 MP3 및 WAV 파일의
열기는 MP3에 대한 예를 들어 다음과 같은 출력을 생성 문제없이 작동 itrate : 256121는
스트림 : 0 (총하기 : 1)
오디오 코덱 : MP3
을하지만 내가 OGG 파일을 열려고 할 때이 얻을 :
오류 발견 스트림 정보 : -1 (스트림 : 1)
수동으로 audioStreamIndex=0
을 설정하고 return 문 : -1 (스트림은 : 1)
오디오 포맷 : MP3
오디오 비트 레이트 : 0
스트림 : 0 (총 : 1)
오류 스트림 정보를 찾을 수
오디오 코덱 : MP3
M4A의 경우 (AAC) 내가 얻을이 :
오디오 포맷 : MP3
오디오 비트 레이트 : 288,000
스트림 : 0 (총 : 1)
오디오 코덱 : MP1
하지만, 나중에 avcodec_decode_audio3
에서 실패합니다. 그것은 단지 MP3 및 WAV와 함께 작동하게하고 다른 형식 실패 로딩 코드에 문제가
AVInputFormat *pForceFormat= av_find_input_format("ogg");
if ((lError = avformat_open_input(&pFormatCtx, filename, pForceFormat, 0))
// continue
있습니까 :
은 또한 수동으로 성공없는 형식을 강제로 시도?감사합니다.