When we have a video or a media file of any kind, and we want to get its metadata information, we can use ffmpeg to get file this data, such as file type, the video codec used in the file, or the codec audio, video resolution or many other relevant information.
In this example we get information from a file example.mp4 with the command:
ffmpeg -i example.mp4 -hide_banner
We are using two parameters:
- -i is used to indicate the input file from which we are getting the information.
- -hide_banner. This parameter is used to suppress version and another information printing.
Here you can see the result. In the result appears information about the container file, and some basic and useful information such as video duration (1:45.71) or bitrate (440 kb/s). It also shows that the file has two streams with information about each one. (Stream #0:0 which is the video stream, and Stream #0:1 which is the audio one)
From the video stream we can get the video codec used (h264), video resolution (640px width and 360px height), video bitrate (308 kb/s, this bitrate is only for the video and obviously it is lower than the bitrate for the file) or the images per second of the video (25 frames per second).
From the audio stream we can get information about the codec (aac) or more details about the audio stream (bitrate, output freq)
This is the type of output that we can get more commonly. Video files with one video stream and one audio stream. Anyway ffmpeg supports more complex files and can get information from media files with multiple streams and more complex configurations.
Consider another case, in this case a webm file with no audio track. The file is called video.webm and we get media information with the command:
ffmpeg -i video.webm -hide_banner
In this case we get:
In this case and since this is a video that has no audio track (it has no sound), only one video track (Stream #0:0) appears. In this case the codec is VP8, and video stream has 30 frames per second (29.97 frames per second)
This information obtained by ffmpeg is basic and very useful if you need to work with these files. For example if we wanted to make sure that we have several videos with the same resolution, or with the same frames per second configuration, we should be able to verify the files using this command. Anyway this is basic information and does not appear in a easily format if we want to work with it from another program or script. If those were our needs and ffmpeg is not enough, we could use ffprobe tool included in most ffmpeg installations. ffprobe provides more information, and it displays it in a more manageable format for other applications such as JSON or XML. Use ffprobe to obtain information from video files.