1

生の PCM オーディオ データを u-law にエンコードしようとしていますが、非常に奇妙に聞こえます (聞こえると...)。AVCodecContext構造体 (および入力)を初期化する方法がよくわかりませんAVFrame

ここに私のパラメータがあります:

  • 入力 : PCM (16bits signed), MONO, 44,1kHz (サンプルレート) (Android デバイスの MIC から)

  • 必要な出力 : G.711 u-law、MONO、8kHz (サンプル レート)、64 kbits/s (ビットレート) (私の出力ターゲット デバイスのドキュメントから)

入力 nb サンプルも知っています。これが私が持っているすべての情報です。

だから私はAVCodecContextそのように初期化します:

AVCodec* pCodec = avcodec_find_encoder(AV_CODEC_ID_PCM_MULAW);
// ...
AVCodecContext* pCodecContext = avcodec_alloc_context3(pCodec);
// ...
// Do I need input or output params in following lines?
pCodecContext->channels = 1:
pCodecContext->channel_layout = AV_CH_LAYOUT_MONO;
pCodecContext->sample_rate = 8000;
pCodecContext->bit_rate = 64000
pCodecContext->sample_fmt = AV_SAMPLE_FMT_S16;

そして私AVFrameのような:

AVFrame* pFrame = av_frame_alloc();
pFrame->channels = 1;
pFrame->channel_layout = AV_CH_LAYOUT_MONO;
pFrame->sample_rate = 44100;
pFrame->format = AV_SAMPLE_FMT_S16;
pFrame->nb_samples = /*my audio data samples count*/;
avcodec_fill_audio_frame(pFrame, 1, AV_SAMPLE_FMT_S16, /*my audio data*/, /*my audio data size*/, 0);

次に、 と でエンコードしavcodec_send_frame()ますavcodec_receive_packet()

したがって、私の問題は、入力または出力の目的の値を異なるパラメーターに入れる必要があるかどうかわからないことです。おそらく、途中でエンコードしてから、swresamplelib を使用して「リサンプリング」する必要があります。しかし、今のところ、適切にエンコードされていないことは確かです。アドバイスをお願いします。ありがとう!

4

1 に答える 1