I try to encode audio to AAC with profile FF_PROFILE_AAC_LOW
by the following settings.
oc_cxt->profile = FF_PROFILE_AAC_LOW;
Also from the output of av_dump_format
, I got this
Metadata:
encoder : Lavf57.36.100
Stream #0:0: Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 192 kb/s
But the output is different. Everything is ok, except the output is AAC
, not AAC (LC)
. By using ffprobe
to detect, the output information is
$ ffprobe o.m4a
...
Stream #0:0(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 195 kb/s (default)
...
AAC (LC)
is the desired result I need.
But from the command line, ffmpeg
can generate AAC (LC)
output. Below is a small test.
$ ffmpeg -f lavfi -i aevalsrc="sin(440*2*PI*t):d=5" aevalsrc.m4a
$ ffprobe aevalsrc.m4a
...
Stream #0:0(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 69 kb/s (default)
...
How can I select FF_PROFILE_LOW
to get AAC (LC)
output?
This was caused by new ffmpeg api which I didn't notice.
The extra data need to copy back to AVStream->codecpar->extradata
after avcodec_open2
. After that, the ffprobe can detect output is the format I need, AAC (LC)
.
The following is a code snippet from ffmpeg.c
if (!ost->st->codecpar->extradata && avctx->extradata) {
ost->st->codecpar->extradata = av_malloc(avctx->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
if (!ost->st->codecpar->extradata) {
av_log(NULL, AV_LOG_ERROR, "Could not allocate extradata buffer to copy parser data.\n");
exit_program(1);
}
ost->st->codecpar->extradata_size = avctx->extradata_size;
memcpy(ost->st->codecpar->extradata, avctx->extradata, avctx->extradata_size);
}
Hopefully it would be helpful to anyone use the latest version of ffmpeg (3.x).