mediainfo

package module
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 22, 2026 License: GPL-2.0 Imports: 4 Imported by: 0

README

███╗   ███╗███████╗██████╗ ██╗ █████╗ ██╗███╗   ██╗███████╗ ██████╗
████╗ ████║██╔════╝██╔══██╗██║██╔══██╗██║████╗  ██║██╔════╝██╔═══██╗
██╔████╔██║█████╗  ██║  ██║██║███████║██║██╔██╗ ██║█████╗  ██║   ██║
██║╚██╔╝██║██╔══╝  ██║  ██║██║██╔══██║██║██║╚██╗██║██╔══╝  ██║   ██║
██║ ╚═╝ ██║███████╗██████╔╝██║██║  ██║██║██║ ╚████║██║     ╚██████╔╝
╚═╝     ╚═╝╚══════╝╚═════╝ ╚═╝╚═╝  ╚═╝╚═╝╚═╝  ╚═══╝╚═╝      ╚═════╝

Go rewrite of MediaInfo CLI.

Installation

  • Homebrew (macOS):
brew tap autobrr/go-mediainfo https://github.com/autobrr/go-mediainfo
brew install --cask autobrr/go-mediainfo/mediainfo

Note: Homebrew’s official MediaInfo install can conflict (media-info / mediainfo). This cask also links go-mediainfo so you can run both:

go-mediainfo version
  • Go install (requires Go toolchain):
go install github.com/autobrr/go-mediainfo/cmd/mediainfo@latest
  • Latest release (one-liner, Linux x86_64):
    • Replace linux_amd64 with linux_arm64, darwin_amd64, or darwin_arm64 as needed.
curl -sL "$(curl -s https://api.github.com/repos/autobrr/go-mediainfo/releases/latest | grep browser_download_url | grep linux_amd64 | cut -d\" -f4)" | tar -xz -C /usr/local/bin

Library Usage (Go)

go get github.com/autobrr/go-mediainfo@latest
import (
	"fmt"

	mediainfo "github.com/autobrr/go-mediainfo"
)

func main() {
	reports, err := mediainfo.AnalyzeFiles(
		[]string{"movie.mkv"},
		mediainfo.WithParseSpeed(0.5),
	)
	if err != nil {
		panic(err)
	}

	out, err := mediainfo.Render(reports, mediainfo.OutputJSON)
	if err != nil {
		panic(err)
	}
	fmt.Println(out)
}

Usage

Recommended (likely what you want):

mediainfo /path/to/file
mediainfo /path/to/file --Output=JSON --Language=raw
mediainfo /path/to/file --Output=JSON --Language=raw --ParseSpeed=0.5
mediainfo /path/to/dir
mediainfo --Info-Parameters
mediainfo --Version
mediainfo update
mediainfo version

Path is required (file or directory).

Default output: text. Footer is separated from media details by a blank line and uses the projection's aligned label column: ReportBy ... : go-mediainfo - vX.Y.Z.

Options

  • --Output=... (TEXT/JSON/XML/OLDXML/HTML/CSV/EBUCore/EBUCore_JSON/PBCore/PBCore2/Graph_Svg/Graph_Dot)
  • --Language=raw (non-translated unique identifiers; recommended for parity)
  • -lang=raw (alias for --Language=raw)
  • --LogFile=... (write output to a file)
  • --BOM (write UTF-8 BOM on Windows)
  • --ParseSpeed=0..1 (speed/accuracy tradeoff; default 0.5)
  • --File_TestContinuousFileNames=0|1 (MediaInfo-style continuous filename probing; default 0)
  • --Help, --Help-Output
  • --Info-Parameters
  • -f, --Full (reserved; currently no-op)

Embedded metadata safety

Embedded attachments and cover art are inspected in memory only; they are never extracted, written, or executed. Per-file parsing limits embedded assets to 256, attachment names to 4 KiB each, MIME values to 1 KiB each, and retained metadata strings to 1 MiB total. Matroska image inspection retains at most 4 MiB per image and 32 MiB total; ID3 image probes retain at most 64 KiB each; ICC decompression is capped at 4 MiB. FLAC picture payloads are skipped after their bounded headers.

Malformed, truncated, unknown-sized, or over-limit embedded metadata is omitted while valid audio/video tracks continue parsing. This intentionally differs from upstream output for hostile inputs. Text and CSV outputs visibly escape control characters; CSV also neutralizes formula-leading metadata and formula-bearing injected cells. JSON continues to use Go JSON escaping.

Commands

  • update (self-update this binary; release builds only)
  • version (print go-mediainfo version)

License

GPL-2.0-or-later. See LICENSE.

Documentation

Overview

Package mediainfo exposes go-mediainfo as an importable library.

Import path:

import mediainfo "github.com/autobrr/go-mediainfo"

Typical flow:

  1. Analyze one or more files with AnalyzeFile/AnalyzeFiles.
  2. Render reports with Render and an OutputFormat.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatVersion

func FormatVersion(version string) string

FormatVersion normalizes the version label to MediaInfo style.

func InfoParameters

func InfoParameters() string

