Qt World Summit: Register Today!

Get video file duration without playing it

  • Hi,

    I have a folder with a few video files (mostly .avi, .mp4). Is there a way to get their duration without playing them? I've tried using QVideoPlayer duartion() method, but it return the correct value only when playing the file. Also, it can only get the duration of one file, while I want to get the duration for multiple values.
    Is there a Qt way of doing it? If no, any other solution you recommend?


  • Lifetime Qt Champion


    The MediaInfo project might of interest here.

    Hope it helps

  • Thanks. Ended up really using mediainfo, got it with the following method

    int getVideoDuration(std::string fileName){
         MediaInfo MI;
        int duration = std::stoi(MI.Get(Stream_General, 0, "Duration"));
        return duration;

Log in to reply