2009-01-30 106 views
9

下面的作品非常漂亮,以确定各种音频/视频文件的长度:用mplayer来确定音频/视频文件的长度

mplayer -identify file.ogg 2>/dev/null | grep ID_LENGTH 

不过,我要杀死MPlayer的输出,所以我能确定的长度许多文件更高效。我怎么做?

+2

你可以说出一个问题的形式你的答案吗? – AShelly 2009-01-30 23:31:42

回答

14

MPlayer源附带称为midentify一个示例脚本,它看起来像这样:

#!/bin/sh 
# 
# This is a wrapper around the -identify functionality. 
# It is supposed to escape the output properly, so it can be easily 
# used in shellscripts by 'eval'ing the output of this script. 
# 
# Written by Tobias Diedrich <[email protected]> 
# Licensed under GNU GPL. 

if [ -z "$1" ]; then 
     echo "Usage: midentify.sh <file> [<file> ...]" 
     exit 1 
fi 

mplayer -vo null -ao null -frames 0 -identify "[email protected]" 2>/dev/null | 
     sed -ne '/^ID_/ { 
          s/[]()|&;<>`'"'"'\\!$" []/\\&/g;p 
         }' 

-frames 0使得mplayer立即退出,而-vo null -ao null防止它试图打开任何视频或音频设备。这些选项全部记录在man mplayer中。

5

FFMPEG可以给你以不同的格式相同的信息(而不会尝试播放文件):

ffmpeg -i <myfile> 
+0

有没有办法调用它,以便它不会抱怨没有输出文件?它很好地工作,但如果你试图从另一个程序调用它,非`0`退出代码很烦人。此外,Wheezy建议使用`avconv`而不是`ffmpeg`。 – Inaimathi 2012-10-09 03:45:35

1

有除了@ codelogic的方法,它不会退出一个错误另一FF-方式:

ffprobe <file> 

,并期待持续时间输入。

直接在错误流

或者用grep吧:

ffprobe <file> 2> >(grep Duration)