QtAV icon indicating copy to clipboard operation
QtAV copied to clipboard

play music some times produce sigsegv in VideoDecoderFFmpegBase::decode at avcodec_decode_video2

Open SGD9919 opened this issue 3 years ago • 0 comments

class: VideoDecoderFFmpegBase

part: ret = avcodec_decode_video2(d.codec_ctx, d.frame, &got_frame_ptr,sendPacket);

debug: I use qtcreator find d.codec_ctx is 0x0; I got an qt wanning log Audio Decode failed in console The problem is random, and it is normal for the music file to play again。

may resolve: check the codec_ctx is null or return false;

I add those in the decode function;I've been testing it for a while if(!d.codec_ctx||!d.is_open) { qWarning("codec context not ready"); return false; }

deep problem:

in AVDecoderPrivate at line 99; codec_ctx = avcodec_alloc_context3(NULL); in ffmpeg introduce: /**

  • Allocate an AVCodecContext and set its fields to default values. The
  • resulting struct should be freed with avcodec_free_context().
  • @param codec if non-NULL, allocate private data and initialize defaults
  •          for the given codec. It is illegal to then call avcodec_open2()
    
  •          with a different codec.
    
  •          If NULL, then the codec-specific defaults won't be initialized,
    
  •          which may result in suboptimal default settings (this is
    
  •          important mainly for encoders, e.g. libx264).
    
  • @return An AVCodecContext filled with default values or NULL on failure. */ AVCodecContext *avcodec_alloc_context3(const AVCodec *codec);

this function may return null ,but it is not check by any if code。

SGD9919 avatar Nov 17 '22 01:11 SGD9919