0

ビデオのコーデック ID を取得するためのネイティブ メソッドを作成しましたが、アプリがこの行「avformat_find_stream_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;
}

質問: このようなストリーム情報の検索にいつも失敗するのはなぜですか? 修正を手伝ってください。ありがとう

4

1 に答える 1

1

コードのいくつかの場所で pFmtCtx の代わりに pFormatCtx (初期化されていません) を使用しています!

pFormatCtx = pFmtCtxavformat_alloc_context() の後に設定できます。

于 2013-04-22T12:27:50.117 に答える