From the following ffmpeg -i
output, how would I get the length (00:35)--
$ ffmpeg -i 1video.mp4
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/Users/david/Desktop/1video.mp4':
Metadata:
major_brand : isom
minor_version : 1
compatible_brands: isomavc1
creation_time : 2010-01-24 00:55:16
Duration: 00:00:35.08, start: 0.000000, bitrate: 354 kb/s
Stream #0.0(und): Video: h264 (High), yuv420p, 640x360 [PAR 1:1 DAR 16:9], 597 kb/s, 25 fps, 25 tbr, 25k tbn, 50 tbc
Metadata:
creation_time : 2010-01-24 00:55:16
Stream #0.1(und): Audio: aac, 44100 Hz, stereo, s16, 109 kb/s
Metadata:
creation_time : 2010-01-24 00:55:17
At least one output file must be specified
You can use the shell
for latest version :
Now $output will hold your duration of video input.mp4
format will be: hh:mm:ss.ms
e.g 00:02:17.25
This way you get the duration in seconds. I think this is more convenient.
ffprobe comes with ffmpeg so you should have it.
EDIT: For a more dedicated version you could use for example
Instead of JSON you could also use e.g. CSV or XML. For more output options look here http://ffmpeg.org/ffprobe.html#Writers
Format (container) duration:
Adding the
-sexagesimal
option will use theHOURS:MM:SS.MICROSECONDS
time unit format:Duration of the first video stream:
https://trac.ffmpeg.org/wiki/FFprobeTips#Duration
should work. Whatever your language's
$1
is will be the hours,$2
will be the minutes,$3
will be the seconds, and$4
will be just the centiseconds if they are exist.Do you want to do this in a bare shell pipeline, or read the result in a calling program?
… is a PCRE that will split the result up (replace the
\.
with[;:.]
if ffmpeg might output the duration in frames rather than fractional seconds). In a Unix pipeline:There are of course a billion other ways to express this.