web-dev-qa-db-ja.com

コマンドラインから.aviファイル情報を取得する

ムービーファイルのビットレート、フレームレート、幅/高さなどの情報を取得するための最良の方法は何ですか(私の場合は.avi)コマンドラインから? ImageMagicks identifyと同様に機能する基本的なツールを探しています。

mplayerを実行すると、すでにこの情報が得られます(ただし、さらに多くの情報が得られます)。

VIDEO:  [FMP4]  800x711  24bpp  25.000 fps  1320.9 kbps (161.2 kbyte/s)

mplayerにこの出力のみを提供させる方法はありますか(私はそれを男性に見つけられませんでした)、または同じ情報を取得するための別の標準のbashコマンドがありますか?

6
Bernhard

mplayerにはmidentifyユーティリティが付属しており、ほとんどの場合、必要な処理を実行します。

出力は変数の割り当てのように見えるので、スクリプトで使用するのは非常に簡単で、解析も簡単です。

midentifymplayerパッケージと一緒にインストールされていない場合は、midentify.sh/usr/share/mplayerスクリプトがある可能性があります。そうでない場合、midenfifyは特定の引数のセットを使用してmplayerを実行します。

#!/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 "$@" 2>/dev/null |
    sed -ne '/^ID_/ {
                      s/[]()|&;<>`'"'"'\\!$" []/\\&/g;p
                    }'

-ao-vo、および-framesパラメーターは、mplayerが実際にクリップを再生するのを防ぎます。残りはフォーマットだけです。

例:

$ midentify some_random.avi 
ID_VIDEO_ID=0
ID_AUDIO_ID=0
...
ID_VIDEO_BITRATE=258488
ID_VIDEO_WIDTH=320
ID_VIDEO_HEIGHT=240
ID_VIDEO_FPS=29.917
...
ID_LENGTH=4216.76
...
ID_AUDIO_BITRATE=64000
ID_AUDIO_RATE=22050
...
6
Mat

mediainfo コマンドも多くの情報を提供します:

$ mediainfo IMGP3793.AVI 
General
Complete name                            : IMGP3793.AVI
Format                                   : AVI
Format/Info                              : Audio Video Interleave
File size                                : 121 MiB
Duration                                 : 2mn 16s
Overall bit rate                         : 7 439 Kbps

Video
ID                                       : 0
Format                                   : JPEG
Codec ID                                 : MJPG
Duration                                 : 2mn 16s
Bit rate                                 : 7 339 Kbps
Width                                    : 640 pixels
Height                                   : 480 pixels
Original height                          : 960 pixels
Display aspect ratio                     : 4:3
Frame rate                               : 30.288 fps
Color space                              : YUV
Chroma subsampling                       : 4:2:2
Bit depth                                : 8 bits
Scan type                                : Interlaced
Compression mode                         : Lossy
Bits/(Pixel*Frame)                       : 0.789
Stream size                              : 119 MiB (99%)

Audio
ID                                       : 1
Format                                   : PCM
Format settings, Endianness              : Little
Format settings, Sign                    : Unsigned
Codec ID                                 : 1
Duration                                 : 2mn 16s
Bit rate mode                            : Constant
Bit rate                                 : 88.2 Kbps
Channel count                            : 1 channel
Sampling rate                            : 11.025 KHz
Bit depth                                : 8 bits
Stream size                              : 1.44 MiB (1%)
Alignment                                : Aligned on interleaves
Interleave, duration                     : 33 ms (1.00 video frame)
5
asalamon74

fileコマンドを使用できます。

2
Stone