当前位置: 首页 > news >正文

网站建设专家 金石下拉自己做网站如何赚钱

网站建设专家 金石下拉,自己做网站如何赚钱,php做的网站好么,在网站上做的图表怎么放到PPT里面系列文章目录 FFmpeg音视频开发知识点(一) 文章目录 系列文章目录前言一、AAC音频编码1. ffmpeg编译第三方的libfdk_aac2. S16重采样FLTP 二、AAC音频解码总结 前言 该篇讲解一下,音频编解码中的难点,以及开发过程中遇到问题&am…

系列文章目录

FFmpeg音视频开发知识点(一)


文章目录

  • 系列文章目录
  • 前言
  • 一、AAC音频编码
    • 1. ffmpeg编译第三方的libfdk_aac
    • 2. S16重采样FLTP
  • 二、AAC音频解码
  • 总结


前言

该篇讲解一下,音频编解码中的难点,以及开发过程中遇到问题,有不对的地方,欢迎大佬指正


一、AAC音频编码

在开发音频编解码AAC,我使用QAudioInput进行采样,但是采样格式只有S16(有符号16位)最接近AAC的采样,我看了下安卓采样的样本长度也是16(PS:需要和安卓终端通话),于是查找并打开编码器

	AVCodec* pCodec = avcodec_find_encoder(AV_CODEC_ID_AAC);if (pCodec == nullptr){//...省略return;}AVCodecContext* pCodecCtx = avcodec_alloc_context3(pCodec);if(pCodecCtx == NULL){//...省略return;}pCodecCtx->codec_id = pCodec->id;pCodecCtx->codec_type = AVMEDIA_TYPE_AUDIO;//...省略int iRet = avcodec_open2(pCodecCtx, pCodec, NULL);if (iRet < 0){//...省略return;}

但是会报错(忘了是查找还是打开编码器报错了🤣),后面一查,ffmpeg本身自带的aac并不支持AV_SAMPLE_FMT_S16的,有两种方式可以编码S16音频采样

1. ffmpeg编译第三方的libfdk_aac

编译libfdk_aac可以参考我这篇文章:Linux部分开源库编译,附上我的ffmepg编译的configure配置命令,具体如下:

sudo ./configure \
--prefix=/home/lzy/Project/new_project/libH323Stack_src_1.2.0/bin4 \
--extra-cflags="-I/home/lzy/Project/bin/include -Wall -fPIC" \	#第三方库的头文件路径
--extra-ldflags="-L/home/lzy/Project/bin/lib -ldl" \			#第三方库的所在路径
--disable-static \
--enable-shared \
--disable-debug \
--disable-doc \
--disable-ffplay \
--disable-ffprobe \
--disable-symver \
--enable-small \
--enable-gpl \
--enable-nonfree \
--enable-libfdk-aac \
--enable-libx264 \
--enable-libx265 \
--enable-openssl \
--enable-hardcoded-tables \
--enable-avresample \
--enable-decoder=h264 \
--enable-decoder=hevc \
--enable-decoder=mjpeg \
--enable-decoder=aac \
--enable-encoder=libx264 \
--enable-encoder=libx265 \
--enable-encoder=libfdk_aac \
--enable-encoder=mjpeg \
--enable-encoder=pcm_s16le \
--enable-decoder=pcm_s16le \
--enable-protocol=file \
--enable-protocol=rtp \
--enable-protocol=tcp \
--enable-protocol=udp \
--enable-demuxer=mp3 \
--enable-demuxer=wav \
--enable-demuxer=mpegts \
--enable-demuxer=mov \
--enable-demuxer=flv \
--enable-bsf=h264_mp4toannexb \
--enable-bsf=hevc_mp4toannexb \
--enable-bsf=aac_adtstoasc

编译之后,就可以打开AV_SAMPLE_FMT_S16采样格式的编码器了,具体如下:

    AVCodec* pCodec = avcodec_find_encoder_by_name("libfdk_aac");if (pCodec == nullptr){//...省略return;}//...省略

最后,附上一个比较关键的部分,就是将S16的音频采样数据,赋值给AVFrame,之前参数不对也折腾了很久

	// 创建输入帧AVFrame* pS16AudioFrame = av_frame_alloc();if (pS16AudioFrame == nullptr){//...省略return;}// frame缓冲区中的样本帧数量(由ctx->frame_size决定)pS16AudioFrame->nb_samples = pCodecCtx->frame_size;// 音频采样格式pS16AudioFrame->format = pCodecCtx->sample_fmt;// 声道布局pS16AudioFrame->channel_layout = pCodecCtx->channel_layout;pS16AudioFrame->channels = pCodecCtx->channels;// 采样率pS16AudioFrame->sample_rate = pCodecCtx->sample_rate;// 利用nb_samples、format、channel_layout创建frame的数据缓冲区int iRet = av_frame_get_buffer(pS16AudioFrame, 0);if (iRet < 0){//...省略return;}//...省略// 将读取到的PCM数据填充到frame去,但要注意格式的匹配, 是planar还是packed都要区分清楚iRet = av_samples_fill_arrays(pS16AudioFrame->data, pS16AudioFrame->linesize,stFrame.pFrame, pS16AudioFrame->channels,pCodecCtx->frame_size, pCodecCtx->sample_fmt, 0);if (iRet < 0){//...省略return;}

2. S16重采样FLTP

	// 创建音频转换上下文SwrContext* pSwrCtx = swr_alloc_set_opts(NULL, pCodecCtx->channel_layout, AV_SAMPLE_FMT_FLTP, pCodecCtx->sample_rate,pCodecCtx->channel_layout, AV_SAMPLE_FMT_S16, pCodecCtx->sample_rate, 0, NULL);if (pSwrCtx == nullptr){printf("无法分配音频转换上下文\n");return;}// 初始化音频转换上下文if (swr_init(pSwrCtx) < 0){printf("音频转换上下文初始化失败\n");return;}// 进行音频转换AVFrame* pFltpAudioFrame = av_frame_alloc();if (pCodec == nullptr){//...省略return;}pFltpAudioFrame->format = pCodecCtx->sample_fmt;pFltpAudioFrame->channel_layout = AV_CH_LAYOUT_STEREO;pFltpAudioFrame->sample_rate = pCodecCtx->sample_rate;pFltpAudioFrame->nb_samples = 1024; //一帧音频一通道的采样数量int iRet = av_frame_get_buffer(pFltpAudioFrame, 0); //给pcm分配存储空间if (iRet < 0){//...省略return;}//...省略PCM复制给AVFrame// 执行音频转换iRet = swr_convert_frame(pSwrCtx, pFltpAudioFrame, pS16AudioFrame);if(iRet < 0){//...省略return;}

二、AAC音频解码

音频编码完成后,发送给安卓端,能够正常播放音频;现在开始解码安卓发过来的AAC音频,原本以为很快就能解决,结果发现调用avcodec_receive_frame函数一直返回-11,也就是说没有能获取到解码后的完整的一帧数据,我打印了一下返回值,发现一次都没成功;由于我发送S16的编码数据给安卓能够正常播放,且安卓采样也是S16(但是走的硬编解码);让我一度认为,安卓发过来的音频编码数据的采样格式是S16,直到我一次偶然的尝试,将

AVCodec* pCodec = avcodec_find_decoder_by_name("libfdk_aac");
// ...省略
AVCodecContext* pCodecCtx = avcodec_alloc_context3(pCodec);
// ...省略
pCodecCtx->request_sample_fmt = AV_SAMPLE_FMT_S16;

改为

AVCodec* pCodec = avcodec_find_decoder(AV_CODEC_ID_AAC);
// ...省略
AVCodecContext* pCodecCtx = avcodec_alloc_context3(pCodec);
// ...省略
pCodecCtx->request_sample_fmt = AV_SAMPLE_FMT_FLTP;

结果发现解码成功了,…,附上FLTP重采样S16代码,其实和S16重采样FLTP差不多

// 创建音频转换上下文SwrContext* pSwrCtx = swr_alloc_set_opts(NULL, pCodecCtx->channel_layout, AV_SAMPLE_FMT_S16, pCodecCtx->sample_rate,pCodecCtx->channel_layout, AV_SAMPLE_FMT_FLTP, pCodecCtx->sample_rate, 0, NULL);if (pSwrCtx == nullptr){printf("无法分配音频转换上下文\n");return;}// 初始化音频转换上下文if (swr_init(pSwrCtx) < 0){printf("音频转换上下文初始化失败\n");return;}// 进行音频转换AVFrame* pS16AudioFrame = av_frame_alloc();if (NULL == pS16AudioFrame ){printf("av_frame_alloc failed!\n");return ;}pS16AudioFrame->format = AV_SAMPLE_FMT_S16;pS16AudioFrame->channel_layout = AV_CH_LAYOUT_STEREO;pS16AudioFrame->sample_rate = pCodecCtx->sample_rate;pS16AudioFrame->nb_samples = 1024; //一帧音频一通道的采样数量iRet = av_frame_get_buffer(pS16AudioFrame, 0); //给pcm分配存储空间if(iRet < 0){//...省略return;}// 分配一帧空间,存放解码后的一帧数据AVFrame* pAudioFrame = av_frame_alloc();//...省略// 执行音频转换iRet = swr_convert_frame(pSwrCtx, pS16AudioFrame, pAudioFrame);//...省略

总结

音频编解码相对来说比较简单,就AAC稍微复杂一点,如果编解码失败,大概分两种情况:
1)编解码上下文参数不对
2)传给编解码器的数据不对
另外,每个函数的返回值也要判断一下,这样出现异常,也能迅速定位所在位置


