[FFmpeg-user] How to get video duration in a script using ffmpeg?

Bo Berglund bo.berglund at gmail.com
Thu Jan 20 16:08:15 EET 2022


On Wed, 19 Jan 2022 20:30:32 +0200, Peter van den Houten <petervdh at gmail.com>
wrote:

>On 19/01/2022 20:12, Shupert, Jim via ffmpeg-user wrote:
>> I have used mediainfo
>>
>> mediainfo --Inform="Video;%Duration/String3%" $SrcDir/${f%.*}.*  > $HOME/t.txt
>> trt=$(<$HOME/t.txt)
>>
>This is more accurate for bitrate as it doesn't read headers but does sample reads of the file (some formats do not express bitrate in the headers). It therefore takes a bit longer:
>
>mediainfo --parsespeed=1 filename
>

Just for curiosity I installed mediainfo and tested:

mediainfo --parsespeed=1 2022-01-20_07Testvideo.mp4 | grep Duration
Duration                                 : 43 min 31 s
Duration                                 : 43 min 31 s
Duration                                 : 43 min 31 s

So it creates 3 instances of the duration output...
Have to add  | tail -n 1 to the end to get one item only.

I think the ffprobe solution is what I'd choose, does not require installing any
additional program too.


-- 
Bo Berglund
Developer in Sweden



More information about the ffmpeg-user mailing list