ffmpeg amr编解码器非交织

时间:2018-12-04 10:32:24

标签: audio ffmpeg amr interleave

请告诉我如何对AMR格式的ffmpeg进行语音编码(wav),禁用交织???我找不到那个标志。默认情况下,根据标准 ETSI TS 126 101 https://www.etsi.org/deliver/etsi_ts/126100_126199/126101/11.00.00_60/ts_126101v110000p.pdf

对输出的AMR帧进行编码
int main()
{
    AVCodec *codec;
    AVCodecContext *c = NULL;
    AVFrame *frame;
    AVPacket *pkt = NULL;
   int i, j, k, ret, got_output;
   int buffer_size;
   FILE *f;
   uint16_t *samples;
   float t, tincr;

   codec = avcodec_find_encoder(AV_CODEC_ID_AMR_NB);

   if (!codec) {
       fprintf(stderr, "Codec not found\n");
       exit(1);
 }

    c = avcodec_alloc_context3(codec);

if (!c) {
    fprintf(stderr, "Could not allocate audio codec context\n");
    exit(1);
}

c->sample_rate = 8000;
c->bit_rate = 12200;
c->channels = 1;
c->sample_fmt = AV_SAMPLE_FMT_S16;
c->channel_layout = AV_CH_LAYOUT_MONO;
c->av_class->option->flags 

if (avcodec_open2(c, codec, NULL) < 0) {
    fprintf(stderr, "Could not open codec\n");
    exit(1);
}


pkt = av_packet_alloc();
if (!pkt) {
    fprintf(stderr, "could not allocate the packet\n");
    exit(1);
}

frame = av_frame_alloc();
if (!frame) {
    fprintf(stderr, "Could not allocate audio frame\n");
    exit(1);
}

frame->nb_samples = c->frame_size;
frame->format = c->sample_fmt;
frame->sample_rate = c->sample_rate;
frame->channel_layout = av_get_default_channel_layout(c->channels);
frame->flags;

/* setup the data pointers in the AVFrame */
ret = av_frame_get_buffer(frame, 0);
if (ret < 0) {
    fprintf(stderr, "Could not allocate audio data buffers\n");
    exit(1);
}

/* encode a single tone sound */
t = 0;
tincr = 2 * M_PI * 440.0 / c->sample_rate;

FILE *output;
output = fopen("file.amr", "wb");

for (i = 0; i < 200; i++) {
    /* make sure the frame is writable -- makes a copy if the encoder
     * kept a reference internally */
    ret = av_frame_make_writable(frame);
    if (ret < 0)
        exit(1);
    samples = (uint16_t*)frame->data[0];

    for (j = 0; j < c->frame_size; j++) {
        samples[j] = (int)(sin(t) * 10000);
        t += tincr;
    }

    /* encode the samples */
    //frame->flags = AVFrame::flags
    ret = avcodec_send_frame(c, frame);
    if (ret < 0) {
        fprintf(stderr, "Error sending the frame to the encoder\n");
        exit(1);
    }

//  while (ret >= 0)
    {
        ret = avcodec_receive_packet(c, pkt);
        if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
            return 0;
        else if (ret < 0) {
            fprintf(stderr, "Error encoding audio frame\n");
            exit(1);
        }

        fwrite(pkt->data, 1, pkt->size, output);
        av_packet_unref(pkt);
    }
}

system("PAUSE");

}

即根据标准表enter image description here,编码后的packat暴露出比特移位。 在此处输入图片描述如何强制编码器,而不使用交织?

0 个答案:

没有答案