在Linux下如何从命令行检索视频文件信息?


81

我想从命令行中查看与给定视频文件有关的所有信息,包括长度,质量,比特率,分辨率,音频和视频格式,音频流和字幕的数量和语言,等等;越多越好。

到目前为止,我必须依靠VLC的“信息”选项卡,因为即使Dolphin文件管理器也无法帮助我:它仅向我显示这些信息中的某些信息,并且仅针对某些格式(即,.mkv似乎不支持该信息) )。


2
那么mediainfo呢?
Endoro

5
看看mkvinfo,并ffprobe为好。
slhck

也谢谢你 和以前一样,请回答,以便我能正确投票给您的建议
Sekhemty 2013年

1
Mkvinfo很好,但仅适用于MKV视频:mkvinfo -v -v video.mkv
Endoro

Answers:


100

给出的MediaInfo一试。在命令行上mediainfo input.mkv。有关更详细的视频信息mediainfo --fullscan input.mkv

输出示例:

一般
唯一ID:239093944660469735839645243666869007606(0xB3DFD199E22F0E7CBAE1FE52206834F6)
完整名称:input.mkv
版式:Matroska
格式版本:版本2
档案大小:39.6 MiB
持续时间:20s 288ms
整体比特率模式:可变
总比特率:16.4 Mbps
电影名称:我最好的电影
编码日期:UTC 2012-11-10 16:42:02
撰写应用程式:mkvmerge v5.8.0('No Sleep / Pillow')建立于2012年9月2日15:37:04
编写库:libebml v1.2.3 + libmatroska v1.3.0
产品:??? ???????
感谢:布鲁斯·戴维
首席表演者:鲁迪·杨布洛德
由...混音:©????

视频
编号:1
格式:AVC
格式/信息:高级视频编解码器
格式设定档:High@L4.0
MultiView_Count:2
格式设置,CABAC:是
格式设置,ReFrames:2张
格式设置,GOP:M = 2,N = 13
混合模式:标题剥离
编解码器ID:V_MPEG4 / ISO / AVC
持续时间:20s 280ms
比特率模式:可变
比特率:15.8 Mbps
最大比特率:16.0 Mbps
宽度:1920像素
高度:1,080像素
显示宽高比:16:9
帧率模式:恒定
帧率:25.000 fps
色彩空间:YUV
色度二次采样:4:2:0
位深:8位
扫描类型:隔行
扫描顺序:顶场优先
比特/(像素*帧):0.304
流大小:38.2 MiB(96%)
标题:索尼硬件视频H.264编码器
英语语言
默认值:是
强制:否

音讯
编号:2
格式:AC-3
格式/信息:音频编码3
模式扩展:CM(完整主码)
格式设置,字节顺序:大
混合模式:标题剥离
编解码器ID:A_AC3
持续时间:20s 288ms
比特率模式:恒定
比特率:256 Kbps
频道:2个频道
通道位置:前:LR
采样率:48.0 KHz
位深:16位
压缩方式:有损
相对于视频的延迟:-80ms
流大小:634 KiB(2%)
标题:Sony Hardware Audio AC3编码器
语言:俄语
默认值:是
强制:否

文本
编号:3
格式:PGS
木星模式:zlib
编解码器ID:S_HDMV / PGS
编解码器ID /信息:与BD / HD-DVD上使用的字幕格式相同
标题:Sony Hardware PGS编码器
英语语言
默认值:是
强制:否

这是件好事,但我只是想只有时间在commandline.Thanks
居纳伊居尔泰金

2
是的,我找到了。我应该这样做; '的MediaInfo --output =视频;%时间%filename.mp4'
居纳伊居尔特金

22

您可以使用mplayer:

mplayer -vo null -ao null -frames 0 -identify videofile.mp4

输出:

MPlayer 1.1-4.2.1 (C) 2000-2012 MPlayer Team
Can't init Apple Remote.

Playing vid.mp4.
libavformat version 54.6.101 (internal)
libavformat file format detected.
ID_VIDEO_ID=0
[lavf] stream 0: video (h264), -vid 0
ID_AUDIO_ID=0
[lavf] stream 1: audio (aac), -aid 0, -alang und
VIDEO:  [H264]  480x360  24bpp  29.970 fps  700.7 kbps (85.5 kbyte/s)
Clip info:
 major_brand: qt
ID_CLIP_INFO_NAME0=major_brand
ID_CLIP_INFO_VALUE0=qt
 minor_version: 0
ID_CLIP_INFO_NAME1=minor_version
ID_CLIP_INFO_VALUE1=0
 compatible_brands: qt
ID_CLIP_INFO_NAME2=compatible_brands
ID_CLIP_INFO_VALUE2=qt
 creation_time: 2011-03-03 15:42:30
