Post

Determine the length of mp4 file

A short bash loop using ffmpeg to determine the duration of multiple MP4 files.

This bash one-liner loops through a list of MP4 files and uses ffmpeg to extract the duration of each file. The grep, awk, and tr pipeline parses the duration value from ffmpeg’s stderr output.

1
2
3
4
for i in file1.mp4 file2.mp4 file3.mp4   ; do
    t=$(ffmpeg -i $i  2>&1 | grep Duration | awk '{print $2}' | tr -d ,);
    echo " $t: $i";
done
This post is licensed under CC BY 4.0 by the author.