transcode_aac流程:
init_resampler重采样初始化
av_audio_fifo_alloc(output_codec_context->sample_fmt,output_codec_context->channels, 1)
// 只要一帧Sample buffer
avformat_write_header(output_format_context, NULL))
while (1) {
/* Use the encoder's desired frame size for processing. */
const int output_frame_size = output_codec_context->frame_size;
int finished = 0;
/* Make sure that there is one frame worth of samples in the FIFO
* buffer so that the encoder can do its work.
* Since the decoder's and the encoder's frame size may differ, we
* need to FIFO buffer to store as many frames worth of input samples
* that they make up at least one frame worth of output samples. */
while (av_audio_fifo_size(fifo) < output_frame_size) {
/* Decode one frame worth of audio samples, convert it to the
* output sample format and put it into the FIFO buffer. */
if (read_decode_convert_and_store(fifo, input_format_context,
input_codec_context,
output_codec_context,
resample_context, &finished))
goto cleanup;
/* If we are at the end of the input file, we continue
* encoding the remaining audio samples to the output file. */
if (finished)
break;
}
/* If we have enough samples for the encoder, we encode them.
* At the end of the file, we pass the remaining samples to
* the encoder. */
while (av_audio_fifo_size(fifo) >= output_frame_size ||
(finished && av_audio_fifo_size(fifo) > 0))
/* Take one frame worth of audio samples from the FIFO buffer,
* encode it and write it to the output file. */
if (load_encode_and_write(fifo, output_format_context,
output_codec_context))
goto cleanup;
/* If we are at the end of the input file and have encoded
* all remaining samples, we can exit this loop and finish. */
if (finished) {
int data_written;
/* Flush the encoder as it may have delayed frames. */
do {
data_written = 0;
if (encode_audio_frame(NULL, output_format_context,
output_codec_context, &data_written))
goto cleanup;
} while (data_written);
break;
}
}
/* Write the trailer of the output file container. */