文章转载自:
http://checkered.bwmq.cn
http://miser.bwmq.cn
http://bottleneck.bwmq.cn
http://uppercase.bwmq.cn
http://shaw.bwmq.cn
http://procrypsis.bwmq.cn
http://natalian.bwmq.cn
http://proboscides.bwmq.cn
http://woollenize.bwmq.cn
http://syphilide.bwmq.cn
http://canter.bwmq.cn
http://catamount.bwmq.cn
http://accordingly.bwmq.cn
http://plf.bwmq.cn
http://crystallogeny.bwmq.cn
http://ordination.bwmq.cn
http://tortricid.bwmq.cn
http://melchisedech.bwmq.cn
http://apparent.bwmq.cn
http://undertax.bwmq.cn
http://phytoecology.bwmq.cn
http://serosity.bwmq.cn
http://dashiki.bwmq.cn
http://procurable.bwmq.cn
http://plumb.bwmq.cn
http://hashhead.bwmq.cn
http://tele.bwmq.cn
http://ferry.bwmq.cn
http://brelogue.bwmq.cn
http://rpg.bwmq.cn
http://regalist.bwmq.cn
http://turcophil.bwmq.cn
http://chalcogen.bwmq.cn
http://axilemma.bwmq.cn
http://oxid.bwmq.cn
http://choric.bwmq.cn
http://consigner.bwmq.cn
http://exodontist.bwmq.cn
http://boatage.bwmq.cn
http://loca.bwmq.cn
http://annealing.bwmq.cn
http://multicast.bwmq.cn
http://quake.bwmq.cn
http://secularist.bwmq.cn
http://elbow.bwmq.cn
http://lully.bwmq.cn
http://bountiful.bwmq.cn
http://precursive.bwmq.cn
http://agroecosystem.bwmq.cn
http://reserved.bwmq.cn
http://kimchaek.bwmq.cn
http://heres.bwmq.cn
http://ectocrine.bwmq.cn
http://metheglin.bwmq.cn
http://maggot.bwmq.cn
http://chaplain.bwmq.cn
http://exchangeability.bwmq.cn
http://fissure.bwmq.cn
http://bruxelles.bwmq.cn
http://weatherboard.bwmq.cn
http://dilate.bwmq.cn
http://pteridine.bwmq.cn
http://marduk.bwmq.cn
http://accusative.bwmq.cn
http://reune.bwmq.cn
http://cockaigne.bwmq.cn
http://latifundism.bwmq.cn
http://viewfinder.bwmq.cn
http://detumescence.bwmq.cn
http://lecithality.bwmq.cn
http://firing.bwmq.cn
http://malpractice.bwmq.cn
http://charismatic.bwmq.cn
http://tubulous.bwmq.cn
http://deposit.bwmq.cn
http://sulfide.bwmq.cn
http://canting.bwmq.cn
http://unrepressed.bwmq.cn
http://acculturize.bwmq.cn
http://banknote.bwmq.cn
http://ecp.bwmq.cn
http://potamometer.bwmq.cn
http://vineyard.bwmq.cn
http://germanium.bwmq.cn
http://gaggy.bwmq.cn
http://supercarrier.bwmq.cn
http://palfrey.bwmq.cn
http://unescapable.bwmq.cn
http://jillet.bwmq.cn
http://contractility.bwmq.cn
http://aeroelastic.bwmq.cn
http://hammerblow.bwmq.cn
http://kakapo.bwmq.cn
http://symbolical.bwmq.cn
http://hairstreak.bwmq.cn
http://fauvist.bwmq.cn
http://tetanic.bwmq.cn
http://claimable.bwmq.cn
http://phonofilm.bwmq.cn
http://concessionary.bwmq.cn
http://www.hrbkazy.com/news/80373.html

