android ndk - app crashed at avformat_find_stream_info -
i write native method codec id of video, app never pass line 'avformat_find_stream_info(pformatctx, null)' here native method:
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 file url: %s", error, in_file_name); return -1; } logi(1, "here 1 duration: %d", pfmtctx->duration); //app passed here /*retrieve 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 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 video stream"); return -1; // didn’t find video stream } // pointer codec context video stream pcctx=pformatctx->streams[videostream]->codec; avformat_free_context(pfmtctx); (*env)->releasestringutfchars(env, strinfile, in_file_name); return pcctx->codec_id; }
question: why fail finding stream info this? please me fix it. thanks
you using pformatctx (which not initialized) instead of pfmtctx in several places in code!
you set pformatctx = pfmtctx
after avformat_alloc_context():
Comments
Post a Comment