shell – 使用mplayer来确定音频/视频文件的长度

前端之家收集整理的这篇文章主要介绍了shell – 使用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 <ranma+mplayer@tdiedrich.de>
# 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 "$@" 2>/dev/null |
        sed -ne '/^ID_/ {
                          s/[]()|&;<>`'"'"'\\!$" []/\\&/g;p
                        }'

-frames 0使mplayer立即退出,-vo null -ao null阻止它尝试打开任何视频或音频设备.这些选项都记录在man mplayer中.

猜你在找的Bash相关文章