Ber*_*ard 6 command-line video files
.avi从命令行获取电影文件(在我的情况下)的比特率、帧率、宽度/高度等信息的最佳方法是什么?我正在寻找一种与 ImageMagicks 类似的基本工具identify。
跑步mplayer已经提供了这些信息(但还有更多):
VIDEO: [FMP4] 800x711 24bpp 25.000 fps 1320.9 kbps (161.2 kbyte/s)
Run Code Online (Sandbox Code Playgroud)
有没有办法mplayer只给出这个输出(我没有在 man 中找到它)或者是否有另一个标准的 bash 命令来获取相同的信息?
mplayer带有一个midentify实用程序,可以满足您的大部分需求。
输出看起来像变量赋值,所以它很容易在脚本中使用/易于解析。
如果midentify没有随您的mplayer软件包一起安装,您可能有一个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 <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)
的-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
...
Run Code Online (Sandbox Code Playgroud)
小智 5
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)
Run Code Online (Sandbox Code Playgroud)