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

tom*_*dxw 11 shell

以下工作非常好地确定各种音频/视频文件的长度:

mplayer -identify file.ogg 2>/dev/null | grep ID_LENGTH
Run Code Online (Sandbox Code Playgroud)

但是,我想杀死mplayer的输出,这样我就可以更有效地确定许多文件的长度.我怎么做?

eph*_*ent 15

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
                        }'
Run Code Online (Sandbox Code Playgroud)

-frames 0品牌mplayer立即退出,并-vo null -ao null防止它试图打开任何视频或音频设备.这些选项都记录在案man mplayer.


cod*_*gic 5

FFMPEG可以以不同的格式提供相同的信息(并且不会尝试播放文件):

ffmpeg -i <myfile>
Run Code Online (Sandbox Code Playgroud)

  • @Inaimathi:是的,``ffprobe &lt;myfile&gt;`` 就是这样做的。 (2认同)