ffmpeg compilation problem: avcodec_find_decoder a

2019-04-29 04:05发布

问题:

I recently tried to upgrade the ffmpeg libraries I use in my Mac OS X application by downloading and compiling ffmpeg from source.

My code works correctly with pre-compiled libraries of the same version on windows. On Mac OS X, the library appears to work (it can open the file and find the streams and codecs used), but when it gets to avcodec_find_decoder, this function always returns null.

The code has worked with an older version of the library (compiled a year ago on Mac OS X 10.5)

I configured fmpeg using

./configure --extra-cflags="-arch i386" --extra-ldflags='-arch i386' --arch=x86_32 --target-os=darwin --enable-cross-compile --disable-indev=jack --enable-shared --disable-static

I checked config.mak, and it appears to have the decoders for the file types I tried enabled (ogg, vorbis, avi, mkv, ...) I also checked that the correct header files have been used and that the newly compiled library is used.

I have found only some older posts relating to this issue, but without any solution:

http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/2007-January/021399.html

http://libav-users.943685.n4.nabble.com/avcodec-find-decoder-problem-td944800.html

Edit: checking further, it appears av_codec_next(NULL) returns null as well, which means there isn't a single codec available, or that first_avcodec in utils.c is not set (I actually haven't found at all where this variable is set, I would have assumed av_register_all, but I can't find it there)

回答1:

I've found a solution for my problem, even though I would still be interested if anyone can help me with an explanation of my problem.

Basically, I was calling only av_register_all() at the top of my function. Now when adding avcodec_register_all() after this, my code works again. I don't understand why though, because avcodec_register_all() should be called by av_register_all() from looking at the source code.

See http://www.ffmpeg.org/doxygen/trunk/allformats_8c-source.html#l00039 for the source code



回答2:

in av_register_all():

static int initialized;
if (initialized)  
    return;
initialized = 1;
avcodec_register_all();

Maybe due to some unnoticed factors, the static int variable "initialized" has been initialized while the avcodec has not been registered...Then we should call avcodec_register_all() to explicitly fulfill it. But I am inclined to think that it is a bug in ffmpeg.



标签: macos ffmpeg