ID_CLIP_INFO_NAME3=creation_time
ID_CLIP_INFO_VALUE3=2011-03-03 15:42:30
 encoder: 4.2.1
ID_CLIP_INFO_NAME4=encoder
ID_CLIP_INFO_VALUE4=4.2.1
 encoder-eng: 4.2.1
ID_CLIP_INFO_NAME5=encoder-eng
ID_CLIP_INFO_VALUE5=4.2.1
 date: 2011-03-03T10:42:30-0500
ID_CLIP_INFO_NAME6=date
ID_CLIP_INFO_VALUE6=2011-03-03T10:42:30-0500
 date-eng: 2011-03-03T10:42:30-0500
ID_CLIP_INFO_NAME7=date-eng
ID_CLIP_INFO_VALUE7=2011-03-03T10:42:30-0500
ID_CLIP_INFO_N=8
Load subtitles in ./
ID_FILENAME=vid.mp4
ID_DEMUXER=lavfpref
ID_VIDEO_FORMAT=H264
ID_VIDEO_BITRATE=700712
ID_VIDEO_WIDTH=480
ID_VIDEO_HEIGHT=360
ID_VIDEO_FPS=29.970
ID_VIDEO_ASPECT=0.0000
ID_AUDIO_FORMAT=MP4A
ID_AUDIO_BITRATE=63600
ID_AUDIO_RATE=44100
ID_AUDIO_NCH=1
ID_START_TIME=0.00
ID_LENGTH=3.83
ID_SEEKABLE=1
ID_CHAPTERS=0
==========================================================================
Opening video decoder: [ffmpeg] FFmpeg's libavcodec codec family
libavcodec version 54.23.100 (internal)
Selected video codec: [ffh264] vfm: ffmpeg (FFmpeg H.264)
==========================================================================
ID_VIDEO_CODEC=ffh264
==========================================================================
Opening audio decoder: [ffmpeg] FFmpeg/libavcodec audio decoders
AUDIO: 44100 Hz, 1 ch, s16le, 63.6 kbit/9.01% (ratio: 7950->88200)
ID_AUDIO_BITRATE=63600
ID_AUDIO_RATE=44100
ID_AUDIO_NCH=1
Selected audio codec: [ffaac] afm: ffmpeg (FFmpeg AAC (MPEG-2/MPEG-4 Audio))
==========================================================================
AO: [null] 44100Hz 1ch s16le (2 bytes per sample)
ID_AUDIO_CODEC=ffaac
Starting playback...


Exiting... (End of file)
ID_EXIT=EOF

2
仅供参考,这在OS X 10.10上使用brew.sh并通过安装mplayer 效果很好brew install mplayer。mplayer似乎比mediainfo检测到更多的非标准元数据。
Andrew Odri 2015年

22

ffprobe

在Ubuntu下:

sudo apt install ffmpeg
ffprobe a.mp4

要获取有关格式,流等的信息,请运行:

ffprobe -v error -show_format -show_streams a.mp4

[STREAM]
index=0
codec_name=h264
codec_long_name=H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10
profile=High
codec_type=video
codec_time_base=1/50
codec_tag_string=avc1
codec_tag=0x31637661
width=320
height=240
has_b_frames=2
sample_aspect_ratio=1:1
display_aspect_ratio=4:3
pix_fmt=yuv420p
level=13
color_range=N/A
color_space=unknown
color_transfer=unknown
color_primaries=unknown
chroma_location=left
timecode=N/A
refs=4
is_avc=1
nal_length_size=4
id=N/A
r_frame_rate=25/1
avg_frame_rate=25/1
time_base=1/12800
start_pts=0
start_time=0.000000
duration_ts=384000
duration=30.000000
bit_rate=34761
max_bit_rate=N/A
bits_per_raw_sample=8
nb_frames=750
nb_read_frames=N/A
nb_read_packets=N/A
DISPOSITION:default=1
DISPOSITION:dub=0
DISPOSITION:original=0
DISPOSITION:comment=0
DISPOSITION:lyrics=0
DISPOSITION:karaoke=0
DISPOSITION:forced=0
DISPOSITION:hearing_impaired=0
DISPOSITION:visual_impaired=0
DISPOSITION:clean_effects=0
DISPOSITION:attached_pic=0
TAG:language=und
TAG:handler_name=VideoHandler
[/STREAM]
[STREAM]
index=1
codec_name=aac
codec_long_name=AAC (Advanced Audio Coding)
profile=LC
codec_type=audio
codec_time_base=1/44100
codec_tag_string=mp4a
codec_tag=0x6134706d
sample_fmt=fltp
sample_rate=44100
channels=1
channel_layout=mono
bits_per_sample=0
id=N/A
r_frame_rate=0/0
avg_frame_rate=0/0
time_base=1/44100
start_pts=-1024
start_time=-0.023220
duration_ts=1324024
duration=30.023220
bit_rate=56517
max_bit_rate=N/A
bits_per_raw_sample=N/A
nb_frames=1293
nb_read_frames=N/A
nb_read_packets=N/A
DISPOSITION:default=1
DISPOSITION:dub=0
DISPOSITION:original=0
DISPOSITION:comment=0
DISPOSITION:lyrics=0
DISPOSITION:karaoke=0
DISPOSITION:forced=0
DISPOSITION:hearing_impaired=0
DISPOSITION:visual_impaired=0
DISPOSITION:clean_effects=0
DISPOSITION:attached_pic=0
TAG:language=und
TAG:handler_name=SoundHandler
[/STREAM]
[FORMAT]
filename=input.mp4
nb_streams=2
nb_programs=0
format_name=mov,mp4,m4a,3gp,3g2,mj2
format_long_name=QuickTime / MOV
start_time=-0.023220
duration=30.024000
size=368644
bit_rate=98226
probe_score=100
TAG:major_brand=isom
TAG:minor_version=512
TAG:compatible_brands=isomiso2avc1mp41
TAG:title=FFprobe Tips
TAG:encoder=Lavf56.15.101
[/FORMAT]

