How to find out exact container/format of a video file using ffprobe?
Asked Answered
C

1

8

I would like to find out the exact format/container of a video file using ffprobe but I am unable to reach to the "exact" part of it.

When I run this sample command:
ffprobe -hide_banner -loglevel fatal -show_error -show_format -print_format json INPUT
I receive this output:

{
    "format": {
        "filename": "INPUT",
        "nb_streams": 2,
        "nb_programs": 0,
        "format_name": "matroska,webm",
        "format_long_name": "Matroska / WebM",
        "start_time": "0.000000",
        "duration": "2.969000",
        "size": "2376430",
        "bit_rate": "6403314",
        "probe_score": 100,
        "tags": {
            "COM.ANDROID.VERSION": "9",
            "MAJOR_BRAND": "mp42",
            "MINOR_VERSION": "0",
            "COMPATIBLE_BRANDS": "isommp42",
            "COM.ANDROID.CAPTURE.FPS": "30.000000",
            "ENCODER": "Lavf57.83.100"
        }
    }
}

As you may have understood, ffprobe gives a list of formats inside the format_name value. This is true for several video formats like mp4, mkv, webm, etc.

Whereas, mediainfo is able to find out the exact type of format, i.e. it outputs a single Format like below:
Command: mediainfo INPUT
Output:

General
Unique ID                                : 41836023869371892704046005573890259380 (0x1F79533A912A2117C3D4CEB704EAB9B4)
Complete name                            : intermediate.mkv
Format                                   : Matroska
Format version                           : Version 4 / Version 2
File size                                : 2.27 MiB
Duration                                 : 2 s 969 ms
Overall bit rate mode                    : Variable
Overall bit rate                         : 6 403 kb/s
Writing application                      : Lavf57.83.100
Writing library                          : Lavf57.83.100
ErrorDetectionType                       : Per level 1
COM.ANDROID.CAPTURE.FPS                  : 30.000000
COM.ANDROID.VERSION                      : 9

*Outputs truncated for decluttering info

Can anyone guide me as to how to achieve this using ffprobe itself?

Capetian answered 8/7, 2020 at 13:0 Comment(2)
Not possible. Specific mode is identified by the demuxer but isn't a standard exported field.Certified
Yes, I haven't found any command combination which outputs this, but ffprobe should be able to do this like mediainfo and any mime_type inferrer like python-magic is able toCapetian
B
5

They're both providing you with the exact same info. The challenge you're running into has to do with ffmpeg's quirkiness.

It appears to me the problem you're running into is perhaps a matter of nomenclature. The ffmpeg output stream you mention does contain ffmpeg's evaluation of the file's container format.

"format_name": "matroska,webm",

If you only want that piece of information, a command such as this (shown in Linux BaSH/SHell):

container=$(ffprobe -v quiet -show_entries format=format_name -of default=noprint_wrappers=1:nokey=1 "$filename") # identify file container type (format)

which in the case of your example would return

# container="matroska,webm"

ffmpeg can be very confusing. For instance, it refers to file containers as "formats" and yet if you are encoding into a file container, it calls them "muxers"

Taking ffmpeg's logic a bit further and comparing it to mediainfo, in your example they are telling you the same thing. The kicker is ffmpeg's peculiarities. ffmpeg reports a Matroska file container as "matroska,webm" which incidentally is the same manner in which ffmpeg refers to its Matroska decoder (demuxer). Yet, if you're encoding a Matroska container, ffmpeg calls the corresponding encoder (muxer) simply "matroska" - in line with how mediainfo reports the same container type.

I hope this helps versus confuses you more. The bottom line is both ffmpeg and mediainfo are providing you the exact same information. Their difference is ffmpeg is more granular. It reports the reading of a file as its demuxer/decoder type for the container. Your example is reported by ffmpeg as "matroska,webm" because ffmpeg uses the same decoder for Matroska and WebM files. Mediainfo OTOH, is more straightforward. It knows the container type is Matroska (WebM is simply a form of Matroska container), and therefore mediainfo reports it simply as a Matroska file (as I said, it's straightforward).

ffmpeg is more specific; mediainfo more general.

Benton answered 7/1, 2021 at 18:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.