How to determine video codec of a file with FFmpeg

前端 未结 4 1869
无人共我
无人共我 2021-02-06 22:38

I often have problems reading AVI files with my TV\'s DVD player if they are not DivX or Xvid (e.g., DX50 is not readable).

I\'d like to make a fast script to determine

4条回答
  •  走了就别回头了
    2021-02-06 23:03

    mediainfo

    mediainfo --Inform="Video;%Codec%" video.mkv
    

    will in my case return:

    V_MPEG4/ISO/AVC
    

    Answer made possible thanks to How to find duration of a video file using mediainfo in seconds or other formats?

    ffprobe (ffmpeg) easy way

    Assuming your video has one video stream only:

    ffprobe -v error -select_streams v:0 -show_entries stream=codec_name \
      -of default=noprint_wrappers=1:nokey=1 video.mkv
    

    Will in my case return:

    h264
    

    Answer made possible thanks to How to get video duration in seconds?

    ffprobe (ffmpeg) dirty way

    This method is easier to understand but messy.

    To get the codec information without playing back the file, use ffprobe.

    $ ffprobe video.mkv
    [...]
    Input #0, matroska,webm, from 'video.mkv':
      Metadata:
        ENCODER         : Lavf56.25.101
      Duration: 00:28:05.15, start: 0.000000, bitrate: 4353 kb/s
        Stream #0:0: Video: h264 (High 4:4:4 Predictive), yuv444p, 1280x960, SAR 1:1 DAR 4:3, 29.97 fps, 29.97 tbr, 1k tbn, 59.94 tbc (default)
        Metadata:
          ENCODER         : Lavc56.26.100 libx264
        Stream #0:1: Audio: vorbis, 48000 Hz, stereo, fltp (default)
        Metadata:
          ENCODER         : Lavc56.26.100 libvorbis
    

    To extract the video codec information - since ffmpeg sends information to stderr - pipe and grep it:

    $ ffprobe video.mkv 2>&1 >/dev/null | grep Stream.*Video
        Stream #0:0: Video: h264 (High 4:4:4 Predictive), yuv444p, 1280x960, SAR 1:1 DAR 4:3, 29.97 fps, 29.97 tbr, 1k tbn, 59.94 tbc (default)
    

    To reduce the output even further, introduce sed:

    $ ffprobe video.mkv 2>&1 >/dev/null |grep Stream.*Video | sed -e 's/.*Video: //' -e 's/[, ].*//'
    h264
    

提交回复
热议问题