Get Video Codec of File using FFmpeg

Get Video Codec of File using FFmpeg

FFmpeg provides tools for inspecting multimedia files and extracting information about their streams. Identifying the codec stored in a video file can be useful when checking media compatibility, investigating encoding settings, or preparing a file for further processing. This tutorial shows how to get video codec of file using FFmpeg.

The ffprobe utility can be used to determine which video codec is associated with a particular file without decoding or converting the video.

Download a sample video file for testing:

curl -sSo test.mp4 https://raw.githubusercontent.com/mediaelement/mediaelement-files/master/big_buck_bunny.mp4

The video codec can then be retrieved by using the following command:

ffprobe -v error -select_streams v:0 -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey=1 test.mp4

The command produces:

h264

Command breakdown:

  • ffprobe - inpects multimedia files and reports information about their streams.
  • -v error - sets the logging level to error, suppressing informational messages while still displaying errors. It prevents informational output from cluttering the codec result.
  • -select_streams v:0 - selects the first video stream from the input file.
  • -show_entries stream=codec_name - requests only the codec name from the selected stream.
  • -of default=noprint_wrappers=1:nokey=1 - uses the default output format while removing wrappers and field names.
  • test.mp4 - specifies the video file being inspected.

Leave a Comment

Cancel reply

Your email address will not be published.