[Libav-user] FFMPEG AVSampleFormat available formats array termination
Mariah Smith
mariah.cherice at gmail.com
Fri Sep 11 20:53:31 EEST 2020
Hello,
I am doing some AAC audio encoding for an Android app.
Audio samples from Google's Oboe library are packed so it makes sense to
keep the packed sample format when possible. When adding in a sample format
check, the documentation and examples state that the available sample
formats array should terminate with -1 (AV_SAMPLE_FMT_NONE). I'm not seeing
the array terminated correctly in my case.
I cannot use AV_SAMPLE_FMT_NB because I am dynamically linking to ffmpeg
binaries.
Here's the simple sample format check function:
int FrequencyEngine::check_sample_fmt(const AVCodec *codec, enum
AVSampleFormat sample_fmt) {
const enum AVSampleFormat *p = codec->sample_fmts;
const enum AVSampleFormat *f = codec->sample_fmts;
for (int i = 0; i < 13; i++) {
__android_log_print(ANDROID_LOG_VERBOSE, FREQUENCY_ENGINE_TAG,
"Encoder format supported %s, enum value %d",
av_get_sample_fmt_name(*f), *f);
f++;
}
while (AV_SAMPLE_FMT_NONE != *p) {
__android_log_print(ANDROID_LOG_VERBOSE, FREQUENCY_ENGINE_TAG,
"Searching format supported %s",
av_get_sample_fmt_name(*p));
if (*p == sample_fmt) {
__android_log_print(ANDROID_LOG_VERBOSE,
FREQUENCY_ENGINE_TAG, "Format found! %s",
av_get_sample_fmt_name(*p));
return 1;
}
p++;
}
return 0;
}
In this function I am just incrementing the pointer 13 times as that's the
max possible formats. Then I am also using a while loop on the sample
format pointer again (as I would in production code). This is where we
should be getting the -1 to terminate the array, but the -1 terminator is
the second entry in the array, see log printout:
[image: Screen Shot 2020-09-11 at 12.46.35 PM.png]
According to the while loop, the only available format would be
AV_SAMPLE_FMT_FLTP, evidenced by that being the one format before -1, but
when I explicitly set the format to AV_SAMPLE_FMT_FLT or any of the formats
listed in the log from the first for loop, the encoder accepts this format
still and works. Because of this discrepancy, I don't know how to properly
check available sample formats for production.
Regards,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20200911/35e046a4/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screen Shot 2020-09-11 at 12.46.35 PM.png
Type: image/png
Size: 97694 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20200911/35e046a4/attachment.png>
More information about the Libav-user
mailing list