如何从linux命令行获取视频文件的分辨率(宽度和高度)?

时间:2022-12-03 20:45:43

I've been digging through the mplayer/mencoder and ffmpeg documentation and I can't seem to come up with anything. I'm not especially picky as to the output format as I can use a regular expression to pull it out, I just can't seem to get the data in the first place.

我一直在查阅mplayer/mencoder和ffmpeg文档,但似乎什么都想不出来。对于输出格式,我不是特别挑剔,因为我可以使用正则表达式来提取它,我只是不能首先获得数据。

9 个解决方案

#1


11  

MediaInfo has a command line version and provides the dimensions together with tons of other information.

MediaInfo有一个命令行版本,并提供维度和大量其他信息。

#2


44  

Use ffprobe (part of FFmpeg toolkit)

使用ffprobe (FFmpeg工具包的一部分)

example:

例子:

ffprobe -v quiet -print_format json -show_format -show_streams ~/Movies/big_buck_bunny_720p_5mb.mp4

output:

输出:

{
    "streams": [
        {
            "index": 0,
            "codec_name": "h264",
            "codec_long_name": "H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10",
            "profile": "Main",
            "codec_type": "video",
            "codec_time_base": "1/50",
            "codec_tag_string": "avc1",
            "codec_tag": "0x31637661",
            "width": 1280,
            "height": 720,
            "coded_width": 1280,
            "coded_height": 720,
            "has_b_frames": 0,
            "sample_aspect_ratio": "1:1",
            "display_aspect_ratio": "16:9",
            "pix_fmt": "yuv420p",
            "level": 31,
            "chroma_location": "left",
            "refs": 1,
            "is_avc": "1",
            "nal_length_size": "4",
            "r_frame_rate": "25/1",
            "avg_frame_rate": "25/1",
            "time_base": "1/12800",
            "start_pts": 0,
            "start_time": "0.000000",
            "duration_ts": 378368,
            "duration": "29.560000",
            "bit_rate": "1032960",
            "bits_per_raw_sample": "8",
            "nb_frames": "739",
            "disposition": {
                "default": 1,
                "dub": 0,
                "original": 0,
                "comment": 0,
                "lyrics": 0,
                "karaoke": 0,
                "forced": 0,
                "hearing_impaired": 0,
                "visual_impaired": 0,
                "clean_effects": 0,
                "attached_pic": 0
            },
            "tags": {
                "creation_time": "1970-01-01 00:00:00",
                "language": "und",
                "handler_name": "VideoHandler"
            }
        },
        {
            "index": 1,
            "codec_name": "aac",
            "codec_long_name": "AAC (Advanced Audio Coding)",
            "profile": "LC",
            "codec_type": "audio",
            "codec_time_base": "1/48000",
            "codec_tag_string": "mp4a",
            "codec_tag": "0x6134706d",
            "sample_fmt": "fltp",
            "sample_rate": "48000",
            "channels": 6,
            "channel_layout": "5.1",
            "bits_per_sample": 0,
            "r_frame_rate": "0/0",
            "avg_frame_rate": "0/0",
            "time_base": "1/48000",
            "start_pts": 0,
            "start_time": "0.000000",
            "duration_ts": 1419264,
            "duration": "29.568000",
            "bit_rate": "383960",
            "max_bit_rate": "416704",
            "nb_frames": "1386",
            "disposition": {
                "default": 1,
                "dub": 0,
                "original": 0,
                "comment": 0,
                "lyrics": 0,
                "karaoke": 0,
                "forced": 0,
                "hearing_impaired": 0,
                "visual_impaired": 0,
                "clean_effects": 0,
                "attached_pic": 0
            },
            "tags": {
                "creation_time": "1970-01-01 00:00:00",
                "language": "und",
                "handler_name": "SoundHandler"
            }
        }
    ],
    "format": {
        "filename": "/Users/farsheed/Movies/big_buck_bunny_720p_5mb.mp4",
        "nb_streams": 2,
        "nb_programs": 0,
        "format_name": "mov,mp4,m4a,3gp,3g2,mj2",
        "format_long_name": "QuickTime / MOV",
        "start_time": "0.000000",
        "duration": "29.568000",
        "size": "5253880",
        "bit_rate": "1421504",
        "probe_score": 100,
        "tags": {
            "major_brand": "isom",
            "minor_version": "512",
            "compatible_brands": "isomiso2avc1mp41",
            "creation_time": "1970-01-01 00:00:00",
            "encoder": "Lavf53.24.2"
        }
    }
}

