[FFmpeg-trac] #4722(avcodec:new): avcodec_alloc_context3 returns NULL - without error

FFmpeg trac at avcodec.org
Tue Jul 14 15:42:46 CEST 2015


#4722: avcodec_alloc_context3 returns NULL - without error
-----------------------------------+-------------------------------------
             Reporter:  TheSHEEEP  |                     Type:  defect
               Status:  new        |                 Priority:  important
            Component:  avcodec    |                  Version:  2.7
             Keywords:             |               Blocked By:
             Blocking:             |  Reproduced by developer:  0
Analyzed by developer:  0          |
-----------------------------------+-------------------------------------
 Summary of the bug:

 I am trying to decode an .ogg file containing vorbis audio.
 However, I cannot even avcodec_open2(), as avcodec_alloc_context3 returns
 NULL without logging any errors, so I have no idea what is wrong.
 Naturally, the following avcodec_open2 fails.

 It does not make a difference if I call avcodec_alloc_context3 with an
 AVCodec* or with NULL, it always returns a null-pointer.

 Please, do not return NULL pointer in this function.
 I have attached the file I used to test, but I doubt the file is the
 problem here, it can played fine with any player.

 Here is the code I use:

 {{{
     av_register_all();
     avcodec_register_all();
     av_log_set_callback(log_callback);
     av_log_set_level(AV_LOG_TRACE);

     int result = avformat_open_input(&_formatContext, fileName, NULL,
 NULL);
     if (result < 0)
     {
         char errorBuf[1024];
         av_make_error_string(errorBuf, 1024, result);
         LOG_DECODING << "ERROR: Could not open input: " << (_path +
 _fileName) << "\n"
                 << errorBuf;
         return;
     }

     // Read stream information
     if (avformat_find_stream_info(_formatContext, NULL) < 0)
     {
         LOG_DECODING << "ERROR: Could not find stream information: " <<
 (_path + _fileName);
         return;
     }

     AVStream* stream;
     AVCodec* decodeCodec = NULL;

     // Find the stream
     int streamIndex = av_find_best_stream(_formatContext, p_type, -1, -1,
 NULL, 0);
     if (streamIndex < 0)
     {
         LOG_DECODING << "ERROR: Could not find stream of type: " <<
 av_get_media_type_string(p_type);
         return false;
     }
     else
     {
         stream = _formatContext->streams[streamIndex];

         // Find decoder codec
         decodeCodec = avcodec_find_decoder(stream->codec->codec_id);
         if (!decodeCodec)
         {
             LOG_DECODING << "Failed to find codec: " <<
 av_get_media_type_string(p_type);
             return false;
         }

         // Allocate the context
         // THIS returns NULL
         decodeCodecContext = avcodec_alloc_context3(decodeCodec);

         // Open decode codec & context
         // With decodeCodecContext == NULL, this naturally fails
         int result = avcodec_open2(decodeCodecContext, decodeCodec, NULL);
         if (result < 0)
         {
             char errorBuf[1024];
             av_make_error_string(errorBuf, 1024, result);
             LOG_DECODING << "Failed to open codec: " <<
 av_get_media_type_string(p_type) << "\n    " << errorBuf;
             return false;
         }
     }
 }}}

--
Ticket URL: <https://trac.ffmpeg.org/ticket/4722>
FFmpeg <https://ffmpeg.org>
FFmpeg issue tracker


More information about the FFmpeg-trac mailing list