在android中,AvcodeContex的宽度和高度返回零

在android中,AvcodeContex的宽度和高度返回零,android,ffmpeg,sdl-2,Android,Ffmpeg,Sdl 2,不确定我在下面的代码中犯了什么错误。我正在尝试在android中使用ffmpeg 0.11和SDL2.0 问题: 为什么编解码器上下文的宽度和高度始终为零?。 int main(int argc, char *argv[]) { int flags; flags = SDL_INIT_VIDEO | SDL_INIT_TIMER; if (SDL_Init (flags)) { LOGD ("Could not intialize Video for

不确定我在下面的代码中犯了什么错误。我正在尝试在android中使用ffmpeg 0.11和SDL2.0

问题: 为什么编解码器上下文的宽度和高度始终为零?。

int main(int argc, char *argv[])
{

    int flags;
    flags = SDL_INIT_VIDEO | SDL_INIT_TIMER;

    if (SDL_Init (flags)) {
        LOGD ("Could not intialize Video for SDL: %s \n", SDL_GetError());
    }
    else 
        LOGD (" SUCCESS: SDL_Init ");

    // ffmpeg Register all services..
    ffmpeg_register_all (); 


    pFrame = avcodec_alloc_frame ();
    context = avformat_alloc_context();

    err = avformat_open_input (&context, "rtsp:ip:port", NULL, NULL);
    if ( err < 0) {
        __android_log_print(ANDROID_LOG_DEBUG, "ffmpegguard", "Unable to open rtsp... ");

        return -1;
    }

    for (i = 0; i < context->nb_streams; i++)
    {               
        // Find the Decoder.
        codec = avcodec_find_decoder(context->streams[i]->codec->codec_id);
        if (codec->type  == AVMEDIA_TYPE_VIDEO ) {
            __android_log_print(ANDROID_LOG_DEBUG, "ffmpegguard", "Found Video Streaming..  ");
            videoStreamIndex = i;

        }
    }

    // Play RTSP
    av_read_play(context);

    // Get Codec Context.
    pCodecCtx = context->streams[videoStreamIndex]->codec;
    if ( pCodecCtx == NULL )
        __android_log_print(ANDROID_LOG_DEBUG, "ffmpegguard", "CodecCtx is NULL>>> ");
    else
        __android_log_print(ANDROID_LOG_DEBUG, "ffmpegguard", "CodecCtx is <<<OK>>> ");


    //Find the Decoder.
    pCodec = avcodec_find_decoder (pCodecCtx->codec_id);
    avcodec_open2 (pCodecCtx, pCodec, NULL);


    int w = pCodecCtx->width;  // Why me getting 0 ? 
    int h = pCodecCtx->height;

    window = SDL_CreateWindow ("Test ffmpeg",SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, w, h, SDL_WINDOW_SHOWN|SDL_WINDOW_ALLOW_HIGHDPI);
    // What this HIGHDPI Means ??

    if ( window != NULL ) 
    {
        LOGD (" WINDOW CREATED.. , create Renderer ..");
        renderer = SDL_CreateRenderer (window, -1, 0);  
    }
    else
    {
        LOGD (" Invalid SDL Window ");  
    }
__android_log_print(ANDROID_LOG_DEBUG, "ffmpegguard", "Width and Height of PCodeccCtx.. %d .. %d " , w, h); 
    return 0;
}
intmain(intargc,char*argv[])
{
国际旗帜;
flags=SDL_INIT_VIDEO | SDL_INIT_计时器;
if(SDL_Init(标志)){
LOGD(“无法初始化SDL的视频:%s\n”,SDL_GetError());
}
其他的
LOGD(“SUCCESS:SDL_Init”);
//ffmpeg注册所有服务。。
ffmpeg_register_all();
pFrame=avcodec_alloc_frame();
context=avformat_alloc_context();
err=avformat\u open\u输入(&context,“rtsp:ip:port”,NULL,NULL);
如果(误差<0){
__安卓日志打印(安卓日志调试,“FFMPEGUARD”,“无法打开rtsp…”);
返回-1;
}
对于(i=0;inb\u streams;i++)
{               
//找到解码器。
codec=avcodec\u find\u解码器(上下文->流[i]->codec->codec\u id);
如果(编解码器->类型==AVMEDIA\u类型\u视频){
__安卓日志打印(安卓日志调试,“FFMPEGUARD”,“发现视频流…”);
视频流指数=i;
}
}
//播放RTSP
视听阅读播放(上下文);
//获取编解码器上下文。
PCODECTX=上下文->流[videoStreamIndex]->编解码器;
if(pCodecCtx==NULL)
__android_log_print(android_log_DEBUG,“ffmpeguard”,“CodecCtx为空>>>”;
其他的
__android_log_print(android_log_DEBUG,“ffmpegguard”,“CodecCtx is”);
//找到解码器。
pCodec=avcodec\u find\u解码器(pCodecCtx->codec\u id);
avcodec_open2(pCodecCtx、pCodec、NULL);
int w=pCodecCtx->width;//为什么我得到0?
int h=PCODECTX->高度;
window=SDL_CreateWindow(“测试ffmpeg”,SDL_WINDOWPOS_未定义,SDL_WINDOWPOS_未定义,w,h,显示SDL_window|SDL_window_允许_HIGHDPI);
//这个HIGHDPI是什么意思??
如果(窗口!=NULL)
{
LOGD(“窗口创建..,创建渲染器..”);
渲染器=SDL_CreateRenderer(窗口,-1,0);
}
其他的
{
LOGD(“无效SDL窗口”);
}
__安卓日志打印(安卓日志调试,“ffmpegguard”,“PCodeccCtx的宽度和高度..%d..%d”,w,h);
返回0;
}
在代码中添加avformat\u stream\u info()函数,它将显示高度和宽度