See documentation for more info.

更多信息请参见文档。

#3


19  

Using exiftool

run the command

运行以下命令

exiftool VIDEOFILE

The output you get is similar to this:

你得到的输出类似于:

ExifTool Version Number         : 9.76
File Name                       : gource2.mkv
Directory                       : .
File Size                       : 2010 MB
File Modification Date/Time     : 2015:01:07 14:16:22-06:00
File Access Date/Time           : 2015:01:07 14:16:22-06:00
File Inode Change Date/Time     : 2015:01:07 14:16:22-06:00
File Permissions                : rw-rw-r--
File Type                       : MKV
MIME Type                       : video/x-matroska
EBML Version                    : 1
EBML Read Version               : 1
Doc Type                        : matroska
Doc Type Version                : 4
Doc Type Read Version           : 2
Timecode Scale                  : 1 ms
Muxing App                      : libebml v1.3.0 + libmatroska v1.4.1
Writing App                     : mkvmerge v7.4.0 ('Circles') 64bit built on Dec 17 2014 11:31:10
Duration                        : 2:35:09
Date/Time Original              : 2015:01:07 20:14:22Z
Video Codec ID                  : V_MPEG4/ISO/AVC
Video Frame Rate                : 60
Track Language                  : und
Image Width                     : 1280
Image Height                    : 1024
Display Width                   : 1280
Display Height                  : 1024
Track Number                    : 2
Track Type                      : Audio
Audio Codec ID                  : A_DTS
Default Duration                : 10.666666 ms
Audio Sample Rate               : 48000
Audio Channels                  : 6
Image Size                      : 1280x1024

Using ffmpeg/ffprobe

run the command

运行以下命令

ffprobe VIDEOFILE

alternatively:

另外:

ffmpeg -i VIDEOFILE

The output you get is similar to this:

你得到的输出类似于:

ffprobe version 2.1.6 Copyright (c) 2007-2014 the FFmpeg developers
  built on Nov 29 2014 12:07:56 with gcc 4.8.3 (GCC) 20140911 (Red Hat 4.8.3-7)
  configuration: --prefix=/usr --bindir=/usr/bin --datadir=/usr/share/ffmpeg --incdir=/usr/include/ffmpeg --libdir=/usr/lib64 --mandir=/usr/share/man --arch=x86_64 --optflags='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic' --enable-bzlib --disable-crystalhd --enable-frei0r --enable-gnutls --enable-libass --enable-libcdio --enable-libcelt --enable-libdc1394 --disable-indev=jack --enable-libfreetype --enable-libgsm --enable-libmp3lame --enable-openal --enable-libopencv --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libv4l2 --enable-libvpx --enable-libx264 --enable-libxvid --enable-x11grab --enable-avfilter --enable-avresample --enable-postproc --enable-pthreads --disable-static --enable-shared --enable-gpl --disable-debug --disable-stripping --shlibdir=/usr/lib64 --enable-runtime-cpudetect
  libavutil      52. 48.101 / 52. 48.101
  libavcodec     55. 39.101 / 55. 39.101
  libavformat    55. 19.104 / 55. 19.104
  libavdevice    55.  5.100 / 55.  5.100
  libavfilter     3. 90.100 /  3. 90.100
  libavresample   1.  1.  0 /  1.  1.  0
  libswscale      2.  5.101 /  2.  5.101
  libswresample   0. 17.104 /  0. 17.104
  libpostproc    52.  3.100 / 52.  3.100
Input #0, matroska,webm, from 'gource2.mkv':
  Metadata:
    creation_time   : 2015-01-07 20:14:22
  Duration: 02:35:09.70, start: 0.000000, bitrate: 1811 kb/s
    Stream #0:0: Video: h264 (Constrained Baseline), yuv420p, 1280x1024, SAR 1:1 DAR 5:4, 60 fps, 60 tbr, 1k tbn, 120 tbc (default)
    Stream #0:1(eng): Audio: dts (DTS), 48000 Hz, 5.1(side), fltp, 1536 kb/s (default)

Using mplayer

run the command

运行以下命令

mplayer -really-quiet -ao null -vo null -identify -frames 0 VIDEOFILE

The output you get is similar to this:

你得到的输出类似于:

ID_VIDEO_ID=0
ID_AUDIO_ID=0
ID_AID_0_LANG=eng
ID_CLIP_INFO_NAME0=creation_time
ID_CLIP_INFO_VALUE0=2015-01-07 20:14:22
ID_CLIP_INFO_N=1
ID_FILENAME=gource2.mkv
ID_DEMUXER=lavfpref
ID_VIDEO_FORMAT=H264
ID_VIDEO_BITRATE=0
ID_VIDEO_WIDTH=1280
ID_VIDEO_HEIGHT=1024
ID_VIDEO_FPS=60.000
ID_VIDEO_ASPECT=0.0000
ID_AUDIO_FORMAT=8193
ID_AUDIO_BITRATE=1536000
ID_AUDIO_RATE=48000
ID_AUDIO_NCH=6
ID_START_TIME=0.00
ID_LENGTH=9309.70
ID_SEEKABLE=1
ID_CHAPTERS=0
ID_VIDEO_CODEC=ffh264
ID_AUDIO_BITRATE=1536000
ID_AUDIO_RATE=48000
ID_AUDIO_NCH=6
ID_AUDIO_CODEC=ffdca
ID_EXIT=EOF

Using mediainfo

run the command

运行以下命令

mediainfo VIDEOFILE

The output you get is similar to this:

你得到的输出类似于:

General
Unique ID                                : 311795358270161665158539797930749663166 (0xEA919A09196F0CAEF4E1B4FEB72B17BE)
Complete name                            : gource2.mkv
Format                                   : Matroska
Format version                           : Version 4 / Version 2
File size                                : 1.96 GiB
Duration                                 : 2h 35mn
Overall bit rate                         : 1 811 Kbps
Encoded date                             : UTC 2015-01-07 20:14:22
Writing application                      : mkvmerge v7.4.0 ('Circles') 64bit built on Dec 17 2014 11:31:10
Writing library                          : libebml v1.3.0 + libmatroska v1.4.1

Video
ID                                       : 1
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : Baseline@L4.2
Format settings, CABAC                   : No
Format settings, ReFrames                : 1 frame
Codec ID                                 : V_MPEG4/ISO/AVC
Bit rate                                 : 266 Kbps
Width                                    : 1 280 pixels
Height                                   : 1 024 pixels
Display aspect ratio                     : 5:4
Frame rate mode                          : Variable
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
Writing library                          : x264 core 138 r2363 c628e3b
Encoding settings                        : cabac=0 / ref=1 / deblock=0:1:1 / analyse=0:0 / me=dia / subme=0 / psy=1 / psy_rd=0.40:0.00 / mixed_ref=0 / me_range=16 / chroma_me=1 / trellis=0 / 8x8dct=0 / cqm=0 / deadzone=21,11 / fast_pskip=1 / chroma_qp_offset=0 / threads=12 / lookahead_threads=2 / sliced_threads=0 / nr=0 / decimate=1 / interlaced=0 / bluray_compat=0 / constrained_intra=0 / bframes=0 / weightp=0 / keyint=250 / keyint_min=25 / scenecut=0 / intra_refresh=0 / rc=crf / mbtree=0 / crf=22.0 / qcomp=0.60 / qpmin=0 / qpmax=69 / qpstep=4 / ip_ratio=1.40 / aq=0
Default                                  : Yes
Forced                                   : No

Audio
ID                                       : 2
Format                                   : DTS
Format/Info                              : Digital Theater Systems
Mode                                     : 16
Format settings, Endianness              : Big
Codec ID                                 : A_DTS
Duration                                 : 2h 35mn
Bit rate mode                            : Constant
Bit rate                                 : 1 509 Kbps
Channel(s)                               : 6 channels
Channel positions                        : Front: L C R, Side: L R, LFE
Sampling rate                            : 48.0 KHz
Bit depth                                : 24 bits
Compression mode                         : Lossy
Stream size                              : 1.64 GiB (83%)
Language                                 : English
Default                                  : Yes
Forced                                   : No

time summary

exiftool
    real    0m0.089s
    user    0m0.081s
    sys     0m0.008s
mplayer
    real    0m0.050s
    user    0m0.034s
    sys     0m0.017s
ffprobe/ffmpeg
    real    0m0.017s
    user    0m0.011s
    sys     0m0.007s
mediainfo
    real    0m0.029s
    user    0m0.025s
    sys     0m0.004s

YMMV, but ffprobe is the fastest followed by mediainfo then mplayer and finally exiftool

而ffprobe则是最快的,其次是mediainfo,然后是mplayer,最后是exiftool

ffprobe < mediainfo < mplayer < exiftool

#4


14  

Use ffprobe:

使用ffprobe:

ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 input.mp4

Example output:

示例输出:

1280x720

See FFprobe Documentation and FFmpeg Wiki: FFprobe Tips for more info.

参见FFprobe文档和FFmpeg Wiki:更多信息的FFprobe提示。

#5


5  

Try midentify.sh (TOOLS/midentify.sh in the source code tree of MPlayer).

midentify试试。sh(工具/ midentify。在MPlayer的源代码树中的sh)。

It will show information in a parseable format:

它将以可分割的格式显示信息:

$  ./midentify.sh /data/myvid.flv 
ID_VIDEO_ID=0
ID_AUDIO_ID=1
ID_FILENAME=/data/myvid.flv
ID_DEMUXER=lavfpref
ID_VIDEO_FORMAT=VP6F
ID_VIDEO_BITRATE=0
ID_VIDEO_WIDTH=640
ID_VIDEO_HEIGHT=480

[,,,]

(,,,)

#6


5  

To return only the Width and Height mediainfo is an excellent tool.

只返回宽度和高度是一个很好的工具。

mediainfo --Inform="Video;%Width%" Videofile && mediainfo --Inform="Video;%Height%" Videofile will do exactly that, no more, no less, for a vast array of supported video files.

mediainfo—Inform=“Video;%Width%”Videofile && & mediainfo—Inform=“Video;%Height%”Videofile将对大量受支持的视频文件执行同样的操作。

There is a long list of useful Inform= parameters which you can obtain with the command mediainfo --Info-Parameters

有一长串有用的Inform=参数列表,您可以通过命令mediainfo -Info-Parameters获得这些参数

If you want the output in standard WidthXHeight format use Width=$(mediainfo --Inform="Video;%Width%" Video.File)&& Height=$(mediainfo --Inform="Video;%Height%" Video.File)&&echo $Width"X"$Height

如果您想要以标准的WidthXHeight格式输出,请使用Width=$(mediainfo—Inform=“Video;%Width%”Video. file)和Height=$(mediainfo—Inform=“Video;%Height%”Video.File)并回传$Width“X”$Height

There's a bash script here that you could easily modify to meet your needs.

这里有一个bash脚本,您可以轻松修改它以满足您的需求。

Sources:

来源:

Adding an Overlay Using FFMPEG With Minimal Re-Encoding

使用FFMPEG添加覆盖,并进行最小的重新编码

http://manpages.ubuntu.com/manpages/xenial/man1/mediainfo.1.html

http://manpages.ubuntu.com/manpages/xenial/man1/mediainfo.1.html

whiptail: How to redirect output to environment variable?

whiptail:如何将输出重定向到环境变量?

How to concatenate string variables in Bash

如何在Bash中连接字符串变量?

#7


3  

If you are just interested in the resolution:

如果你只是对决议感兴趣:

ffprobe -v error -of flat=s=_ -select_streams v:0 -show_entries stream=height,width video.mkv

It works also on Windows. This is running right now on my PC to build an index of all files:

它也适用于Windows。这是现在在我的电脑上运行,建立一个索引的所有文件:

find //Q1207/Film -size +10000k -print -a -exec ./ffprobe.exe -v error -of flat=s=_ -select_streams v:0 -show_entries stream=height,width \{\} \; > //Q1207/Film/index.txt

#8


1  

Here's an "almost-one-liner" I've concocted around ffprobe for exactly this purpose. Works pretty well for me both on Linux and MacOS.

这是我围绕ffprobe来编造的一个“几乎是一行的词”,就是为了这个目的。我在Linux和MacOS上都做得很好。

#!/bin/bash

B='[[:blank:]]'
D='[[:digit:]]'
ffprobe "$1" 2>&1 \
    | grep 'Stream.*Video.*fps' \
    | sed "s/^.*$B\($D$D$D*x$D$D$D*\).*$/\1/"

#9


-1  

The good ol' "file" utility will often get the dimensions of a video file.

好的ol的“文件”工具通常会得到视频文件的尺寸。

#1


11  

MediaInfo has a command line version and provides the dimensions together with tons of other information.

MediaInfo有一个命令行版本,并提供维度和大量其他信息。

#2


44  

Use ffprobe (part of FFmpeg toolkit)

使用ffprobe (FFmpeg工具包的一部分)

example:

例子:

ffprobe -v quiet -print_format json -show_format -show_streams ~/Movies/big_buck_bunny_720p_5mb.mp4

output:

输出:

{
    "streams": [
        {
            "index": 0,
            "codec_name": "h264",
            "codec_long_name": "H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10",
            "profile": "Main",
            "codec_type": "video",
            "codec_time_base": "1/50",
            "codec_tag_string": "avc1",
            "codec_tag": "0x31637661",
            "width": 1280,
            "height": 720,
            "coded_width": 1280,
            "coded_height": 720,
            "has_b_frames": 0,
            "sample_aspect_ratio": "1:1",
            "display_aspect_ratio": "16:9",
            "pix_fmt": "yuv420p",
            "level": 31,
            "chroma_location": "left",
            "refs": 1,
            "is_avc": "1",
            "nal_length_size": "4",
            "r_frame_rate": "25/1",
            "avg_frame_rate": "25/1",
            "time_base": "1/12800",
            "start_pts": 0,
            "start_time": "0.000000",
            "duration_ts": 378368,
            "duration": "29.560000",
            "bit_rate": "1032960",
            "bits_per_raw_sample": "8",
            "nb_frames": "739",
            "disposition": {
                "default": 1,
                "dub": 0,
                "original": 0,
                "comment": 0,
                "lyrics": 0,
                "karaoke": 0,
                "forced": 0,
                "hearing_impaired": 0,
                "visual_impaired": 0,
                "clean_effects": 0,
                "attached_pic": 0
            },
            "tags": {
                "creation_time": "1970-01-01 00:00:00",
                "language": "und",
                "handler_name": "VideoHandler"
            }
        },
        {
            "index": 1,
            "codec_name": "aac",
            "codec_long_name": "AAC (Advanced Audio Coding)",
            "profile": "LC",
            "codec_type": "audio",
            "codec_time_base": "1/48000",
            "codec_tag_string": "mp4a",
            "codec_tag": "0x6134706d",
            "sample_fmt": "fltp",
            "sample_rate": "48000",
            "channels": 6,
            "channel_layout": "5.1",
            "bits_per_sample": 0,
            "r_frame_rate": "0/0",
            "avg_frame_rate": "0/0",
            "time_base": "1/48000",
            "start_pts": 0,
            "start_time": "0.000000",
            "duration_ts": 1419264,
            "duration": "29.568000",
            "bit_rate": "383960",
            "max_bit_rate": "416704",
            "nb_frames": "1386",
            "disposition": {
                "default": 1,
                "dub": 0,
                "original": 0,
                "comment": 0,
                "lyrics": 0,
                "karaoke": 0,
                "forced": 0,
                "hearing_impaired": 0,
                "visual_impaired": 0,
                "clean_effects": 0,
                "attached_pic": 0
            },
            "tags": {
                "creation_time": "1970-01-01 00:00:00",
                "language": "und",
                "handler_name": "SoundHandler"
            }
        }
    ],
    "format": {
        "filename": "/Users/farsheed/Movies/big_buck_bunny_720p_5mb.mp4",
        "nb_streams": 2,
        "nb_programs": 0,
        "format_name": "mov,mp4,m4a,3gp,3g2,mj2",
        "format_long_name": "QuickTime / MOV",
        "start_time": "0.000000",
        "duration": "29.568000",
        "size": "5253880",
        "bit_rate": "1421504",
        "probe_score": 100,
        "tags": {
            "major_brand": "isom",
            "minor_version": "512",
            "compatible_brands": "isomiso2avc1mp41",
            "creation_time": "1970-01-01 00:00:00",
            "encoder": "Lavf53.24.2"
        }
    }
}

See documentation for more info.

更多信息请参见文档。

#3


19  

Using exiftool

run the command

运行以下命令

exiftool VIDEOFILE

The output you get is similar to this:

你得到的输出类似于:

ExifTool Version Number         : 9.76
File Name                       : gource2.mkv
Directory                       : .
File Size                       : 2010 MB
File Modification Date/Time     : 2015:01:07 14:16:22-06:00
File Access Date/Time           : 2015:01:07 14:16:22-06:00
File Inode Change Date/Time     : 2015:01:07 14:16:22-06:00
File Permissions                : rw-rw-r--
File Type                       : MKV
MIME Type                       : video/x-matroska
EBML Version                    : 1
EBML Read Version               : 1
Doc Type                        : matroska
Doc Type Version                : 4
Doc Type Read Version           : 2
Timecode Scale                  : 1 ms
Muxing App                      : libebml v1.3.0 + libmatroska v1.4.1
Writing App                     : mkvmerge v7.4.0 ('Circles') 64bit built on Dec 17 2014 11:31:10
Duration                        : 2:35:09
Date/Time Original              : 2015:01:07 20:14:22Z
Video Codec ID                  : V_MPEG4/ISO/AVC
Video Frame Rate                : 60
Track Language                  : und
Image Width                     : 1280
Image Height                    : 1024
Display Width                   : 1280
Display Height                  : 1024
Track Number                    : 2
Track Type                      : Audio
Audio Codec ID                  : A_DTS
Default Duration                : 10.666666 ms
Audio Sample Rate               : 48000
Audio Channels                  : 6
Image Size                      : 1280x1024

Using ffmpeg/ffprobe

run the command

运行以下命令

ffprobe VIDEOFILE

alternatively:

另外:

ffmpeg -i VIDEOFILE

The output you get is similar to this:

你得到的输出类似于:

ffprobe version 2.1.6 Copyright (c) 2007-2014 the FFmpeg developers
  built on Nov 29 2014 12:07:56 with gcc 4.8.3 (GCC) 20140911 (Red Hat 4.8.3-7)
  configuration: --prefix=/usr --bindir=/usr/bin --datadir=/usr/share/ffmpeg --incdir=/usr/include/ffmpeg --libdir=/usr/lib64 --mandir=/usr/share/man --arch=x86_64 --optflags='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic' --enable-bzlib --disable-crystalhd --enable-frei0r --enable-gnutls --enable-libass --enable-libcdio --enable-libcelt --enable-libdc1394 --disable-indev=jack --enable-libfreetype --enable-libgsm --enable-libmp3lame --enable-openal --enable-libopencv --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libv4l2 --enable-libvpx --enable-libx264 --enable-libxvid --enable-x11grab --enable-avfilter --enable-avresample --enable-postproc --enable-pthreads --disable-static --enable-shared --enable-gpl --disable-debug --disable-stripping --shlibdir=/usr/lib64 --enable-runtime-cpudetect
  libavutil      52. 48.101 / 52. 48.101
  libavcodec     55. 39.101 / 55. 39.101
  libavformat    55. 19.104 / 55. 19.104
  libavdevice    55.  5.100 / 55.  5.100
  libavfilter     3. 90.100 /  3. 90.100
  libavresample   1.  1.  0 /  1.  1.  0
  libswscale      2.  5.101 /  2.  5.101
  libswresample   0. 17.104 /  0. 17.104
  libpostproc    52.  3.100 / 52.  3.100
Input #0, matroska,webm, from 'gource2.mkv':
  Metadata:
    creation_time   : 2015-01-07 20:14:22
  Duration: 02:35:09.70, start: 0.000000, bitrate: 1811 kb/s
    Stream #0:0: Video: h264 (Constrained Baseline), yuv420p, 1280x1024, SAR 1:1 DAR 5:4, 60 fps, 60 tbr, 1k tbn, 120 tbc (default)
    Stream #0:1(eng): Audio: dts (DTS), 48000 Hz, 5.1(side), fltp, 1536 kb/s (default)

Using mplayer

run the command

运行以下命令

mplayer -really-quiet -ao null -vo null -identify -frames 0 VIDEOFILE

The output you get is similar to this:

你得到的输出类似于:

ID_VIDEO_ID=0
ID_AUDIO_ID=0
ID_AID_0_LANG=eng
ID_CLIP_INFO_NAME0=creation_time
ID_CLIP_INFO_VALUE0=2015-01-07 20:14:22
ID_CLIP_INFO_N=1
ID_FILENAME=gource2.mkv
ID_DEMUXER=lavfpref
ID_VIDEO_FORMAT=H264
ID_VIDEO_BITRATE=0
ID_VIDEO_WIDTH=1280
ID_VIDEO_HEIGHT=1024
ID_VIDEO_FPS=60.000
ID_VIDEO_ASPECT=0.0000
ID_AUDIO_FORMAT=8193
ID_AUDIO_BITRATE=1536000
ID_AUDIO_RATE=48000
ID_AUDIO_NCH=6
ID_START_TIME=0.00
ID_LENGTH=9309.70
ID_SEEKABLE=1
ID_CHAPTERS=0
ID_VIDEO_CODEC=ffh264
ID_AUDIO_BITRATE=1536000
ID_AUDIO_RATE=48000
ID_AUDIO_NCH=6
ID_AUDIO_CODEC=ffdca
ID_EXIT=EOF

Using mediainfo

run the command

运行以下命令

mediainfo VIDEOFILE

The output you get is similar to this:

你得到的输出类似于:

General
Unique ID                                : 311795358270161665158539797930749663166 (0xEA919A09196F0CAEF4E1B4FEB72B17BE)
Complete name                            : gource2.mkv
Format                                   : Matroska
Format version                           : Version 4 / Version 2
File size                                : 1.96 GiB
Duration                                 : 2h 35mn
Overall bit rate                         : 1 811 Kbps
Encoded date                             : UTC 2015-01-07 20:14:22
Writing application                      : mkvmerge v7.4.0 ('Circles') 64bit built on Dec 17 2014 11:31:10
Writing library                          : libebml v1.3.0 + libmatroska v1.4.1

Video
ID                                       : 1
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : Baseline@L4.2
Format settings, CABAC                   : No
Format settings, ReFrames                : 1 frame
Codec ID                                 : V_MPEG4/ISO/AVC
Bit rate                                 : 266 Kbps
Width                                    : 1 280 pixels
Height                                   : 1 024 pixels
Display aspect ratio                     : 5:4
Frame rate mode                          : Variable
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
Writing library                          : x264 core 138 r2363 c628e3b
Encoding settings                        : cabac=0 / ref=1 / deblock=0:1:1 / analyse=0:0 / me=dia / subme=0 / psy=1 / psy_rd=0.40:0.00 / mixed_ref=0 / me_range=16 / chroma_me=1 / trellis=0 / 8x8dct=0 / cqm=0 / deadzone=21,11 / fast_pskip=1 / chroma_qp_offset=0 / threads=12 / lookahead_threads=2 / sliced_threads=0 / nr=0 / decimate=1 / interlaced=0 / bluray_compat=0 / constrained_intra=0 / bframes=0 / weightp=0 / keyint=250 / keyint_min=25 / scenecut=0 / intra_refresh=0 / rc=crf / mbtree=0 / crf=22.0 / qcomp=0.60 / qpmin=0 / qpmax=69 / qpstep=4 / ip_ratio=1.40 / aq=0
Default                                  : Yes
Forced                                   : No

Audio
ID                                       : 2
Format                                   : DTS
Format/Info                              : Digital Theater Systems
Mode                                     : 16
Format settings, Endianness              : Big
Codec ID                                 : A_DTS
Duration                                 : 2h 35mn
Bit rate mode                            : Constant
Bit rate                                 : 1 509 Kbps
Channel(s)                               : 6 channels
Channel positions                        : Front: L C R, Side: L R, LFE
Sampling rate                            : 48.0 KHz
Bit depth                                : 24 bits
Compression mode                         : Lossy
Stream size                              : 1.64 GiB (83%)
Language                                 : English
Default                                  : Yes
Forced                                   : No

time summary

exiftool
    real    0m0.089s
    user    0m0.081s
    sys     0m0.008s
mplayer
    real    0m0.050s
    user    0m0.034s
    sys     0m0.017s
ffprobe/ffmpeg
    real    0m0.017s
    user    0m0.011s
    sys     0m0.007s
mediainfo
    real    0m0.029s
    user    0m0.025s
    sys     0m0.004s

YMMV, but ffprobe is the fastest followed by mediainfo then mplayer and finally exiftool

而ffprobe则是最快的,其次是mediainfo,然后是mplayer,最后是exiftool

ffprobe < mediainfo < mplayer < exiftool

#4


14  

Use ffprobe:

使用ffprobe:

ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 input.mp4

Example output:

示例输出:

1280x720

See FFprobe Documentation and FFmpeg Wiki: FFprobe Tips for more info.

参见FFprobe文档和FFmpeg Wiki:更多信息的FFprobe提示。

#5


5  

Try midentify.sh (TOOLS/midentify.sh in the source code tree of MPlayer).

midentify试试。sh(工具/ midentify。在MPlayer的源代码树中的sh)。

It will show information in a parseable format:

它将以可分割的格式显示信息:

$  ./midentify.sh /data/myvid.flv 
ID_VIDEO_ID=0
ID_AUDIO_ID=1
ID_FILENAME=/data/myvid.flv
ID_DEMUXER=lavfpref
ID_VIDEO_FORMAT=VP6F
ID_VIDEO_BITRATE=0
ID_VIDEO_WIDTH=640
ID_VIDEO_HEIGHT=480

[,,,]

(,,,)

#6


5  

To return only the Width and Height mediainfo is an excellent tool.

只返回宽度和高度是一个很好的工具。

mediainfo --Inform="Video;%Width%" Videofile && mediainfo --Inform="Video;%Height%" Videofile will do exactly that, no more, no less, for a vast array of supported video files.

mediainfo—Inform=“Video;%Width%”Videofile && & mediainfo—Inform=“Video;%Height%”Videofile将对大量受支持的视频文件执行同样的操作。

There is a long list of useful Inform= parameters which you can obtain with the command mediainfo --Info-Parameters

有一长串有用的Inform=参数列表,您可以通过命令mediainfo -Info-Parameters获得这些参数

If you want the output in standard WidthXHeight format use Width=$(mediainfo --Inform="Video;%Width%" Video.File)&& Height=$(mediainfo --Inform="Video;%Height%" Video.File)&&echo $Width"X"$Height

如果您想要以标准的WidthXHeight格式输出,请使用Width=$(mediainfo—Inform=“Video;%Width%”Video. file)和Height=$(mediainfo—Inform=“Video;%Height%”Video.File)并回传$Width“X”$Height

There's a bash script here that you could easily modify to meet your needs.

这里有一个bash脚本,您可以轻松修改它以满足您的需求。

Sources:

来源:

Adding an Overlay Using FFMPEG With Minimal Re-Encoding

使用FFMPEG添加覆盖,并进行最小的重新编码

http://manpages.ubuntu.com/manpages/xenial/man1/mediainfo.1.html

http://manpages.ubuntu.com/manpages/xenial/man1/mediainfo.1.html

whiptail: How to redirect output to environment variable?

whiptail:如何将输出重定向到环境变量?

How to concatenate string variables in Bash

如何在Bash中连接字符串变量?

#7


3  

If you are just interested in the resolution:

如果你只是对决议感兴趣:

ffprobe -v error -of flat=s=_ -select_streams v:0 -show_entries stream=height,width video.mkv

It works also on Windows. This is running right now on my PC to build an index of all files:

它也适用于Windows。这是现在在我的电脑上运行,建立一个索引的所有文件:

find //Q1207/Film -size +10000k -print -a -exec ./ffprobe.exe -v error -of flat=s=_ -select_streams v:0 -show_entries stream=height,width \{\} \; > //Q1207/Film/index.txt

#8


1  

Here's an "almost-one-liner" I've concocted around ffprobe for exactly this purpose. Works pretty well for me both on Linux and MacOS.

这是我围绕ffprobe来编造的一个“几乎是一行的词”,就是为了这个目的。我在Linux和MacOS上都做得很好。

#!/bin/bash

B='[[:blank:]]'
D='[[:digit:]]'
ffprobe "$1" 2>&1 \
    | grep 'Stream.*Video.*fps' \
    | sed "s/^.*$B\($D$D$D*x$D$D$D*\).*$/\1/"

#9


-1  

The good ol' "file" utility will often get the dimensions of a video file.

好的ol的“文件”工具通常会得到视频文件的尺寸。