FFMPEG kann die Dauer eines Videos nicht anzeigen

Ich versuche, mit ffmpeg Bilder aus einer Videodatei aufzunehmen, kann aber nicht einmal die Dauer eines Videos ermitteln. jedes Mal, wenn ich versuche, darauf zuzugreifenpFormatCtx->duration Ich bekomme 0. Ich kenne den Zeiger initialisiert und enthält die richtige Dauer denn wenn ich benutzeav_dump_format(pFormatCtx, 0, videoName, 0); dann bekomme ich tatsächlich die dauerdaten zusammen mit anderen informationen zum video. Das bekomme ich, wenn ich es benutzeav_dump_format(pFormatCtx, 0, videoName, 0);:

Eingabe # 0, avi, aus 'futurama.avi':

Dauer: 00: 21: 36,28, Start: 0,000000, Bitrate: 1135 kb / s

Stream Nr. 0.0: Video: mpeg4 (Advanced Simple Profile), yuv420p, 512 x 384

[PAR 1: 1 DAR 4: 3], 25 tbr, 25 tbn, 25 tbc

Stream Nr. 0.1: Audio: ac3, 48000 Hz, Stereo, s16, 192 kb / s

Ich verstehe nicht warumav_dum_format kann die Dauer anzeigen und ich kann nicht. Ich habe die Funktionsdefinition überprüft, um die Dauer anzuzeigen, die Funktion verwendet auch pFormatCtx-> duration. Es ist nicht nur die Dauer, für die andere Mitgliedsvariablen nicht die richtigen Daten anzeigen, wenn ich sie in main.cpp aufrufe

Hier ist meine main.cpp:

extern "C" {
    #include<libavcodec/avcodec.h>
    #include<libavformat/avformat.h>
    #include<libswscale/swscale.h>
}


int main(int argc, char *argv[]) {
    AVFormatContext *pFormatCtx = NULL;

    const char videoName[] = "futurama.avi";

    // Register all formats and codecs.
    av_register_all();
    cout << "Opening the video file";
    // Open video file
    int ret = avformat_open_input(&pFormatCtx, videoName, NULL, NULL) != 0;
    if (ret != 0) {
        cout << "Couldn't open the video file." << ret ;
        return -1;
    }
    if(avformat_find_stream_info(pFormatCtx, 0) < 0) {
        cout << "problem with stream info";
        return -1;
    }

    av_dump_format(pFormatCtx, 0, videoName, 0);
    cout << pFormatCtx->bit_rate << endl; // different value each time, not initialized properly.
    cout << pFormatCtx->duration << endl; // 0
    return 0;
}

Ich weiß nicht, ob es hilft, aber ich benutze QtCreator auf Ubuntu und verknüpfe die Bibliotheken statisch.

Danke für deine Hilfe.

Antworten auf die Frage(3)

Ihre Antwort auf die Frage