How to encode audio to AAC with profile FF_PROFILE_AAC_LOW

我只是一个虾纸丫 提交于 2019-12-12 03:24:41

问题


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?


回答1:


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).



来源:https://stackoverflow.com/questions/37239113/how-to-encode-audio-to-aac-with-profile-ff-profile-aac-low

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!