您还可以输出为JSON或CSV。查看有关ffprobe的更多信息


Exif工具

在Ubuntu下:

sudo apt install libimage-exiftool-perl
exiftool a.mp4

样本输出:

ExifTool Version Number         : 10.00
File Name                       : lego.mp4
Directory                       : .
File Size                       : 375 kB
File Modification Date/Time     : 2016:02:03 17:18:15+01:00
File Access Date/Time           : 2016:02:03 17:18:49+01:00
File Inode Change Date/Time     : 2016:02:03 17:18:49+01:00
File Permissions                : rw-rw-r--
File Type                       : MP4
File Type Extension             : mp4
MIME Type                       : video/mp4
Major Brand                     : MP4 v2 [ISO 14496-14]
Minor Version                   : 0.0.0
Compatible Brands               : mp42, isom, avc1
Movie Data Size                 : 379872
Movie Data Offset               : 168
Movie Header Version            : 0
Create Date                     : 2010:03:20 21:29:11
Modify Date                     : 2010:03:20 21:29:12
Time Scale                      : 90000
Duration                        : 5.57 s
Preferred Rate                  : 1
Preferred Volume                : 100.00%
Preview Time                    : 0 s
Preview Duration                : 0 s
Poster Time                     : 0 s
Selection Time                  : 0 s
Selection Duration              : 0 s
Current Time                    : 0 s
Next Track ID                   : 3
Track Header Version            : 0
Track Create Date               : 2010:03:20 21:29:11
Track Modify Date               : 2010:03:20 21:29:12
Track ID                        : 1
Track Duration                  : 5.53 s
Track Layer                     : 0
Track Volume                    : 0.00%
Image Width                     : 560
Image Height                    : 320
Graphics Mode                   : srcCopy
Op Color                        : 0 0 0
Compressor ID                   : avc1
Source Image Width              : 560
Source Image Height             : 320
X Resolution                    : 72
Y Resolution                    : 72
Compressor Name                 : JVT/AVC Coding
Bit Depth                       : 24
Color Representation            : nclc 1 1 1
Video Frame Rate                : 30
Matrix Structure                : 1 0 0 0 1 0 0 0 1
Media Header Version            : 0
Media Create Date               : 2010:03:20 21:29:11
Media Modify Date               : 2010:03:20 21:29:12
Media Time Scale                : 48000
Media Duration                  : 5.57 s
Media Language Code             : eng
Balance                         : 0
Audio Format                    : mp4a
Audio Channels                  : 1
Audio Bits Per Sample           : 16
Audio Sample Rate               : 48000
Track 2 Name                    : Stereo
Handler Type                    : Metadata
Encoder                         : HandBrake 0.9.4 2009112300
Avg Bitrate                     : 546 kbps
Image Size                      : 560x320
Megapixels                      : 0.179
Rotation                        : 0

另请参阅:https : //askubuntu.com/questions/249828/command-to-see-media-file-info-in-terminal

在Ubuntu 18.10上测试。


@slhck感谢您的修改,但是请说说您使用的是哪个ubuntu版本。鉴于此,我接受编辑,谢谢。
Ciro Santilli新疆改造中心法轮功六四事件

18.04和18.10,因此是LTS和当前版本。请考虑其他用户可能会编辑Stack Exchange上的答案以保持最新。
slhck

