Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android ndk 应用程序在avformat\u find\u stream\u info处崩溃_Android Ndk_Ffmpeg - Fatal编程技术网

Android ndk 应用程序在avformat\u find\u stream\u info处崩溃

Android ndk 应用程序在avformat\u find\u stream\u info处崩溃,android-ndk,ffmpeg,Android Ndk,Ffmpeg,我编写了一个本机方法来简单地获取视频的编解码器id,但我的应用程序从未通过这一行“avformat\u find\u stream\u info(pFormatCtx,NULL)” 以下是我的原生方法: int get_video_info(JNIEnv *env, jobject thiz, jstring strInFile){ AVFormatContext *pFmtCtx; AVCodecContext *pCCtx; AVCodec *pCd; AVFrame *picture; i

我编写了一个本机方法来简单地获取视频的编解码器id,但我的应用程序从未通过这一行“avformat\u find\u stream\u info(pFormatCtx,NULL)” 以下是我的原生方法:

int get_video_info(JNIEnv *env, jobject thiz, jstring strInFile){
AVFormatContext *pFmtCtx;
AVCodecContext *pCCtx;
AVCodec *pCd;
AVFrame *picture;
int i, videoStream = -1, error = 0;

const char *in_file_name = (*env)->GetStringUTFChars(env, strInFile, NULL);

av_register_all();

LOGI(1, "HERE 0 %s", in_file_name); // app passed here

/*Open video file*/
pFmtCtx = avformat_alloc_context();
if((error=avformat_open_input(&pFmtCtx, in_file_name, NULL, NULL)) < 0){
    LOGE(1, "Couldn't open file, error-code: %d with file url: %s", error, in_file_name);
    return -1;
}

LOGI(1, "HERE 1 Duration: %d", pFmtCtx->duration); //app passed here

/*Retrieve the stream information, APP CRASH RIGHT HERE*/
if(avformat_find_stream_info(pFormatCtx, NULL)<0){
    LOGE(1, "Couldn't retrieve stream information");
    avformat_free_context(pFmtCtx);
    return -1; // Couldn’t find stream information
}

LOGI(1, "HERE 2");

//Find the first video stream
videoStream=-1;
for(i=0; i<pFormatCtx->nb_streams; i++) {
    if(pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO){
        videoStream=i;
        break;
    }
}

if(videoStream==-1){
    avformat_free_context(pFmtCtx);
    LOGE(1, "Didn't find a video stream");
    return -1; // Didn’t find a video stream
}

// Get a pointer to the codec context for the video stream
pCCtx=pFormatCtx->streams[videoStream]->codec;

avformat_free_context(pFmtCtx);
(*env)->ReleaseStringUTFChars(env, strInFile, in_file_name);
return pCCtx->codec_id;
}
int-get\u-video\u-info(JNIEnv*env、jobject-thiz、jstring-strInFile){
AVFormatContext*pFmtCtx;
AVCodecContext*pCCtx;
AVCodec*pCd;
AVFrame*图片;
inti,videoStream=-1,error=0;
const char*in_file_name=(*env)->GetStringUTFChars(env,strInFile,NULL);
av_寄存器_all();
LOGI(1,“此处0%s”,在_文件_名称中);//此处传递了应用程序
/*打开视频文件*/
pFmtCtx=avformat_alloc_context();
if((error=avformat\u open\u input(&pFmtCtx,in\u file\u name,NULL,NULL))<0){
LOGE(1,“无法打开文件,错误代码:%d,文件url:%s”,错误,文件名中);
返回-1;
}
LOGI(1,“此处1持续时间:%d”,pFmtCtx->Duration);//此处传递了应用程序
/*检索流信息,应用程序崩溃就在这里*/
如果(avformat\u find\u stream\u info(pFormatCtx,NULL)streams[i]->codec->codec\u type==AVMEDIA\u type\u VIDEO){
视频流=i;
打破
}
}
如果(视频流==-1){
avformat_free_上下文(pFmtCtx);
LOGE(1,“未找到视频流”);
return-1;//未找到视频流
}
//获取指向视频流的编解码器上下文的指针
pCCtx=pFormatCtx->流[视频流]->编解码器;
avformat_free_上下文(pFmtCtx);
(*env)->ReleaseStringUTFChars(env,strInFile,in_file_name);
返回pCCtx->codec_id;
}
问:为什么我总是找不到这样的流信息?请帮我修一下。谢谢

您在代码中的多个位置使用了pFormatCtx(未初始化)而不是pFmtCtx

您可以在avformat\u alloc\u context()之后设置
pFormatCtx=pFmtCtx