avcodec_find_decoder()-分段错误

avcodec_find_decoder()-分段错误,c,ffmpeg,C,Ffmpeg,这是我简单的ffmpeg代码 我正在从文件中读一个.ogg #include <libavcodec/avcodec.h> #include <libavformat/avformat.h> int main(int argc, char **argv){ av_register_all(); avcodec_register_all(); static const char *src_filenam

这是我简单的ffmpeg代码

我正在从文件中读一个.ogg

      #include <libavcodec/avcodec.h>
      #include <libavformat/avformat.h>
      int main(int argc, char **argv){
      av_register_all();
      avcodec_register_all();
      static const char *src_filename = NULL;
      static AVFormatContext *input_format_context = NULL;
      int ret; int error;
    
      
      src_filename = argv[1];
    
      //open audio file
      if ((error = avformat_open_input(&input_format_context, src_filename, NULL, NULL)) < 0) {
            av_log(NULL, AV_LOG_ERROR, "Cannot open input file\n");
            return ret;
        }else{
          fprintf(stderr, "open file +  \n");
        }

此错误的具体原因是什么?

您正在调用的是
error=avformat\u find\u stream\u info(input\u format\u context,NULL)
,但您正在下一行测试
ret
的值。改为检查
error
。我已经解决了这个问题,但这不是问题所在。代码卡在1.2和1.3之间@vmtar您确定
不为空吗?另外-很可能是不相关的,但您总是使用循环中的第一个流,您的代码暗示您要遍历所有流。无论如何,您可以使用调试符号进行编译,并使用调试器查看它。是的,先生。我已经检查过了。并与其他一些音频进行了测试。是一样的。“streams[0]”仅用于测试。当它是“streams[i]”时,我得到了相同的错误。
  // find stream info 
  error = avformat_find_stream_info(input_format_context, NULL);
  if (ret < 0) {
     av_log(NULL, AV_LOG_ERROR, "Cannot find stream information\n");
    }else{
      fprintf(stderr, "find stream +  \n");
      }
for (int i=0; i < input_format_context->nb_streams; i++) 
            {
          fprintf(stderr, "1.1\n");
                AVStream *stream = input_format_context->streams[0];
          fprintf(stderr, "1.2\n");
          
          AVCodec *dec = avcodec_find_decoder(stream->codecpar->codec_id);
          fprintf(stderr, "1.3\n");
            }
        
      return 0;
      }
cmake_minimum_required(VERSION 2.6)
project(decode_encode)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "-D__STDC_CONSTANT_MACROS")

find_path(AVCODEC_INCLUDE_DIR libavcodec/avcodec.h)
find_library(AVCODEC_LIBRARY avcodec)

find_path(AVFORMAT_INCLUDE_DIR libavformat/avformat.h)
find_library(AVFORMAT_LIBRARY avformat)

find_path(AVUTIL_INCLUDE_DIR libavutil/avutil.h)
find_library(AVUTIL_LIBRARY avutil)

find_path(AVDEVICE_INCLUDE_DIR libavdevice/avdevice.h)
find_library(AVDEVICE_LIBRARY avdevice)

add_executable(readFewFrame readFewFrame.c)

target_include_directories(readFewFrame PRIVATE ${AVCODEC_INCLUDE_DIR} ${AVFORMAT_INCLUDE_DIR} ${AVUTIL_INCLUDE_DIR} ${AVDEVICE_INCLUDE_DIR})
target_link_libraries(readFewFrame PRIVATE ${AVCODEC_LIBRARY} ${AVFORMAT_LIBRARY} ${AVUTIL_LIBRARY} ${AVDEVICE_LIBRARY})