用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]);
            }
        }

 

posted @ 2014-02-23 15:58  bug不是小强  阅读(547)  评论(0编辑  收藏  举报