[Libav-user] aac encoder in real time scenario

遇到和这个人一毛一样的问题 声音中存在噪声 其他的还好

[Libav-user] aac encoder in real time scenario

Gerard C.L.   gerardcl at gmail.com 
Fri Mar 15 09:19:26 CET 2013


Good moring,

I've seen that it's necessary to show the init methods, so here you have:

----------------------------------------8<-------------------------------------------

int audio_avcodec_init_encode(struct audio_avcodec_encode_state *aavces,
int bit_rate, int sample_rate, int channels){

    int enabled=0;
    avcodec_register_all();

    aavces->c= NULL;

    /* find the encoder */
    aavces->codec = avcodec_find_encoder(CODEC_ID_AAC);  //AQUÍ STRING
*codec, ara AAC default
    if (!aavces->codec) {
        fprintf(stderr, "\n[avcodec - audio - encode] Codec not found");
        //exit(1);
        return enabled;
    }else enabled = 1;

    aavces->c= avcodec_alloc_context();

    /* put sample parameters */
    aavces->c->bit_rate = bit_rate;//64000;
    aavces->c->sample_fmt = AV_SAMPLE_FMT_S16;
    //aavces->c->channel_layout = AV_CH_LAYOUT_STEREO;

    aavces->c->sample_rate = sample_rate;//48000;   //TODO: get it from
dp_map
    aavces->c->channels = channels;//2;                //TODO
    aavces->c->profile = FF_PROFILE_AAC_MAIN;//FF_PROFILE_AAC_LOW;
    //aavces->c->time_base = (AVRational){1, sample_rate};
    aavces->c->time_base.num = 1;
    aavces->c->time_base.den = sample_rate;
    aavces->c->codec_type = AVMEDIA_TYPE_AUDIO;

    /* open it */
    if (avcodec_open(aavces->c, aavces->codec) < 0) {
        fprintf(stderr, "\n[avcodec - audio - encode] Could not open
codec");
        //exit(1);
        return enabled;
    }else enabled = 1;

    /* the codec gives us the frame size, in samples */
    //aavces->frame_size = aavces->c->frame_size;
    //aavces->samples = malloc(aavces->frame_size * 2 *
aavces->c->channels);

    aavces->outbuf_size = 1024;//FF_MIN_BUFFER_SIZE * 10;
    aavces->outbuf = (uint8_t *)av_malloc(aavces->outbuf_size);

    aavces->fifo_buf =
av_fifo_alloc(2*MAX_AUDIO_PACKET_SIZE);//FF_MIN_BUFFER_SIZE);
    aavces->fifo_outbuf = (uint8_t *)av_malloc(MAX_AUDIO_PACKET_SIZE);

    if (!(aavces->outbuf == NULL))enabled = 1;

    printf("\n[avcodec - audio - encode] Enabled!",enabled);

    return enabled;

}

------------------------------->8------------------------------------------------------

Anyone can help me, please?

Hope not being a concept problem...

Thanks,
--------------------
  Gerard C.L.
--------------------


2013/3/14 Gerard C.L. <gerardcl at gmail.com>

