Length of a video file (.avi, .mpg) from the command line

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Length of a video file (.avi, .mpg) from the command line

Jean-Baptiste Thomas
Can anyone recommend a command line program that could tell me
the length of the video stream in a .avi or .mpg file ? Thanks
in advance.

Reply | Threaded
Open this post in threaded view
|

Re: Length of a video file (.avi, .mpg) from the command line

Dan Ritter-4
Jean-Baptiste Thomas wrote:
> Can anyone recommend a command line program that could tell me
> the length of the video stream in a .avi or .mpg file ? Thanks
> in advance.

If you invoke

mplayer -vo none -ao none <filename>

you will get a set of statistics which include the resolution,
frame rate, and encoding rate for both video and audio streams.

A little addition and division with the total size of the file
should get you a good idea.

ffmpeg -i <filename>

will do a similar set of stats, including doing some math for
you. (Look at "duration" in the output.)

However, everything is only *likely* to be correct, because
there are a number of encodings which can cause variable length.


-dsr-

Reply | Threaded
Open this post in threaded view
|

Re: Length of a video file (.avi, .mpg) from the command line

andy smith-10
In reply to this post by Jean-Baptiste Thomas
Hi,

On Wed, Aug 14, 2019 at 05:43:42PM +0200, Jean-Baptiste Thomas wrote:
> Can anyone recommend a command line program that could tell me
> the length of the video stream in a .avi or .mpg file ?

ffprobe from the ffmpeg package can extract the duration, and offers
programmatically-friendly output formats such as CSV, JSON and so
on.

    http://trac.ffmpeg.org/wiki/FFprobeTips#Duration

Cheers,
Andy

--
https://bitfolk.com/ -- No-nonsense VPS hosting

Reply | Threaded
Open this post in threaded view
|

Re: Length of a video file (.avi, .mpg) from the command line

Jonas Smedegaard-2
In reply to this post by Jean-Baptiste Thomas
Quoting Jean-Baptiste Thomas (2019-08-14 17:43:42)
> Can anyone recommend a command line program that could tell me
> the length of the video stream in a .avi or .mpg file ? Thanks
> in advance.

mediainfo

Ffmpeg and mpv also can do this, but IMO mediainfo is the right tool for
this specific task.


 - Jonas

--
 * Jonas Smedegaard - idealist & Internet-arkitekt
 * Tlf.: +45 40843136  Website: http://dr.jones.dk/

 [x] quote me freely  [ ] ask before reusing  [ ] keep private

Reply | Threaded
Open this post in threaded view
|

Re: Length of a video file (.avi, .mpg) from the command line

Michael Lange-2
In reply to this post by Jean-Baptiste Thomas
Hi,

On Wed, 14 Aug 2019 17:43:42 +0200 (CEST)
Jean-Baptiste Thomas <[hidden email]> wrote:

> Can anyone recommend a command line program that could tell me
> the length of the video stream in a .avi or .mpg file ? Thanks
> in advance.
>

as Jonas already suggested, I would use mediainfo, with for example

$ mediainfo --Inform="Video;%Duration/String3%" <videofile>

which will output something like:

01:58:39.029

See

$ mediainfo --Info-Parameters

for a list of possible output parameters and formats.

Regards

Michael

.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

On my planet, to rest is to rest -- to cease using energy.  To me, it
is quite illogical to run up and down on green grass, using energy,
instead of saving it.
                -- Spock, "Shore Leave", stardate 3025.2