具有持续时间的媒体文件列表


2

我想从所有符合下面模式的文件夹中获取mp4文件列表及其相应的持续时间

例如:LO1 / LO1.MP4,LO3 / LO3.MP4

我尝试了以下但是我得到了多个条目以及我无法弄清楚文件名:


$ 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

那么如何获取文件名列表(.mp4)及其相应的持续时间?

Answers:


5

我不知道mediainfo的输出,但这就是我的工作方式 使用ffrobe(或ffmpeg -i)这将获得持续时间

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

使用find将获取您的文件名

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

因此,您可以将所有内容整合在一起进行循环以获取列表

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

1
我更喜欢 -exec 这种类型的任务的查找标志,因为它们可以节省大量的进程分支: find [filter rules] -exec mediainfo \{\} + | grep [filter] 或者如果你没有找到GNU find [filter rules] -print0 | xargs -0 mediainfo | grep [filter]
David Foerster
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.