AVFrame pcm音频帧的保存

13 篇文章 0 订阅

目的

将pcm数据保存到文件中,方便使用pcm音频播放器来进行播放。

代码

void writeAVFramePcmToFile(AVFrame *inFrame,QFile *outPcmFilePtr)
{
    if(NULL == inFrame)
    {
        qDebug()<<"robin:InFrame is NULL";
        return;
    }
    int  t_data_size = av_samples_get_buffer_size(
                            NULL, inFrame->channels,
                            inFrame->nb_samples,
                            (AVSampleFormat)inFrame->format,
                            0);
    if(t_data_size < 0)
    {
        qDebug()<<"robin:av_samples_get_buffer_size return:"<<t_data_size<<"||so return.";
        return;
    }
    if(av_sample_fmt_is_planar((AVSampleFormat)inFrame->format))
    {//如果是平面的
        uint8_t *buf = (uint8_t *)malloc(t_data_size);
        interleave(inFrame->data, buf,
                   inFrame->channels, (AVSampleFormat)inFrame->format, t_data_size);
        outPcmFilePtr->write((const char *)buf,t_data_size);
        outPcmFilePtr->flush();
        free(buf);
    }
    else
    {

        outPcmFilePtr->write((const char *)inFrame->data[0],t_data_size);
        outPcmFilePtr->flush();
    }
}

总结

关键点就是:pcm数据是否是平面类型

(年纪大了,总感觉这个问题以前写过博客,算了,再写一遍吧)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值