> Hi all,
>
> I'm developing an AAC encoder in a real time environment.
>
> The scene is:
> - Capture format -> PCM: 48kHz, stereo, 16b/sample.  at 25fps  -> so, per
> frame, 7680Bytes have to be encoded.
>
> The first problem become when I realised that the encoder works on fixed
> chunk sizes (in this case, for the audio configuration, the size is
> 4096Bytes per chunk). So, working like a file encoder, I was only encoding
> 4096bytes of the 7680 per frame.
> The solution was implementing FIFOs, using the av_fifo_.. methods. So now,
> I can hear the entire captured sound per frame, but I hear some garbage and
> I don't know if it's because of the encoder or how I work with the fifo or
> if I have conceptual errors in my mind. To note that I'm playing the sound
> after saving it to a file, could it be also the problem?
>
> I'm copying the piece of code I've implemented right now, I'd love if some
> one gets the error... I'm so noob...
>
>
> -----------------------------------8<------------------------------------------------------------------
> int audio_avcodec_encode(struct audio_avcodec_encode_state *aavces,
> unsigned char *inbuf, unsigned char *outbuf, int inbufsize) {
>     AVPacket pkt;
>     int frameBytes;
>     int outsize = 0;
>     int packetSize = 0;
>     int ret;
>     int nfifoBytes;
>     int encBytes = 0;
>     int sizeTmp = 0;
>
>     frameBytes = aavces->c->frame_size * aavces->c->channels * 2;
>     av_fifo_realloc2(aavces->fifo_buf,av_fifo_size(aavces->fifo_buf) +
> inbufsize);
>
>     // Put the raw audio samples into the FIFO.
>     ret = av_fifo_generic_write(aavces->fifo_buf, /*(int8_t*)*/inbuf,
> inbufsize, NULL );
>
>     printf("\n[avcodec encode] raw buffer intput size: %d ; fifo size:
> %d",inbufsize, ret);
>
>     //encoding each frameByte block
>     while ((ret = av_fifo_size(aavces->fifo_buf)) >= frameBytes) {
>         ret = av_fifo_generic_read(aavces->fifo_buf,
> aavces->fifo_outbuf,frameBytes, NULL );
>
>         av_init_packet(&pkt);
>
>         pkt.size = avcodec_encode_audio(aavces->c,
> aavces->outbuf,aavces->outbuf_size, (int16_t*) aavces->fifo_outbuf);
>
>         if (pkt.size < 0) {
>             printf("FFmpeg : ERROR - Can't encode audio frame.");
>         }
>         // Rescale from the codec time_base to the AVStream time_base.
>         if (aavces->c->coded_frame && aavces->c->coded_frame->pts !=
> (int64_t) (AV_NOPTS_VALUE ))
>             pkt.pts =
> av_rescale_q(aavces->c->coded_frame->pts,aavces->c->time_base,
> aavces->c->time_base);
>
>         printf("\nFFmpeg : (%d) Writing audio frame with PTS:
> %lld.",aavces->c->frame_number, pkt.pts);
>         printf("\n[avcodec - audio - encode] Encoder returned %d bytes of
> data",pkt.size);
>
>         pkt.data = aavces->outbuf;
>         pkt.flags |= AV_PKT_FLAG_KEY;
>
>         memcpy(outbuf, pkt.data, pkt.size);
>     }
>
>     // any bytes left in audio FIFO to encode?
>     nfifoBytes = av_fifo_size(aavces->fifo_buf);
>
>     printf("\n[avcodec encode] raw buffer intput size: %d", nfifoBytes);
>
>     if (nfifoBytes > 0) {
>         memset(aavces->fifo_outbuf, 0, frameBytes);
>         if (aavces->c->codec->capabilities & CODEC_CAP_SMALL_LAST_FRAME) {
>             int nFrameSizeTmp = aavces->c->frame_size;
>             if (aavces->c->frame_size != 1 &&
> (aavces->c->codec->capabilities & CODEC_CAP_SMALL_LAST_FRAME))
>                 aavces->c->frame_size = nfifoBytes / (aavces->c->channels
> * 2);
>
>             if (av_fifo_generic_read(aavces->fifo_buf,
> aavces->fifo_outbuf,nfifoBytes, NULL ) == 0) {
>                 if (aavces->c->frame_size != 1)
>                     encBytes = avcodec_encode_audio(aavces->c,
> aavces->outbuf,aavces->outbuf_size,(int16_t*) aavces->fifo_outbuf);
>                 else
>                     encBytes = avcodec_encode_audio(aavces->c,
> aavces->outbuf,nfifoBytes, (int16_t*) aavces->fifo_outbuf);
>             }
>             aavces->c->frame_size = nFrameSizeTmp;// restore the native
> frame size
>         } else
>             printf("\n[audio encoder] codec does not support small
> frames");
>     }
>
>     // Now flush the encoder.
>     if (encBytes <= 0){
>         encBytes = avcodec_encode_audio(aavces->c,
> aavces->outbuf,aavces->outbuf_size, NULL );
>         printf("\nFFmpeg : flushing the encoder");
>     }
>     if (encBytes < 0) {
>         printf("\nFFmpeg : ERROR - Can't encode LAST audio frame.");
>     }
>     av_init_packet(&pkt);
>
>     sizeTmp = pkt.size;
>
>     pkt.size = encBytes;
>     pkt.data = aavces->outbuf;
>     pkt.flags |= AV_PKT_FLAG_KEY;
>
>     // Rescale from the codec time_base to the AVStream time_base.
>     if (aavces->c->coded_frame && aavces->c->coded_frame->pts != (int64_t)
> (AV_NOPTS_VALUE ))
>         pkt.pts =
> av_rescale_q(aavces->c->coded_frame->pts,aavces->c->time_base,
> aavces->c->time_base);
>
>     printf("\nFFmpeg : (%d) Writing audio frame with PTS:
> %lld.",aavces->c->frame_number, pkt.pts);
>     printf("\n[avcodec - audio - encode] Encoder returned %d bytes of
> data\n",pkt.size);
>
>     memcpy(outbuf + sizeTmp, pkt.data, pkt.size);
>
>     outsize = sizeTmp + pkt.size;
>
>     return outsize;
> }
>
> -------------------------------------------------->8-------------------------------------------------
>
>
> Then, I'm saving outbuf with outsize per frame encoded.
>
> Any idea of what I'm doing wrong?
>
> Thanks in advance!
> --------------------
>   Gerard C.L.
> --------------------
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20130315/c5f874e2/attachment.html>


More information about the Libav-user mailing list
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
VR(Virtual Reality)即虚拟现实,是一种可以创建和体验虚拟世界的计算机技术。它利用计算机生成一种模拟环境,是一种多源信息融合的、交互式的三维动态视景和实体行为的系统仿真,使用户沉浸到该环境中。VR技术通过模拟人的视觉、听觉、触觉等感觉器官功能,使人能够沉浸在计算机生成的虚拟境界中,并能够通过语言、手势等自然的方式与之进行实时交互,创建了一种适人化的多维信息空间。 VR技术具有以下主要特点: 沉浸感:用户感到作为主角存在于模拟环境中的真实程度。理想的模拟环境应该使用户难以分辨真假,使用户全身心地投入到计算机创建的三维虚拟环境中,该环境中的一切看上去是真的,听上去是真的,动起来是真的,甚至闻起来、尝起来等一切感觉都是真的,如同在现实世界中的感觉一样。 交互性:用户对模拟环境内物体的可操作程度和从环境得到反馈的自然程度(包括实时性)。例如,用户可以用手去直接抓取模拟环境中虚拟的物体,这时手有握着东西的感觉,并可以感觉物体的重量,视野中被抓的物体也能立刻随着手的移动而移动。 构想性:也称想象性,指用户沉浸在多维信息空间中,依靠自己的感知和认知能力获取知识,发挥主观能动性,寻求解答,形成新的概念。此概念不仅是指观念上或语言上的创意,而且可以是指对某些客观存在事物的创造性设想和安排。 VR技术可以应用于各个领域,如游戏、娱乐、教育、医疗、军事、房地产、工业仿真等。随着VR技术的不断发展,它正在改变人们的生活和工作方式,为人们带来全新的体验。
VR(Virtual Reality)即虚拟现实,是一种可以创建和体验虚拟世界的计算机技术。它利用计算机生成一种模拟环境,是一种多源信息融合的、交互式的三维动态视景和实体行为的系统仿真,使用户沉浸到该环境中。VR技术通过模拟人的视觉、听觉、触觉等感觉器官功能,使人能够沉浸在计算机生成的虚拟境界中,并能够通过语言、手势等自然的方式与之进行实时交互,创建了一种适人化的多维信息空间。 VR技术具有以下主要特点: 沉浸感:用户感到作为主角存在于模拟环境中的真实程度。理想的模拟环境应该使用户难以分辨真假,使用户全身心地投入到计算机创建的三维虚拟环境中,该环境中的一切看上去是真的,听上去是真的,动起来是真的,甚至闻起来、尝起来等一切感觉都是真的,如同在现实世界中的感觉一样。 交互性:用户对模拟环境内物体的可操作程度和从环境得到反馈的自然程度(包括实时性)。例如,用户可以用手去直接抓取模拟环境中虚拟的物体,这时手有握着东西的感觉,并可以感觉物体的重量,视野中被抓的物体也能立刻随着手的移动而移动。 构想性:也称想象性,指用户沉浸在多维信息空间中,依靠自己的感知和认知能力获取知识,发挥主观能动性,寻求解答,形成新的概念。此概念不仅是指观念上或语言上的创意,而且可以是指对某些客观存在事物的创造性设想和安排。 VR技术可以应用于各个领域,如游戏、娱乐、教育、医疗、军事、房地产、工业仿真等。随着VR技术的不断发展,它正在改变人们的生活和工作方式,为人们带来全新的体验。
基于GPT-SoVITS的视频剪辑快捷配音工具 GPT, 通常指的是“Generative Pre-trained Transformer”(生成式预训练转换器),是一个在自然语言处理(NLP)领域非常流行的深度学习模型架构。GPT模型由OpenAI公司开发,并在多个NLP任务上取得了显著的性能提升。 GPT模型的核心是一个多层Transformer解码器结构,它通过在海量的文本数据上进行预训练来学习语言的规律。这种预训练方式使得GPT模型能够捕捉到丰富的上下文信息,并生成流畅、自然的文本。 GPT模型的训练过程可以分为两个阶段: 预训练阶段:在这个阶段,模型会接触到大量的文本数据,并通过无监督学习的方式学习语言的结构和规律。具体来说,模型会尝试预测文本序列中的下一个词或短语,从而学习到语言的语法、语义和上下文信息。 微调阶段(也称为下游任务训练):在预训练完成后,模型会被应用到具体的NLP任务中,如文本分类、机器翻译、问答系统等。在这个阶段,模型会使用有标签的数据进行微调,以适应特定任务的需求。通过微调,模型能够学习到与任务相关的特定知识,并进一步提高在该任务上的性能。 GPT模型的优势在于其强大的生成能力和对上下文信息的捕捉能力。这使得GPT模型在自然语言生成、文本摘要、对话系统等领域具有广泛的应用前景。同时,GPT模型也面临一些挑战,如计算资源消耗大、训练时间长等问题。为了解决这些问题,研究人员不断提出新的优化方法和扩展模型架构,如GPT-2、GPT-3等,以进一步提高模型的性能和效率。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值