« Inspecting with ffprobe
What is ffprobe
ffprobe
is a very useful command-line tool that comes with ffmpeg
. We can use it to extract and show various information about the media, for example, the resolution of a video, codec information, number of channels in an audio stream, etc.
1ffprobe seagull.mp4
1ffprobe -v error seagull.mp4
we can see that the media
information we had in the logs are also not getting printed anymore
1ffprobe -v error seagull.mp4 -show_format
We can specify the -show_format
option like this. And then it will print information about the media format.
1ffprobe -v error seagull.mp4 -show_format -show_streams
We can also add the -show_streams
option, like this, to show all the streams in the file. So we can see that the first stream is a video stream with H.264 codec, and then there is a second stream, which is an audio stream with AAC codec.
1ffprobe -v error seagull.mp4 -show_format -show_streams -print_format json
We can change the format of the output with another option called -print_format
and we can specify CSV
or XML
or JSON
or a few other formats that can be useful, for example, I'm specifying JSON
, which is particularly useful when we want to consume this information from a Node.js.
1ffprobe -v error seagull.mp4 -show_format -show_streams -print_format json -select_streams v
- Depending on your requirement, you may not want to extract all this information of the media all the time, in which case you can further limit the information to show, with more options.
- If you are only interested about the video in the file, you can select the video stream only with
-select_streams v
1ffprobe -v error seagull.mp4 -show_streams -select_streams v -show_entries stream=codec_name
We can filter the output even further, let's say we are only interested to know the codec name of the video. Then we can add -show_entries stream=codec_name
.
1ffprobe -v error seagull.mp4 -select_streams v -show_entries stream=codec_name
- You can see that it is now showing only the codec name without showing all the other info like codec type, etc., on the same level. But some other nested information is still printed. We can skip that by taking away the "-show_streams" option. Since we don't need all information it prints.
- Now we see the single field we want, but we can see these stream wrappers around it.
1ffprobe -v error seagull.mp4 -select_streams v -show_entries stream=codec_name -print_format default=noprint_wrappers=1
We can further suppress from the output, and for this, we need to add an option for the default print format, so let's add it back.
-print_format default=noprint_wrappers=1
. So we can see that the stream wrappers that were getting printed are no longer there.
1ffprobe -v error seagull.mp4 -select_streams v -show_entries stream=codec_name -print_format default=noprint_wrappers=1:nokey=1
We can be even more concise and get only the value part of the codec name without even this label. Then we can do this easily by just adding the nokey
flag, "-nokey=1".
1ffprobe -v error seagull.mp4 -show_entries format=format_long_name -print_format default=noprint_wrappers=1:nokey=1
- So in this way, we can also extract any other field from the streams, or from the format section as well.
- For example, in place of
stream=codec_name
, we can specifyformat=format_long_name
1ffprobe -v error https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/720/Big_Buck_Bunny_720_10s_1MB.mp4 -show_format -show_streams -print_format json
The media path can also be an HTTP URL, which is really useful for getting information for a media without really downloading it to the disk.