FFMPEG Dekodierung geht nicht



  • hi,
    Ich habe ein FFMPEG Dekodierprogramm in Visual C++ 2008 geschrieben.

    Ich möchte den videoStream initialisieren der eine Datei einliest, aber die videoStreamnumber liefert mir immer den Wert null.

    Zudem bekomme ich immer Fehlermeldung. Bei jedem Format eine andere! Z.B. bei Mpeg1 : "max_analyze_duration_reached". Was ist falsch?

    Hier der Code:

    #include "stdafx.h"
    #include <stdlib.h>
    #include <stdio.h>
    #include <string.h>
    #include <math.h>
    
    extern "C" {
    //The mainlibraries
    #include <libavformat/avformat.h>
    #include <libavcodec/avcodec.h>
    #include <libavutil/avutil.h>
    //additional functions
    #include <libavutil/mathematics.h>
    }
    //I need this for the Sleepfunction
    #include <windows.h>
    
    int main(int argc, char *argv[])
    {
    AVFormatContext *pFormatCtx;
    int i, videoStream;
    AVCodecContext *pCodecCtx;
    AVCodec *pCodec;
    AVFrame *pFrame;
    AVFrame *pFrameRGB;
    int numBytes;
    uint8_t *buffer;
    
    //register all codecs
    av_register_all();
    
    //open file for input (autodetect)
    if(av_open_input_file(&pFormatCtx, "test.mpg", NULL, 0, NULL)!=0)
    {
    fprintf(stderr, "cant open inputfile! %s\n", "test.avi");
    Sleep(2000);
    exit(1);
    }
    
    //get the stream
    if(av_find_stream_info(pFormatCtx)<0) //Here I get some errors like: max_analyze_duration_reached
    {
    fprintf(stderr, "cant initialize the Stream %s\n", "test.mpg");
    Sleep(2000);
    exit(1);
    }
    
    // Find the first video stream
    videoStream=-1;
    for(i=0; i<pFormatCtx->nb_streams; i++)
    if(pFormatCtx->streams[i]->codec->codec_type==CODEC_TYPE_VIDEO)
    {
    videoStream=i;
    break;
    }
    if(videoStream==-1)
    {
    fprintf(stderr, "Didnt find any videostream! %s\n");
    Sleep(2000);
    exit(1);
    }
    
    //Print the number of the videoStream! --------- Its always <null>
    fprintf(stderr, "Videostreamnr: %s\n",videoStream);
    Sleep(2000);
    
    // Get a pointer to the codec context for the video stream
    pCodecCtx=pFormatCtx->streams[videoStream]->codec;
    
    // Find the decoder for the video stream
    pCodec=avcodec_find_decoder(pCodecCtx->codec_id);
    if(pCodec==NULL)
    fprintf(stderr, "Codec not found! %s\n");; // Codec not found
    
    // Inform the codec that we can handle truncated bitstreams -- i.e.,
    // bitstreams where frame boundaries can fall in the middle of packets
    if(pCodec->capabilities & CODEC_CAP_TRUNCATED)
    pCodecCtx->flags|=CODEC_FLAG_TRUNCATED;
    
    // Open codec
    if(avcodec_open(pCodecCtx, pCodec)<0)
    fprintf(stderr, "Cant open codec! %s\n");
    //Allokiere VideoFrame
    pFrame=avcodec_alloc_frame();
    
    printf("Video decoding\n");
    
    }
    

    Gruß Profcoder


Anmelden zum Antworten