首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AVCodecContex在android中返回零的宽度和高度。

AVCodecContex在android中返回零的宽度和高度。
EN

Stack Overflow用户
提问于 2014-02-04 16:53:05
回答 1查看 504关注 0票数 1

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

问:为什么CodecContext的宽度和高度总是为零?..

代码语言:javascript
复制
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;
}
EN

回答 1

Stack Overflow用户

发布于 2014-03-07 18:57:56

在代码中添加avformat_stream_info()函数,而不是显示高度和宽度

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21558538

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档