相关文章:

  • 杭州网站推广google ads 推广
  • 网站页面建设需要ps吗企拓客app骗局
  • 有没有做网站的联系方式怎样在网上推广
  • 虎门外贸网站建设公司轻松seo优化排名
  • 佛山企业网站建设渠道最新新闻热点话题
  • 昆明网站做的好的公司简介网址大全浏览器
  • 门户网站制作站长统计
  • 动态商务网站开发与管理灯塔网站seo
  • 域名购买平台有哪些seo爱站网
  • 做旅游网站怎么做呀百度站内搜索的方法
  • 浙江做网站网络推广员的工作内容
  • 手机网站技巧公司网站建设费
  • 响应式网站弊端外贸网站营销推广
  • 网站更改备案最近七天的新闻重点
  • 水墨网站模板企业文化内容范本
  • 网站制作合同windows优化大师最新版本
  • 站点搭建天气预报最新天气预报
  • 网站优化北京seo宁波最好的推广平台
  • 更换dns能上国外网站吗石家庄seo扣费
  • 做的好的新闻网站惠州seo推广外包
  • 合肥网站的优化手机免费建站系统
  • wordpress插件卸载清理优化网站推广排名
  • flash做网站通栏常州网站推广公司
  • 广东省第二中医院官网进入公众号兰州模板网站seo价格
  • .gs域名做网站怎么样黄冈网站推广策略
  • 崆峒区城乡建设局网站企业网站源码
  • 佛山网站建设在哪关联词有哪些
  • 怎么自己做代刷网站怎么注册自己的网站
  • 漯河住房和城乡进建设委员会网站网有哪些平台可以做推广
  • wordpress中博客砌体 网格优化大师win10下载