Commit 749a89d1 authored by Andreas Unterweger's avatar Andreas Unterweger Committed by Anton Khirnov

examples/transcode_aac: properly select the output sample format

Makes the example work with all the supported AAC encoders.
Signed-off-by: 's avatarAnton Khirnov <anton@khirnov.net>
parent 443b7192
...@@ -40,11 +40,9 @@ ...@@ -40,11 +40,9 @@
#include "libavresample/avresample.h" #include "libavresample/avresample.h"
/** The output bit rate in kbit/s */ /** The output bit rate in kbit/s */
#define OUTPUT_BIT_RATE 48000 #define OUTPUT_BIT_RATE 96000
/** The number of output channels */ /** The number of output channels */
#define OUTPUT_CHANNELS 2 #define OUTPUT_CHANNELS 2
/** The audio sample output format */
#define OUTPUT_SAMPLE_FORMAT AV_SAMPLE_FMT_S16
/** /**
* Convert an error code into a text message. * Convert an error code into a text message.
...@@ -178,9 +176,12 @@ static int open_output_file(const char *filename, ...@@ -178,9 +176,12 @@ static int open_output_file(const char *filename,
(*output_codec_context)->channels = OUTPUT_CHANNELS; (*output_codec_context)->channels = OUTPUT_CHANNELS;
(*output_codec_context)->channel_layout = av_get_default_channel_layout(OUTPUT_CHANNELS); (*output_codec_context)->channel_layout = av_get_default_channel_layout(OUTPUT_CHANNELS);
(*output_codec_context)->sample_rate = input_codec_context->sample_rate; (*output_codec_context)->sample_rate = input_codec_context->sample_rate;
(*output_codec_context)->sample_fmt = AV_SAMPLE_FMT_S16; (*output_codec_context)->sample_fmt = output_codec->sample_fmts[0];
(*output_codec_context)->bit_rate = OUTPUT_BIT_RATE; (*output_codec_context)->bit_rate = OUTPUT_BIT_RATE;
/** Allow the use of the experimental AAC encoder */
(*output_codec_context)->strict_std_compliance = FF_COMPLIANCE_EXPERIMENTAL;
/** /**
* Some container formats (like MP4) require global headers to be present * Some container formats (like MP4) require global headers to be present
* Mark the encoder so that it behaves accordingly. * Mark the encoder so that it behaves accordingly.
...@@ -276,10 +277,11 @@ static int init_resampler(AVCodecContext *input_codec_context, ...@@ -276,10 +277,11 @@ static int init_resampler(AVCodecContext *input_codec_context,
} }
/** Initialize a FIFO buffer for the audio samples to be encoded. */ /** Initialize a FIFO buffer for the audio samples to be encoded. */
static int init_fifo(AVAudioFifo **fifo) static int init_fifo(AVAudioFifo **fifo, AVCodecContext *output_codec_context)
{ {
/** Create the FIFO buffer based on the specified output sample format. */ /** Create the FIFO buffer based on the specified output sample format. */
if (!(*fifo = av_audio_fifo_alloc(OUTPUT_SAMPLE_FORMAT, OUTPUT_CHANNELS, 1))) { if (!(*fifo = av_audio_fifo_alloc(output_codec_context->sample_fmt,
output_codec_context->channels, 1))) {
fprintf(stderr, "Could not allocate FIFO\n"); fprintf(stderr, "Could not allocate FIFO\n");
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
} }
...@@ -673,7 +675,7 @@ int main(int argc, char **argv) ...@@ -673,7 +675,7 @@ int main(int argc, char **argv)
&resample_context)) &resample_context))
goto cleanup; goto cleanup;
/** Initialize the FIFO buffer to store audio samples to be encoded. */ /** Initialize the FIFO buffer to store audio samples to be encoded. */
if (init_fifo(&fifo)) if (init_fifo(&fifo, output_codec_context))
goto cleanup; goto cleanup;
/** Write the header of the output file container. */ /** Write the header of the output file container. */
if (write_output_file_header(output_format_context)) if (write_output_file_header(output_format_context))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment