사용 swr_convert
이 포맷 간의 변환합니다. 다음과 같이 입력하십시오 :
#include "libswresample/swresample.h"
au_convert_ctx = swr_alloc();
out_channel_layout = AV_CH_LAYOUT_MONO;
out_sample_fmt = AV_SAMPLE_FMT_S16;
out_sample_rate = 44100;
out_channels = av_get_channel_layout_nb_channels(out_channel_layout);
in_sample_fmt = pCodecCtx->sample_fmt;
in_channel_layout=av_get_default_channel_layout(pCodecCtx->channels);
au_convert_ctx=swr_alloc_set_opts(au_convert_ctx,out_channel_layout, out_sample_fmt, out_sample_rate,
in_channel_layout, in_sample_fmt, pCodecCtx->sample_rate, 0, NULL);
swr_init(au_convert_ctx);
//Generate your frame of original audio, then use swr_convert to convert to mono,
//converted number of samples will now be in out_buffer.
int converted = swr_convert(au_convert_ctx, &out_buffer, MAX_AUDIO_FRAME_SIZE, (const uint8_t **)&pFrame->data , pFrame->nb_samples);
//...
swr_free(&au_convert_ctx);
이렇게하면 원본 형식이 44100 kHz 모노로 변환됩니다. 또한 출력 샘플 속도로 pCodecCtx->sample_rate
을 사용할 수도 있습니다.
가장 유연하고 쉬운 솔루션입니다.
나는 함수가 없다는 것을 기억하지만 두 스트림을 함께 계산하여 쉽게 변환 할 수 있습니다. – user1810087
예를 들어 줄 코드가 있습니까? – Meugiwara