@slhck谢谢。但它们也可能会保留数年而不进行更新,最好在每次编辑时进行测试。
Ciro Santilli新疆改造中心法轮功六四事件

是的,可以添加针对其进行测试的版本,但是它主要取决于工具本身(ffprobe,exiftool),而不取决于操作系统。
slhck

@slhck同意,我当前的答案模板以“在Ubuntu ZW中测试,mypackage XY测试”结尾:-)
Ciro Santilli新疆改造中心法轮功六四事件

3

Mediainfo是一个很棒的工具。另外,您也可以使用ffprobe获取详细信息。

$ ffprobe -hide_banner -loglevel fatal -show_error -show_format -show_streams -show_programs -show_chapters -show_private_data -print_format json /home/sathish/Videos/Aandipatti.mp4

这是输出

{
    "programs": [

    ],
    "streams": [
        {
            "index": 0,
            "codec_name": "h264",
            "codec_long_name": "H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10",
            "profile": "High",
            "codec_type": "video",
            "codec_time_base": "28113749/1349640000",
            "codec_tag_string": "avc1",
            "codec_tag": "0x31637661",
            "width": 1920,
            "height": 1080,
            "coded_width": 1920,
            "coded_height": 1080,
            "has_b_frames": 1,
            "sample_aspect_ratio": "1:1",
            "display_aspect_ratio": "16:9",
            "pix_fmt": "yuv420p",
            "level": 40,
            "color_range": "tv",
            "color_space": "bt709",
            "color_transfer": "bt709",
            "color_primaries": "bt709",
            "chroma_location": "left",
            "refs": 1,
            "is_avc": "true",
            "nal_length_size": "4",
            "r_frame_rate": "24/1",
            "avg_frame_rate": "674820000/28113749",
            "time_base": "1/90000",
            "start_pts": 0,
            "start_time": "0.000000",
            "duration_ts": 28113750,
            "duration": "312.375000",
            "bit_rate": "2612895",
            "bits_per_raw_sample": "8",
            "nb_frames": "7498",
            "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,
                "timed_thumbnails": 0
            },
            "tags": {
                "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/44100",
            "codec_tag_string": "mp4a",
            "codec_tag": "0x6134706d",
            "sample_fmt": "fltp",
            "sample_rate": "44100",
            "channels": 2,
            "channel_layout": "stereo",
            "bits_per_sample": 0,
            "r_frame_rate": "0/0",
            "avg_frame_rate": "0/0",
            "time_base": "1/44100",
            "start_pts": 0,
            "start_time": "0.000000",
            "duration_ts": 13779971,
            "duration": "312.470998",
            "bit_rate": "125595",
            "max_bit_rate": "125595",
            "nb_frames": "13457",
            "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,
                "timed_thumbnails": 0
            },
            "tags": {
                "language": "und",
                "handler_name": "SoundHandler"
            }
        }
    ],
    "chapters": [

    ],
    "format": {
        "filename": "/home/sathish/Videos/Aandipatti.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": "312.471000",
        "size": "107155047",
        "bit_rate": "2743423",
        "probe_score": 100,
        "tags": {
            "major_brand": "isom",
            "minor_version": "512",
            "compatible_brands": "isomiso2avc1mp41",
            "encoder": "Lavf56.40.101"
        }
    }
}

2

正如GünayGültekin所写,您只能获得特定的属性,但是引号缺失:

mediaInfo --Output='Video;%Duration%' filename.mp4

基于此,我写了一个小包装程序来计算找到的文件的持续时间,并输出摘要:

echo "scale=2; ($(find /foo/bar -type f -exec mediainfo --Output='Video;%Duration%+' {} \; | grep -v ^$ | tr -d \\n)0)"/60000/60|bc

1

在最近的Linux发行版中,您还可以使用avconv以下信息获取信息:

$ avconv -i ch1_video_01.mpg 
avconv version 9.18-6:9.18-0ubuntu0.14.04.1, Copyright (c) 2000-2014 the Libav developers
  built on Mar 16 2015 13:19:10 with gcc 4.8 (Ubuntu 4.8.2-19ubuntu1)
[mpeg @ 0x722840] max_analyze_duration reached
Guessed Channel Layout for  Input Stream #0.1 : stereo
Input #0, mpeg, from 'ch1_video_01.mpg':
  Duration: 00:03:48.01, start: 0.274000, bitrate: 6042 kb/s
    Stream #0.0[0x1e0]: Video: mpeg2video (Main), yuv420p, 720x576 [PAR 64:45 DAR 16:9], 8000 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc
    Stream #0.1[0x1c0]: Audio: mp2, 48000 Hz, stereo, s16p, 256 kb/s
At least one output file must be specified

avconv不再随Ubuntu一起提供。
slhck
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.