用ffmpeg和audioTrack实现音频输出

 

使用ffmpeg 解码, Android的audioTrack播放音频,只是自己的笔记而已

av_register_all();

avformat_open_input()

avformat_find_stream_info()

codecCtx=formatCtx->streams[audioStream]->codec;

pCodec=avcodec_find_decoder(codecCtx->codec_id);

avcodec_open2(codecCtx, pCodec, &optionsDict)

}

 

while(av_read_frame(formatCtx, &packet)>=0 && !stop) {
        // Is this a packet from the video stream?
        if(packet.stream_index==audioStream) {
            // Decode video frame
            avcodec_decode_audio4(codecCtx, decodedFrame, &frameFinished,
               &packet);
            // Did we get a video frame?
            if(frameFinished) {
                data_size = 
                    av_samples_get_buffer_size
                    (
                     NULL, 
                     codecCtx->channels,
                     decodedFrame->nb_samples,
                     codecCtx->sample_fmt,
                     1
                    );
                memcpy(&out_buf, decodedFrame->data[0], decodedFrame->linesize[0]);
            }
        }

 

转载于:https://www.cnblogs.com/tanjinc/p/3562034.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值