How to find duration of a video file using mediainfo in seconds or other formats?

后端 未结 3 621
时光说笑
时光说笑 2020-12-28 10:51

How can I find duration of a video file in miliseconds i.e. in integer in deterministic way. I have used ffprobe to get the duration but it doesn\'t give duration for all fi

3条回答
  •  心在旅途
    2020-12-28 11:30

    As offered by iota to use mediainfo --Inform="Video;%Duration%" [inputfile], possible but returns weird results.

    For example, for video with duration 31s 565ms the output of given command would be:

    31565
    

    It wasn't suitable for me and I came up to the following solution:

    mediainfo --Inform="Video;%Duration/String3%" inputExample.webm
    

    Returned value is:

    00:00:31.565
    

    After all, you could just format returned value with, let's say PHP, to convert it to seconds, e.g.:

    $parsed = date_parse( '00:00:31.565' );
    echo $parsed['hour'] * 3600 + $parsed['minute'] * 60 + $parsed['second'];
    

    Example

提交回复
热议问题