ffmpeg 音频使用流程

基本的流程:从输入文件中解码出一帧音频(音频数据保存在input_frame->extended_data),把音频数据进行格式转换并且保存到fifo中
从音频fifo中读音频数据(output_frame->data),进行编码,写入文件
1、从输入文件解码出一帧
avformat_open_input->avformat_find_stream_info->avcodec_find_decoder->avcodec_open2->av_frame_alloc->av_init_packet->av_read_frame->avcodec_decode_audio4(至此获得一帧音频数据)->av_free_packet->av_frame_free->avcodec_close->avformat_close_input
至此,已经获取了一帧数据
2、重采样
swr_alloc_set_opts->swr_init->av_samples_alloc->swr_convert->swr_free
3、音频fifo
av_audio_fifo_alloc->av_audio_fifo_realloc->av_audio_fifo_write->av_audio_fifo_read->av_audio_fifo_free
4、编码写入文件
avio_open->avformat_alloc_context->av_guess_format->avcodec_find_encoder->avformat_new_stream->avcodec_open2->avformat_write_header->av_frame_alloc->av_init_packet->avcodec_encode_audio2->av_write_frame->av_free_packet->av_frame_free->av_write_trailer

总结:音频fifo是比较重要的,fifo在处理音频的时候几乎是必须的, 也可以自己实现一个fifo,不过ffmpeg既然实现了,自己写也一样,没啥必要

你可能感兴趣的:(ffmpeg 音频使用流程)