【Android音视频开发】C++多线程解码音频数据

FFmpeg在C++子线程中解码音频数据,得到数据包AVPacket

AVPacket:存放原始音频/视频的压缩包。

C++多线程解码音频数据

1、注册解码器并初始化网络

av_register_all();

avformat_network_init();

2、打开文件或网络流

AVFormatContext *pFormatCtx = avformat_alloc_context();

avformat_open_input(&pFormatCtx, url, NULL, NULL);

3、获取流信息

avformat_find_stream_info(pFormatCtx, NULL)

4、获取音频流

pFormatCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO

5、获取解码器

AVCodec *dec = avcodec_find_decoder(audio->codecpar->codec_id);

6、利用解码器创建解码器上下文

AVCodecContext *avCodecContext = avcodec_alloc_context3(dec); avcodec_parameters_to_context(audio->avCodecContext, audio->codecpar)

7、打开解码器

avcodec_open2(audio->avCodecContext, dec, 0)

8、读取音频帧

AVPacket *packet = av_packet_alloc();

av_read_frame(pFormatCtx, packet);

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值