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

Harit Vishwakarma picture Harit Vishwakarma · Sep 30, 2013 · Viewed 18k times · Source

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 file formats.

Answer

Harit Vishwakarma picture Harit Vishwakarma · Sep 30, 2013

Use the following commands:

i) To get the duration of video stream:

$ mediainfo --Inform="Video;%Duration%"  [inputfile]

ii) To get the duration of the media file:

$ mediainfo --Inform="General;%Duration%" [inputfile]

iii) To get the duration of audio stream only:

$ mediainfo --Inform="Audio;%Duration%" [inputfile]

iv) To get values of more than one parameter:

$ mediainfo --Inform="Video;%Width%,%Height%,%BitRate%,%FrameRate%" [inputfile]

Output would be something like this:

1280,720,3000000,30.0