0
点赞
收藏
分享

微信扫一扫

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

小编 2022-09-27 阅读 48


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

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

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

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 条评论