Skip to content

muxtools.utils.ffprobe

__all__ module-attribute

__all__ = ['ProbeResult', 'ProbeFormat', 'ProbeStream']

ProbeStream pydantic-model

ProbeStream(*, raw: dict[str, Any] = dict(), index: int | None = None, codec_name: str | None = None, codec_long_name: str | None = None, codec_type: str | None = None, profile: str | None = None, width: int | None = None, height: int | None = None, sample_aspect_ratio: str | None = None, pix_fmt: str | None = None, color_range: str | None = None, color_space: str | None = None, color_transfer: str | None = None, color_primaries: str | None = None, chroma_location: str | None = None, avg_frame_rate: str | None = None, sample_fmt: str | None = None, sample_rate: int | None = None, channels: int | None = None, channel_layout: str | None = None, bits_per_sample: int | None = None, bits_per_raw_sample: int | None = None, bit_rate: int | None = None, tags: dict[str, str] = dict(), disposition: dict[str, int] = dict(), side_data_list: list[dict[str, Any]] = list())

Bases: _ProbeModel

Show JSON schema:
{
  "properties": {
    "raw": {
      "additionalProperties": true,
      "title": "Raw",
      "type": "object"
    },
    "index": {
      "anyOf": [
        {
          "type": "integer"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Index"
    },
    "codec_name": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Codec Name"
    },
    "codec_long_name": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Codec Long Name"
    },
    "codec_type": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Codec Type"
    },
    "profile": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Profile"
    },
    "width": {
      "anyOf": [
        {
          "type": "integer"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Width"
    },
    "height": {
      "anyOf": [
        {
          "type": "integer"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Height"
    },
    "sample_aspect_ratio": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Sample Aspect Ratio"
    },
    "pix_fmt": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Pix Fmt"
    },
    "color_range": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Color Range"
    },
    "color_space": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Color Space"
    },
    "color_transfer": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Color Transfer"
    },
    "color_primaries": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Color Primaries"
    },
    "chroma_location": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Chroma Location"
    },
    "avg_frame_rate": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Avg Frame Rate"
    },
    "sample_fmt": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Sample Fmt"
    },
    "sample_rate": {
      "anyOf": [
        {
          "type": "integer"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Sample Rate"
    },
    "channels": {
      "anyOf": [
        {
          "type": "integer"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Channels"
    },
    "channel_layout": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Channel Layout"
    },
    "bits_per_sample": {
      "anyOf": [
        {
          "type": "integer"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Bits Per Sample"
    },
    "bits_per_raw_sample": {
      "anyOf": [
        {
          "type": "integer"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Bits Per Raw Sample"
    },
    "bit_rate": {
      "anyOf": [
        {
          "type": "integer"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Bit Rate"
    },
    "tags": {
      "additionalProperties": {
        "type": "string"
      },
      "title": "Tags",
      "type": "object"
    },
    "disposition": {
      "additionalProperties": {
        "type": "integer"
      },
      "title": "Disposition",
      "type": "object"
    },
    "side_data_list": {
      "items": {
        "additionalProperties": true,
        "type": "object"
      },
      "title": "Side Data List",
      "type": "array"
    }
  },
  "title": "ProbeStream",
  "type": "object"
}

Fields:

Validators:

index pydantic-field

index: int | None = None

codec_name pydantic-field

codec_name: str | None = None

codec_long_name pydantic-field

codec_long_name: str | None = None

codec_type pydantic-field

codec_type: str | None = None

profile pydantic-field

profile: str | None = None

width pydantic-field

width: int | None = None

height pydantic-field

height: int | None = None

sample_aspect_ratio pydantic-field

sample_aspect_ratio: str | None = None

pix_fmt pydantic-field

pix_fmt: str | None = None

color_range pydantic-field

color_range: str | None = None

color_space pydantic-field

color_space: str | None = None

color_transfer pydantic-field

color_transfer: str | None = None

color_primaries pydantic-field

color_primaries: str | None = None

chroma_location pydantic-field

chroma_location: str | None = None

avg_frame_rate pydantic-field

avg_frame_rate: str | None = None

sample_fmt pydantic-field

sample_fmt: str | None = None

sample_rate pydantic-field

sample_rate: int | None = None

channels pydantic-field

channels: int | None = None

channel_layout pydantic-field

channel_layout: str | None = None

bits_per_sample pydantic-field

bits_per_sample: int | None = None

bits_per_raw_sample pydantic-field

bits_per_raw_sample: int | None = None

bit_rate pydantic-field

bit_rate: int | None = None

tags pydantic-field

tags: dict[str, str] = dict()

disposition pydantic-field

disposition: dict[str, int] = dict()

side_data_list pydantic-field

side_data_list: list[dict[str, Any]] = list()

ProbeFormat pydantic-model

ProbeFormat(*, raw: dict[str, Any] = dict(), nb_streams: int | None = None, format_name: str | None = None, format_long_name: str | None = None, tags: dict[str, str] = dict())

Bases: _ProbeModel

Show JSON schema:
{
  "properties": {
    "raw": {
      "additionalProperties": true,
      "title": "Raw",
      "type": "object"
    },
    "nb_streams": {
      "anyOf": [
        {
          "type": "integer"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Nb Streams"
    },
    "format_name": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Format Name"
    },
    "format_long_name": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Format Long Name"
    },
    "tags": {
      "additionalProperties": {
        "type": "string"
      },
      "title": "Tags",
      "type": "object"
    }
  },
  "title": "ProbeFormat",
  "type": "object"
}

Fields:

Validators:

nb_streams pydantic-field

nb_streams: int | None = None

format_name pydantic-field

format_name: str | None = None

format_long_name pydantic-field

format_long_name: str | None = None

tags pydantic-field

tags: dict[str, str] = dict()

ProbeResult pydantic-model

ProbeResult(*, raw: dict[str, Any] = dict(), format: ProbeFormat, streams: list[ProbeStream] = list(), chapters: list[dict[str, Any]] = list())

Bases: _ProbeModel

Show JSON schema:
{
  "$defs": {
    "ProbeFormat": {
      "properties": {
        "raw": {
          "additionalProperties": true,
          "title": "Raw",
          "type": "object"
        },
        "nb_streams": {
          "anyOf": [
            {
              "type": "integer"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Nb Streams"
        },
        "format_name": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Format Name"
        },
        "format_long_name": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Format Long Name"
        },
        "tags": {
          "additionalProperties": {
            "type": "string"
          },
          "title": "Tags",
          "type": "object"
        }
      },
      "title": "ProbeFormat",
      "type": "object"
    },
    "ProbeStream": {
      "properties": {
        "raw": {
          "additionalProperties": true,
          "title": "Raw",
          "type": "object"
        },
        "index": {
          "anyOf": [
            {
              "type": "integer"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Index"
        },
        "codec_name": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Codec Name"
        },
        "codec_long_name": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Codec Long Name"
        },
        "codec_type": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Codec Type"
        },
        "profile": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Profile"
        },
        "width": {
          "anyOf": [
            {
              "type": "integer"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Width"
        },
        "height": {
          "anyOf": [
            {
              "type": "integer"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Height"
        },
        "sample_aspect_ratio": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Sample Aspect Ratio"
        },
        "pix_fmt": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Pix Fmt"
        },
        "color_range": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Color Range"
        },
        "color_space": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Color Space"
        },
        "color_transfer": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Color Transfer"
        },
        "color_primaries": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Color Primaries"
        },
        "chroma_location": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Chroma Location"
        },
        "avg_frame_rate": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Avg Frame Rate"
        },
        "sample_fmt": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Sample Fmt"
        },
        "sample_rate": {
          "anyOf": [
            {
              "type": "integer"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Sample Rate"
        },
        "channels": {
          "anyOf": [
            {
              "type": "integer"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Channels"
        },
        "channel_layout": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Channel Layout"
        },
        "bits_per_sample": {
          "anyOf": [
            {
              "type": "integer"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Bits Per Sample"
        },
        "bits_per_raw_sample": {
          "anyOf": [
            {
              "type": "integer"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Bits Per Raw Sample"
        },
        "bit_rate": {
          "anyOf": [
            {
              "type": "integer"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Bit Rate"
        },
        "tags": {
          "additionalProperties": {
            "type": "string"
          },
          "title": "Tags",
          "type": "object"
        },
        "disposition": {
          "additionalProperties": {
            "type": "integer"
          },
          "title": "Disposition",
          "type": "object"
        },
        "side_data_list": {
          "items": {
            "additionalProperties": true,
            "type": "object"
          },
          "title": "Side Data List",
          "type": "array"
        }
      },
      "title": "ProbeStream",
      "type": "object"
    }
  },
  "properties": {
    "raw": {
      "additionalProperties": true,
      "title": "Raw",
      "type": "object"
    },
    "format": {
      "$ref": "#/$defs/ProbeFormat"
    },
    "streams": {
      "items": {
        "$ref": "#/$defs/ProbeStream"
      },
      "title": "Streams",
      "type": "array"
    },
    "chapters": {
      "items": {
        "additionalProperties": true,
        "type": "object"
      },
      "title": "Chapters",
      "type": "array"
    }
  },
  "required": [
    "format"
  ],
  "title": "ProbeResult",
  "type": "object"
}

Fields:

Validators:

  • _keep_raw

format pydantic-field

format: ProbeFormat

streams pydantic-field

streams: list[ProbeStream] = list()

chapters pydantic-field

chapters: list[dict[str, Any]] = list()

parse_probe_json

parse_probe_json(output: str | bytes) -> ProbeResult
Source code in muxtools/utils/ffprobe.py
def parse_probe_json(output: str | bytes) -> ProbeResult:
    return ProbeResult.model_validate(json.loads(output))

probe_file

probe_file(path: Path, executable: str) -> ProbeResult
Source code in muxtools/utils/ffprobe.py
def probe_file(path: Path, executable: str) -> ProbeResult:
    result = subprocess.run(
        [executable, "-v", "error", "-show_format", "-show_streams", "-show_chapters", "-of", "json", "-i", str(path)],
        capture_output=True,
        check=True,
        encoding="utf-8",
    )
    return parse_probe_json(result.stdout)