I have an m4a file containing two AAC-encoded audio streams. I want to decode it on Android with the ffmpeg library. However, avformat_open_input() fails with "Invalid data found when processing input".
This file was created (i.e. the audio data encoded) with the same library.
I've double-checked the accuracy of the file path I provide to the call.
The file doesn't appear to be corrupt. It plays with QuickTime player, and ffprobe reports the output below.
I've looked at the source in ffmpeg's utils.c but it's not clear at which of several points (including nested calls) this invalidity of the data in the file is being decided.
FFPROBE OUTPUT
built with gcc 7.2.0 (crosstool-NG fa8859cb)
configuration: --prefix=/home/ubuntu/miniconda3 --disable-doc --enable-
shared --extra-cflags='-fPIC -I/home/ubuntu/miniconda3/include' --extra-
cxxflags='=-fPIC' --extra-libs='-L/home/ubuntu/miniconda3/lib -lz' --enable-
pic --disable-static --disable-gpl --disable-nonfree --disable-openssl --
enable-libvpx --cc=/opt/conda/conda-
bld/ffmpeg_1530807717919/_build_env/bin/x86_64-conda_cos6-linux-gnu-cc --cxx=/opt/conda/conda-bld/ffmpeg_1530807717919/_build_env/bin/x86_64-conda_cos6-linux-gnu-c++ --enable-libopus
libavutil 55. 78.100 / 55. 78.100
libavcodec 57.107.100 / 57.107.100
libavformat 57. 83.100 / 57. 83.100
libavdevice 57. 10.100 / 57. 10.100
libavfilter 6.107.100 / 6.107.100
libswscale 4. 8.100 / 4. 8.100
libswresample 2. 9.100 / 2. 9.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'recording-2019-09-03-110626.m4a':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2mp41
encoder : Lavf58.27.103
Duration: 00:00:05.04, start: 0.000000, bitrate: 637 kb/s
Stream #0:0(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 314 kb/s (default)
Metadata:
handler_name : SoundHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 315 kb/s (default)
Metadata:
handler_name : SoundHandler
The call that fails with "invalid data found" is:
if ( (ret = avformat_open_input( &inputFormatContext, filePath, 0, 0)) < 0 )
{
__android_log_print(ANDROID_LOG_DEBUG, "MyTag", "Could not open input file '%s' error %s ", filePath, av_err2str(ret) );
return false;
}
I would expect this to "just work" since I encoded and muxed the two audio tracks with the same build of the ffmpeg libraries.
When I built the libraries, I configured the build with:
--enable-decoder=aac,pcm_s16le --enable-encoder=aac,pcm_s16le --enable-demuxer=mp4,wav --enable-muxer=mp4,wav --enable-protocol=file,http
When I iterate through the codecs using av_codec_iterate() and look for supported sample rates I see:
Found codec aac
supported sample rate 96000
supported sample rate 88200
supported sample rate 64000
supported sample rate 48000
supported sample rate 44100
supported sample rate 32000
supported sample rate 24000
supported sample rate 22050
supported sample rate 16000
supported sample rate 12000
supported sample rate 11025
supported sample rate 8000
supported sample rate 7350
Found codec pcm_s16le
Found codec aac
Found codec pcm_s16le
Each codec appears twice, which I thought was maybe the encoder and decoder. But I note that only one has any supported sample rates. My test files' sample rate is 44100.
Any thoughts on what other things I can check for? I wondered whether I should create and pass an AVInputFormat object explicitly to the call, based upon what I know about the contents of the file. But I don't know how to construct one.