Using mplayer to determine length of audio/video file

后端 未结 5 2216
不思量自难忘°
不思量自难忘° 2021-02-14 00:21

The following works very nicely to determine the length of various audio/video files:

mplayer -identify file.ogg 2>/dev/null | grep ID_LENGTH
<
5条回答
  •  借酒劲吻你
    2021-02-14 00:33

    The MPlayer source ships with a sample script called midentify, which looks like this:

    #!/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 
    # Licensed under GNU GPL.
    
    if [ -z "$1" ]; then
            echo "Usage: midentify.sh  [ ...]"
            exit 1
    fi
    
    mplayer -vo null -ao null -frames 0 -identify "$@" 2>/dev/null |
            sed -ne '/^ID_/ {
                              s/[]()|&;<>`'"'"'\\!$" []/\\&/g;p
                            }'
    

    The -frames 0 makes mplayer exit immediately, and the -vo null -ao null prevent it from trying to open any video or audio devices. These options are all documented in man mplayer.

提交回复
热议问题