【问题标题】:Using mplayer to determine length of audio/video file使用 mplayer 确定音频/视频文件的长度
【发布时间】:2010-10-04 14:29:41
【问题描述】:

以下方法可以很好地确定各种音频/视频文件的长度:

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

但是,我想终止 mplayer 的输出,以便更有效地确定许多文件的长度。我该怎么做?

【问题讨论】:

  • 您能以问题的形式给出您的答案吗?

标签: shell


【解决方案1】:

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

【讨论】:

    【解决方案2】:

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

    ffmpeg -i <myfile>
    

    【讨论】:

    • 有没有办法调用它,这样它就不会抱怨没有输出文件?它工作得很好,但是如果你试图从另一个程序调用它,那么非0 退出代码很烦人。此外,Wheezy 建议使用avconv 而不是ffmpeg
    • @Inaimathi:是的,ffprobe &lt;myfile&gt; 就是这么做的。
    【解决方案3】:

    除了@codelogic的方法之外,还有另一种FF-way,不会报错退出:

    ffprobe <file>
    

    并查找持续时间条目。

    或者直接在错误流中对其进行grep:

    ffprobe <file> 2> >(grep Duration)
    

    【讨论】:

    • 为什么 error streamffprobe 中? ffmpeg 产生错误。
    • @Time: ffprobe 打印到错误流,尽管它没有以错误代码退出。不知道为什么会这样。
    【解决方案4】:

    看起来还有一些其他可用的库,请参阅time length of an mp3 file

    【讨论】:

      【解决方案5】:

      下载您的 .mp3 文件,使用播放器(例如 Windows Media Player)播放,播放器将在播放结束时显示总时间。

      【讨论】:

      • 此操作将阻止用户在自动化中运行此类任务,这很可能是他正在尝试做的事情。
      猜你喜欢
      • 2011-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多