当前位置: 首页>>技术教程>>正文


从 命令行 工具获取有关视频的信息

, ,

问题描述

如何使用 命令行 工具获取有关视频的信息? (例如视频时长、音频编解码器、比特率等)

最佳方案

您有几个命令可以获取该信息:

avprobe from the package libav-tools is pretty good.

Sample output avprobe somefile.mp4

avprobe version 0.8.4-4:0.8.4-0ubuntu0.12.04.1, Copyright (c) 2007-2012 the Libav developers   built on Nov  6 2012 16:51:33 with gcc 4.6.3 Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'somefile.mp4':   Metadata:     major_brand     : avc1     minor_version   : 0     compatible_brands: isomavc1     creation_time   : 2012-08-10 15:01:14   Duration: 00:01:02.55, start: 0.000000, bitrate: 682 kb/s     Stream #0.0(und): Video: h264 (High), yuv420p, 1904x1040 [PAR 1:1 DAR 119:65], 680 kb/s, 19.18 fps, 20 tbr, 20 tbn, 40 tbc     Metadata:     creation_time   : 2012-08-10 15:01:14 

To add to Thunar custom action, in relation to what was suggested here, the analog formula to add would be:

gnome-terminal --window-with-profile=new1 -e "avprobe %f" 

来源:Command to see media file info in terminal?(然后复制)。

你还有:

You can use MPlayer to get that information.

$ mplayer -vo null -ao null -identify -frames 0 foo.avi 

来源:https://superuser.com/questions/55780/linux-命令行-tool-to-get-bitrate-of-divx-xvid

次佳方案

有几种方法可以实现这一点。这是三种方法,使用三种不同的实用程序。

使用 exiftool

  1. 使用命令 sudo apt-get install libimage-exiftool-perl 安装 libimage-exiftool-perl

  2. 运行 exiftool /path/to/file

  3. 你得到的输出类似于:

    ExifTool Version Number         : 9.04
    File Name                       : filename.avi
    Directory                       : Path/To/File
    File Size                       : ### MB
    File Modification Date/Time     : 2013:04:14 10:46:51+04:00
    File Access Date/Time           : 2013:05:19 09:21:08+04:00
    File Permissions                : rwxrwxr--
    File Type                       : AVI
    MIME Type                       : video/x-msvideo
    Frame Rate                      : 25
    Max Data Rate                   : 0 kB/s
    Frame Count                     : 105154
    Stream Count                    : 2
    Stream Type                     : Video
    Video Codec                     : xvid
    Video Frame Rate                : 25
    Video Frame Count               : 105154
    Quality                         : 10000
    Sample Size                     : Variable
    Image Width                     : 640
    Image Height                    : 360
    Planes                          : 1
    Bit Depth                       : 12
    Compression                     : XVID
    Image Length                    : 1382400
    Pixels Per Meter X              : 0
    Pixels Per Meter Y              : 0
    Num Colors                      : Use BitDepth
    Num Important Colors            : All
    Audio Codec                     : 
    Audio Sample Rate               : 41.67
    Audio Sample Count              : 175252
    Encoding                        : MP3
    Num Channels                    : 2
    Sample Rate                     : 48000
    Avg Bytes Per Sec               : 16000
    Bits Per Sample                 : 0
    Stream Name                     : filename.audio
    Duration                        : 1:10:06
    Image Size                      : 640x360
    

来源:http://ubuntuforums.org/showthread.php?t=474839&p=2851338#post2851338


使用 ffmpeg

  1. 使用命令 sudo apt-get install ffmpeg 安装 ffmpeg

  2. 运行 ffmpeg -i /path/to/file

  3. 你得到的输出类似于:

    Input #0, avi, from 'Path/To/File':
      Duration: 01:10:06.16, start: 0.000000, bitrate: 1172 kb/s
        Stream #0.0: Video: mpeg4 (Advanced Simple Profile), yuv420p, 640x360 [PAR 1:1 DAR 16:9], 25 tbr, 25 tbn, 25 tbc
        Stream #0.1: Audio: mp3, 48000 Hz, stereo, s16, 128 kb/s
        Metadata:
           title           : filename.audio
    

来源:http://www.commandlinefu.com/commands/view/2207/get-video-information-with-ffmpeg


使用播放器

  1. 使用命令 sudo apt-get install mplayer 安装 mplayer

  2. 运行 mplayer -vo null -ao null -identify -frames 0 /path/to/file

  3. 你得到的输出类似于:

    Playing Path/To/File.
    libavformat version 53.21.1 (external)
    Mismatching header version 53.19.0
    AVI file format detected.
    ID_VIDEO_ID=0
    [aviheader] Video stream found, -vid 0
    ID_AUDIO_ID=1
    [aviheader] Audio stream found, -aid 1
    VIDEO:  [XVID]  640x360  12bpp  25.000 fps  1031.9 kbps (126.0 kbyte/s)
    Load subtitles in Path/To/File
    ID_FILENAME=Path/To/File
    ID_DEMUXER=avi
    ID_VIDEO_FORMAT=XVID
    ID_VIDEO_BITRATE=1031880
    ID_VIDEO_WIDTH=640
    ID_VIDEO_HEIGHT=360
    ID_VIDEO_FPS=25.000
    ID_VIDEO_ASPECT=0.0000
    ID_AUDIO_FORMAT=85
    ID_AUDIO_BITRATE=127992
    ID_AUDIO_RATE=0
    ID_AUDIO_NCH=0
    ID_START_TIME=0.00
    ID_LENGTH=4206.16
    ID_SEEKABLE=1
    ID_CHAPTERS=0
    ==========================================================================
    Opening video decoder: [ffmpeg] FFmpeg's libavcodec codec family
    libavcodec version 53.35.0 (external)
    Mismatching header version 53.32.2
    Unsupported PixelFormat 61
    Unsupported PixelFormat 53
    Unsupported PixelFormat 81
    Selected video codec: [ffodivx] vfm: ffmpeg (FFmpeg MPEG-4)
    ==========================================================================
    ID_VIDEO_CODEC=ffodivx
    ==========================================================================
    Requested audio codec family [mpg123] (afm=mpg123) not available.
    Enable it at compilation.
    Opening audio decoder: [ffmpeg] FFmpeg/libavcodec audio decoders
    AUDIO: 48000 Hz, 2 ch, floatle, 128.0 kbit/4.17% (ratio: 16000->384000)
    ID_AUDIO_BITRATE=128000
    ID_AUDIO_RATE=48000
    ID_AUDIO_NCH=2
    Selected audio codec: [ffmp3float] afm: ffmpeg (FFmpeg MPEG layer-3 audio)
    ==========================================================================
    AO: [null] 48000Hz 2ch floatle (4 bytes per sample)
    ID_AUDIO_CODEC=ffmp3float
    Starting playback...
    
    
    Exiting... (End of file)
    ID_EXIT=EOF
    

来源:https://superuser.com/a/55802

参考资料

本文由Ubuntu问答整理, 博文地址: https://ubuntuqa.com/article/11969.html,未经允许,请勿转载。