ffprobe

package
v0.0.0-...-0fe5c75 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2019 License: AGPL-3.0 Imports: 3 Imported by: 1

README

creamy-transcode/mediainfo/ffprobe

Run ffprobe on local files and decode the output.

Usage

package main

import (
	"fmt"

	"github.com/AlbinoDrought/creamy-transcode/mediainfo/ffprobe"
	"github.com/davecgh/go-spew/spew"
)

func main() {
	result, _ := ffprobe.ProbeFile("./mediainfo/ffprobe/test_fixtures/doggo_waddling.mp4")

	for i, stream := range result.Streams {
		fmt.Printf("stream %v:\n", i)
		fmt.Printf("audio    [%v]\n", ffprobe.IsAudioStream(&stream))
		fmt.Printf("video    [%v]\n", ffprobe.IsVideoStream(&stream))
		fmt.Printf("HD video [%v]\n\n", ffprobe.IsHDVideoStream(&stream))
	}

	spew.Dump(result)
}


// output:
/*
stream 0:
audio    [false]
video    [true]
HD video [false]

stream 1:
audio    [true]
video    [false]
HD video [false]

(ffprobe.Result) {
 Streams: ([]ffprobe.Stream) (len=2 cap=4) {
  (ffprobe.Stream) {
   Index: (int) 0,
   CodecName: (string) (len=4) "h264",
   CodecLongName: (string) (len=41) "H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10",
   Profile: (string) (len=20) "Constrained Baseline",
   CodecType: (string) (len=5) "video",
   CodecTimeBase: (string) (len=14) "127989/7646464",
   CodecTagString: (string) (len=4) "avc1",
   CodecTag: (string) (len=10) "0x31637661",
   Width: (int) 640,
   Height: (int) 360,
   CodedWidth: (int) 640,
   CodedHeight: (int) 368,
   HasBFrames: (int) 0,
   SampleAspectRatio: (string) (len=3) "1:1",
   DisplayAspectRatio: (string) (len=4) "16:9",
   PixFmt: (string) (len=7) "yuv420p",
   Level: (int) 30,
   ChromaLocation: (string) (len=4) "left",
   Refs: (int) 1,
   IsAvc: (string) (len=4) "true",
   NalLengthSize: (string) (len=1) "4",
   RFrameRate: (string) (len=10) "29869/1000",
   AvgFrameRate: (string) (len=14) "3823232/127989",
   TimeBase: (string) (len=7) "1/29869",
   StartPts: (int) 0,
   StartTime: (string) (len=8) "0.000000",
   DurationTs: (int) 127989,
   Duration: (string) (len=8) "4.285011",
   BitRate: (string) (len=6) "276883",
   BitsPerRawSample: (string) (len=1) "8",
   NbFrames: (string) (len=3) "128",
   Disposition: (struct { Default int "json:\"default\""; Dub int "json:\"dub\""; Original int "json:\"original\""; Comment int "json:\"comment\""; Lyrics int "json:\"lyrics\""; Karaoke int "json:\"karaoke\""; Forced int "json:\"forced\""; HearingImpaired int "json:\"hearing_impaired\""; VisualImpaired int "json:\"visual_impaired\""; CleanEffects int "json:\"clean_effects\""; AttachedPic int "json:\"attached_pic\""; TimedThumbnails int "json:\"timed_thumbnails\"" }) {
    Default: (int) 1,
    Dub: (int) 0,
    Original: (int) 0,
    Comment: (int) 0,
    Lyrics: (int) 0,
    Karaoke: (int) 0,
    Forced: (int) 0,
    HearingImpaired: (int) 0,
    VisualImpaired: (int) 0,
    CleanEffects: (int) 0,
    AttachedPic: (int) 0,
    TimedThumbnails: (int) 0
   },
   SampleFmt: (string) "",
   SampleRate: (string) "",
   Channels: (int) 0,
   ChannelLayout: (string) "",
   BitsPerSample: (int) 0
  },
  (ffprobe.Stream) {
   Index: (int) 1,
   CodecName: (string) (len=3) "aac",
   CodecLongName: (string) (len=27) "AAC (Advanced Audio Coding)",
   Profile: (string) (len=2) "LC",
   CodecType: (string) (len=5) "audio",
   CodecTimeBase: (string) (len=7) "1/44100",
   CodecTagString: (string) (len=4) "mp4a",
   CodecTag: (string) (len=10) "0x6134706d",
   Width: (int) 0,
   Height: (int) 0,
   CodedWidth: (int) 0,
   CodedHeight: (int) 0,
   HasBFrames: (int) 0,
   SampleAspectRatio: (string) "",
   DisplayAspectRatio: (string) "",
   PixFmt: (string) "",
   Level: (int) 0,
   ChromaLocation: (string) "",
   Refs: (int) 0,
   IsAvc: (string) "",
   NalLengthSize: (string) "",
   RFrameRate: (string) (len=3) "0/0",
   AvgFrameRate: (string) (len=3) "0/0",
   TimeBase: (string) (len=7) "1/44100",
   StartPts: (int) 0,
   StartTime: (string) (len=8) "0.000000",
   DurationTs: (int) 195584,
   Duration: (string) (len=8) "4.435011",
   BitRate: (string) (len=5) "95999",
   BitsPerRawSample: (string) "",
   NbFrames: (string) (len=3) "191",
   Disposition: (struct { Default int "json:\"default\""; Dub int "json:\"dub\""; Original int "json:\"original\""; Comment int "json:\"comment\""; Lyrics int "json:\"lyrics\""; Karaoke int "json:\"karaoke\""; Forced int "json:\"forced\""; HearingImpaired int "json:\"hearing_impaired\""; VisualImpaired int "json:\"visual_impaired\""; CleanEffects int "json:\"clean_effects\""; AttachedPic int "json:\"attached_pic\""; TimedThumbnails int "json:\"timed_thumbnails\"" }) {
    Default: (int) 1,
    Dub: (int) 0,
    Original: (int) 0,
    Comment: (int) 0,
    Lyrics: (int) 0,
    Karaoke: (int) 0,
    Forced: (int) 0,
    HearingImpaired: (int) 0,
    VisualImpaired: (int) 0,
    CleanEffects: (int) 0,
    AttachedPic: (int) 0,
    TimedThumbnails: (int) 0
   },
   SampleFmt: (string) (len=4) "fltp",
   SampleRate: (string) (len=5) "44100",
   Channels: (int) 2,
   ChannelLayout: (string) (len=6) "stereo",
   BitsPerSample: (int) 0
  }
 },
 Format: (ffprobe.Format) {
  Filename: (string) (len=52) "./mediainfo/ffprobe/test_fixtures/doggo_waddling.mp4",
  NbStreams: (int) 2,
  NbPrograms: (int) 0,
  FormatName: (string) (len=23) "mov,mp4,m4a,3gp,3g2,mj2",
  FormatLongName: (string) (len=15) "QuickTime / MOV",
  StartTime: (string) (len=8) "0.000000",
  Duration: (string) (len=8) "4.435000",
  Size: (string) (len=6) "204141",
  BitRate: (string) (len=6) "368236",
  ProbeScore: (int) 100
 }
}
*/

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsAudioStream

