下面的作品非常漂亮,以确定各种音频/视频文件的长度:用mplayer来确定音频/视频文件的长度
mplayer -identify file.ogg 2>/dev/null | grep ID_LENGTH
不过,我要杀死MPlayer的输出,所以我能确定的长度许多文件更高效。我怎么做?
下面的作品非常漂亮,以确定各种音频/视频文件的长度:用mplayer来确定音频/视频文件的长度
mplayer -identify file.ogg 2>/dev/null | grep ID_LENGTH
不过,我要杀死MPlayer的输出,所以我能确定的长度许多文件更高效。我怎么做?
的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
中。
FFMPEG可以给你以不同的格式相同的信息(而不会尝试播放文件):
ffmpeg -i <myfile>
有没有办法调用它,以便它不会抱怨没有输出文件?它很好地工作,但如果你试图从另一个程序调用它,非`0`退出代码很烦人。此外,Wheezy建议使用`avconv`而不是`ffmpeg`。 – Inaimathi 2012-10-09 03:45:35
貌似有提供一些其他的库,看到time length of an mp3 file
有除了@ codelogic的方法,它不会退出一个错误另一FF-方式:
ffprobe <file>
,并期待持续时间输入。
直接在错误流或者用grep吧:
ffprobe <file> 2> >(grep Duration)
你可以说出一个问题的形式你的答案吗? – AShelly 2009-01-30 23:31:42