0

How can I change the output order of FFprobe?

ffprobe -hide_banner -show_streams -show_format space.mkv -of json=c=0 -o output.json creates a json output file with the streams sections first and the format section last.

I need the reverse order (format section first, streams section last).

But reordering the parameters (i.e. -show_format -show_streams) has no effect unfortunately.

This is the output of the command above:

{
    "streams": [
        {
            "index": 0,
            "codec_name": "h264",
            "codec_long_name": "H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10",
            "profile": "Main",
            "codec_type": "video",
            "codec_tag_string": "[0][0][0][0]",
            "codec_tag": "0x0000",
            "width": 256,
            "height": 144,
            "coded_width": 256,
            "coded_height": 144,
            "closed_captions": 0,
            "film_grain": 0,
            "has_b_frames": 1,
            "sample_aspect_ratio": "1:1",
            "display_aspect_ratio": "16:9",
            "pix_fmt": "yuv420p",
            "level": 11,
            "color_range": "tv",
            "color_space": "bt709",
            "color_transfer": "bt709",
            "color_primaries": "bt709",
            "chroma_location": "left",
            "field_order": "progressive",
            "refs": 1,
            "is_avc": "true",
            "nal_length_size": "4",
            "r_frame_rate": "3737/250",
            "avg_frame_rate": "3737/250",
            "time_base": "1/1000",
            "start_pts": 0,
            "start_time": "0.000000",
            "bits_per_raw_sample": "8",
            "extradata_size": 41,
            "disposition": {
                "default": 1,
                "dub": 0,
                "original": 0,
                "comment": 0,
                "lyrics": 0,
                "karaoke": 0,
                "forced": 0,
                "hearing_impaired": 0,
                "visual_impaired": 0,
                "clean_effects": 0,
                "attached_pic": 0,
                "timed_thumbnails": 0,
                "captions": 0,
                "descriptions": 0,
                "metadata": 0,
                "dependent": 0,
                "still_image": 0
            },
            "tags": {
                "HANDLER_NAME": "ISO Media file produced by Google Inc.",
                "VENDOR_ID": "[0][0][0][0]",
                "DURATION": "00:10:53.276000000"
            }
        },
        {
            "index": 1,
            "codec_name": "aac",
            "codec_long_name": "AAC (Advanced Audio Coding)",
            "profile": "HE-AAC",
            "codec_type": "audio",
            "codec_tag_string": "[0][0][0][0]",
            "codec_tag": "0x0000",
            "sample_fmt": "fltp",
            "sample_rate": "44100",
            "channels": 2,
            "channel_layout": "stereo",
            "bits_per_sample": 0,
            "initial_padding": 0,
            "r_frame_rate": "0/0",
            "avg_frame_rate": "0/0",
            "time_base": "1/1000",
            "start_pts": 0,
            "start_time": "0.000000",
            "extradata_size": 25,
            "disposition": {
                "default": 1,
                "dub": 0,
                "original": 0,
                "comment": 0,
                "lyrics": 0,
                "karaoke": 0,
                "forced": 0,
                "hearing_impaired": 0,
                "visual_impaired": 0,
                "clean_effects": 0,
                "attached_pic": 0,
                "timed_thumbnails": 0,
                "captions": 0,
                "descriptions": 0,
                "metadata": 0,
                "dependent": 0,
                "still_image": 0
            },
            "tags": {
                "HANDLER_NAME": "ISO Media file produced by Google Inc.",
                "VENDOR_ID": "[0][0][0][0]",
                "DURATION": "00:10:53.409000000"
            }
        }
    ],
    "format": {
        "filename": "space.mkv",
        "nb_streams": 2,
        "nb_programs": 0,
        "format_name": "matroska,webm",
        "format_long_name": "Matroska / WebM",
        "start_time": "0.000000",
        "duration": "653.409000",
        "size": "5252652",
        "bit_rate": "64310",
        "probe_score": 100,
        "tags": {
            "title": "SpaceX Starship explodes on first launch attempt",
            "COMMENT": "https://www.youtube.com/watch?v=gk1BViilFFk",
            "COMPATIBLE_BRANDS": "iso6avc1mp41",
            "MAJOR_BRAND": "dash",
            "MINOR_VERSION": "0",
            "ARTIST": "CNN",
            "DATE": "20230420",
            "DESCRIPTION": "SpaceX’s Starship, the most powerful rocket ever built, took off from a launch pad on the coast of South Texas, but exploded midair before stage separation. #CNN #News",
            "SYNOPSIS": "SpaceX’s Starship, the most powerful rocket ever built, took off from a launch pad on the coast of South Texas, but exploded midair before stage separation. #CNN #News",
            "PURL": "https://www.youtube.com/watch?v=gk1BViilFFk",
            "ENCODER": "Lavf60.4.101"
        }
    }
}
3
  • 2
    The order is hardcoded :(
    – Gyan
    May 1 at 11:33
  • If you know this to be the case (and as a bonus can demonstrate it), please post this as an answer. Assuming there is no way to change the result with FFprobe itself, I will accept this as the correct answer.
    – summerrain
    May 1 at 13:09
  • Why downvote? This is an important question for me.
    – summerrain
    May 2 at 0:46

1 Answer 1

1

The order in which sections are printed is hard-coded and insensitive to user specification.

This is the layout in the source.

if (do_read_frames || do_read_packets) {
...
}

if (do_show_programs) {
...
}

if (do_show_streams) {
...
}
if (do_show_chapters) {
...
}
if (do_show_format) {
...
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.