InfoParameters returns the supported info parameter listing.

func Render

func Render(reports []Report, format OutputFormat) (string, error)

Render renders reports with the selected format.

func RenderWithOptions added in v0.5.0

func RenderWithOptions(reports []Report, format OutputFormat, options RenderOptions) (string, error)

RenderWithOptions renders reports with the selected format and options. It returns an error when format is unsupported. Language affects text output only; other formats remain unchanged.

func SetAppVersion

func SetAppVersion(version string)

SetAppVersion sets the version shown in rendered metadata.

Types

type AnalyzeOption

type AnalyzeOption func(*core.AnalyzeOptions)

AnalyzeOption configures parsing behavior.

func WithParseSpeed

func WithParseSpeed(value float64) AnalyzeOption

WithParseSpeed sets ParseSpeed (0..1). If unset, default is 0.5.

func WithTestContinuousFileNames

func WithTestContinuousFileNames(enabled bool) AnalyzeOption

WithTestContinuousFileNames enables MediaInfo-style continuous file probing.

type Field

type Field = core.Field

Field represents one MediaInfo field/value pair.

type OutputFormat

type OutputFormat string

OutputFormat is a renderer output type.

const (
	// OutputText renders text output.
	OutputText OutputFormat = "TEXT"
	// OutputJSON renders JSON output.
	OutputJSON OutputFormat = "JSON"
	// OutputXML renders XML output.
	OutputXML OutputFormat = "XML"
	// OutputOldXML renders old XML output.
	OutputOldXML OutputFormat = "OLDXML"
	// OutputHTML renders HTML output.
	OutputHTML OutputFormat = "HTML"
	// OutputCSV renders CSV output.
	OutputCSV OutputFormat = "CSV"
	// OutputEBUCore renders EBUCore output.
	OutputEBUCore OutputFormat = "EBUCORE"
	// OutputEBUCoreJSON renders EBUCore JSON output.
	OutputEBUCoreJSON OutputFormat = "EBUCORE_JSON"
	// OutputPBCore renders PBCore output.
	OutputPBCore OutputFormat = "PBCORE"
	// OutputPBCore2 renders PBCore2 output.
	OutputPBCore2 OutputFormat = "PBCORE2"
	// OutputGraphSVG renders Graph SVG output.
	OutputGraphSVG OutputFormat = "GRAPH_SVG"
	// OutputGraphDOT renders Graph DOT output.
	OutputGraphDOT OutputFormat = "GRAPH_DOT"
)

type RenderOptions added in v0.5.0

type RenderOptions struct {
	// Language selects the text projection. "raw" enables MediaInfo raw labels
	// and values; the zero value and other languages retain friendly text.
	// Non-text renderers ignore Language.
	Language string
	// InformVersion appends MediaInfo's ReportBy footer to raw-language text output.
	InformVersion bool
}

RenderOptions configures representation-specific rendering behavior.

type Report

type Report = core.Report

Report is the analysis result for one input path.

func AnalyzeFile

func AnalyzeFile(path string, options ...AnalyzeOption) (Report, error)

AnalyzeFile analyzes one file or directory path.

Example
package main

import (
	"fmt"

	mediainfo "github.com/autobrr/go-mediainfo"
)

func main() {
	report, err := mediainfo.AnalyzeFile("samples/sample.mp4")
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(report.General.Kind)
}
Output:
General

func AnalyzeFileContext added in v0.8.0

func AnalyzeFileContext(ctx context.Context, path string, options ...AnalyzeOption) (Report, error)

AnalyzeFileContext behaves like AnalyzeFile but observes ctx between reads of the input file, so a caller can bound an analysis that would otherwise block on slow storage. It returns ctx's error when the context ends before the analysis completes; ctx must be non-nil. A read already blocked in the OS still returns only when the OS completes it, and reads of any file other than the input are not cancellation-checked.

func AnalyzeFiles

func AnalyzeFiles(paths []string, options ...AnalyzeOption) ([]Report, error)

AnalyzeFiles analyzes multiple paths.

func AnalyzeFilesWithCount

func AnalyzeFilesWithCount(paths []string, options ...AnalyzeOption) ([]Report, int, error)

AnalyzeFilesWithCount analyzes multiple paths and returns report count.

type Stream

type Stream = core.Stream

Stream represents one parsed stream (General/Video/Audio/Text/Menu).

type StreamKind

type StreamKind = core.StreamKind

StreamKind identifies a MediaInfo stream category.

const (
	// StreamGeneral is the container-level stream.
	StreamGeneral StreamKind = core.StreamGeneral
	// StreamVideo is a video stream.
	StreamVideo StreamKind = core.StreamVideo
	// StreamAudio is an audio stream.
	StreamAudio StreamKind = core.StreamAudio
	// StreamText is a subtitle/caption stream.
	StreamText StreamKind = core.StreamText
	// StreamImage is an image stream.
	StreamImage StreamKind = core.StreamImage
	// StreamMenu is a menu/chapters stream.
	StreamMenu StreamKind = core.StreamMenu
)

Directories

Path Synopsis
cmd
mediainfo command
internal
cli

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL