2

I wanted to get a list of mp4 files and its corresponding duration from all the folders matching the pattern below

e.g: LO1/LO1.MP4,LO3/LO3.MP4

I tried following but I get multiple entries as well as I cant figure out the filename:


$ mediainfo /var/www/videos/L*/L*.mp4 | grep Duration
Duration                                 : 25mn 54s
Duration                                 : 25mn 54s
Material_Duration                        : 1554665
Duration                                 : 25mn 54s
Material_Duration                        : 1554688
Duration                                 : 37mn 21s
Duration                                 : 37mn 21s
Material_Duration                        : 2241664
Duration                                 : 37mn 21s
Material_Duration                        : 2241696
Duration                                 : 26mn 6s
Duration                                 : 26mn 6s
Duration                                 : 26mn 6s
Duration                                 : 30mn 41s
Duration                                 : 30mn 41s
Duration                                 : 30mn 41s
Duration                                 : 39mn 41s
Duration                                 : 39mn 41s
Duration                                 : 39mn 41s
Duration_LastFrame                       : -7ms
Duration                                 : 37mn 2s
Duration                                 : 37mn 2s
Duration                                 : 37mn 2s
Duration_LastFrame                       : -12ms
Duration                                 : 34mn 24s
Duration                                 : 34mn 24s
Duration                                 : 34mn 24s
Duration                                 : 31mn 7s
Duration                                 : 31mn 7s
Duration                                 : 31mn 7s
Duration                                 : 31mn 57s
Duration                                 : 31mn 57s
Duration                                 : 31mn 57s
Duration                                 : 29mn 30s
Duration                                 : 29mn 30s
Duration                                 : 29mn 30s
Duration                                 : 36mn 28s
Duration                                 : 36mn 28s
Duration                                 : 36mn 27s
Material_Duration                        : 2187988

So how can I get a list of filenames(.mp4) and its corresponding duration?

5

I don't know the output from mediainfo, but this is how I do it using ffrobe (or ffmpeg -i) this will get the duration

ffprobe $fn 2>&1|grep Duration|sed -e 's/^[ \t]*//'|cut -d" " -f2|cut -d. -f1

using find will obtain the file names for you

find /var/www/videos/L* -type f -name L\*.mp4

so you can pop the whole lot together in a little for loop to get your list

for fn in `find /var/www/videos/L* -type f -name L\*.mp4`;
do
    dur=`ffprobe $fn 2>&1|grep Duration|sed -e 's/^[ \t]*//'|cut -d" " -f2|cut -d. -f1`
    echo "$fn $dur"
done
| improve this answer | |
  • 1
    I prefer the -exec flag of find for this type of task because they save a lot of process forks: find [filter rules] -exec mediainfo \{\} + | grep [filter] or if you dont have GNU find find [filter rules] -print0 | xargs -0 mediainfo | grep [filter]. – David Foerster Oct 15 '13 at 11:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.