func IsAudioStream(stream *Stream) bool

IsAudioStream returns true if the stream is an audio stream

func IsHDVideoStream

func IsHDVideoStream(stream *Stream) bool

IsHDVideoStream returns true if the stream is a high-definition video stream (min 720p)

func IsVideoStream

func IsVideoStream(stream *Stream) bool

IsVideoStream returns true if the stream is a video stream

Types

type Format

type Format struct {
	Filename       string `json:"filename"`
	NbStreams      int    `json:"nb_streams"`
	NbPrograms     int    `json:"nb_programs"`
	FormatName     string `json:"format_name"`
	FormatLongName string `json:"format_long_name"`
	StartTime      string `json:"start_time"`
	Duration       string `json:"duration"`
	Size           string `json:"size"`
	BitRate        string `json:"bit_rate"`
	ProbeScore     int    `json:"probe_score"`
}

Format is a golang-consumable representation of the JSON format output from FFProbe

type Result

type Result struct {
	Streams []Stream `json:"streams"`
	Format  Format   `json:"format"`
}

Result is a golang-consumable representation of the JSON output from FFProbe

func ProbeFile

func ProbeFile(path string) (Result, error)

ProbeFile uses ffprobe to fetch media info from an ffprobe-compatible path

type Stream

type Stream struct {
	Index              int    `json:"index"`
	CodecName          string `json:"codec_name"`
	CodecLongName      string `json:"codec_long_name"`
	Profile            string `json:"profile"`
	CodecType          string `json:"codec_type"`
	CodecTimeBase      string `json:"codec_time_base"`
	CodecTagString     string `json:"codec_tag_string"`
	CodecTag           string `json:"codec_tag"`
	Width              int    `json:"width,omitempty"`
	Height             int    `json:"height,omitempty"`
	CodedWidth         int    `json:"coded_width,omitempty"`
	CodedHeight        int    `json:"coded_height,omitempty"`
	HasBFrames         int    `json:"has_b_frames,omitempty"`
	SampleAspectRatio  string `json:"sample_aspect_ratio,omitempty"`
	DisplayAspectRatio string `json:"display_aspect_ratio,omitempty"`
	PixFmt             string `json:"pix_fmt,omitempty"`
	Level              int    `json:"level,omitempty"`
	ChromaLocation     string `json:"chroma_location,omitempty"`
	Refs               int    `json:"refs,omitempty"`
	IsAvc              string `json:"is_avc,omitempty"`
	NalLengthSize      string `json:"nal_length_size,omitempty"`
	RFrameRate         string `json:"r_frame_rate"`
	AvgFrameRate       string `json:"avg_frame_rate"`
	TimeBase           string `json:"time_base"`
	StartPts           int    `json:"start_pts"`
	StartTime          string `json:"start_time"`
	DurationTs         int    `json:"duration_ts"`
	Duration           string `json:"duration"`
	BitRate            string `json:"bit_rate"`
	BitsPerRawSample   string `json:"bits_per_raw_sample,omitempty"`
	NbFrames           string `json:"nb_frames"`
	Disposition        struct {
		Default         int `json:"default"`
		Dub             int `json:"dub"`
		Original        int `json:"original"`
		Comment         int `json:"comment"`
		Lyrics          int `json:"lyrics"`
		Karaoke         int `json:"karaoke"`
		Forced          int `json:"forced"`
		HearingImpaired int `json:"hearing_impaired"`
		VisualImpaired  int `json:"visual_impaired"`
		CleanEffects    int `json:"clean_effects"`
		AttachedPic     int `json:"attached_pic"`
		TimedThumbnails int `json:"timed_thumbnails"`
	} `json:"disposition"`
	SampleFmt     string `json:"sample_fmt,omitempty"`
	SampleRate    string `json:"sample_rate,omitempty"`
	Channels      int    `json:"channels,omitempty"`
	ChannelLayout string `json:"channel_layout,omitempty"`
	BitsPerSample int    `json:"bits_per_sample,omitempty"`
}

Stream is a golang-compatible representation of the JSON stream output from FFProbe

Jump to

Keyboard shortcuts

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