ffmpeg

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2020 License: GPL-3.0 Imports: 28 Imported by: 5

Documentation

Overview

Convenience wrapper around ffmpeg as a transcoder to DASH chunks https://github.com/go-cmd/cmd/blob/master/cmd.go was very useful while writing this module.

Index

Constants

View Source
const SegmentDuration = 5000 * time.Millisecond

SegmentDuration defines the duration of segments that ffmpeg will generate. In the transmuxing case this is really just a minimum time, the actual segments will be longer because they are cut at keyframes. For transcoding, we can force keyframes to occur exactly every SegmentDuration, so SegmentDuration will be the actual duration of the segments.

View Source
const TotalDurationInvalid = float64(-1)

Variables

View Source
var AudioEncoderPresets = map[string]EncoderParams{
	"64k-audio":  {Codecs: "mp4a.40.2", /* contains filtered or unexported fields */},
	"128k-audio": {Codecs: "mp4a.40.2", /* contains filtered or unexported fields */},
}
View Source
var FfmpegUrlPort = 8080

TODO(Leon Handreke): Figure out a better way than a package-global variable to convey this info from the top-level command flag to ffmpeg. Or maybe a setter is enough? Also this should go in some util package to build URLs

View Source
var InitialSegmentIdx int = -1

InitialSegmentIdx is a magic segment index value to denote the initial segment

Functions

func CleanTranscodingCache

func CleanTranscodingCache() error

func ComputeSegmentDurations

func ComputeSegmentDurations(sessions [][]Segment) []time.Duration

func EncoderParamsToString

func EncoderParamsToString(m EncoderParams) string

func GetAVC1Tag

func GetAVC1Tag(width int, height int, biteRate int64, frameRate *big.Rat) string

func GetHumanizedToLangTag

func GetHumanizedToLangTag() map[string]string

func GetLanguageTag

func GetLanguageTag(stream ProbeStream) string

func GetTitleOrHumanizedLanguage

func GetTitleOrHumanizedLanguage(stream ProbeStream) string

Types

type ClientCodecCapabilities

type ClientCodecCapabilities struct {
	PlayableCodecs []string `json:"playableCodecs"`
}

func (*ClientCodecCapabilities) CanPlay

func (*ClientCodecCapabilities) Filter

func (c *ClientCodecCapabilities) Filter(
	representations []StreamRepresentation) []StreamRepresentation

type DtsTimestamp

type DtsTimestamp int64
const DtsTimestampInvalid DtsTimestamp = -1

type EncoderParams

type EncoderParams struct {

	// The codecs (https://tools.ietf.org/html/rfc6381#section-3.3) that these params will produce.
	Codecs string
	// contains filtered or unexported fields
}

func EncoderParamsFromString

func EncoderParamsFromString(str string) (EncoderParams, error)

func GetSimilarEncoderParams

func GetSimilarEncoderParams(stream Stream) (EncoderParams, error)

func GetVideoEncoderPreset

func GetVideoEncoderPreset(stream Stream, name string) (EncoderParams, error)

type Interval

type Interval struct {
	TimeBase       int64
	StartTimestamp DtsTimestamp
	EndTimestamp   DtsTimestamp
}

A time interval [StartTimestamp, EndTimestamp) in DTS

func (*Interval) Duration

func (i *Interval) Duration() time.Duration

func (*Interval) EndDuration

func (i *Interval) EndDuration() time.Duration

func (*Interval) StartDuration

func (i *Interval) StartDuration() time.Duration

type ProbeContainer

type ProbeContainer struct {
	Streams []ProbeStream `json:"streams"`
	Format  ProbeFormat   `json:"format"`
}

func Probe

func Probe(fileLocator filesystem.FileLocator) (*ProbeContainer, error)

Probe analyzes the given file, attempting to parse the container's metadata and discover the number and types of streams contained within. Metadata from probed files is cached in a global probeCache, with access restricted by the probeMutex.

type ProbeData

type ProbeData struct {
	Format *ProbeFormat `json:"format,omitempty"`
}

type ProbeFormat

type ProbeFormat 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"`
	StartTimeSeconds float64           `json:"start_time,string"`
	DurationSeconds  float64           `json:"duration,string"`
	Size             uint64            `json:"size,string"`
	BitRate          uint64            `json:"bit_rate,string"`
	ProbeScore       float64           `json:"probe_score"`
	Tags             map[string]string `json:"tags"`
}

func (ProbeFormat) StartTime

func (f ProbeFormat) StartTime() time.Duration

type ProbeStream

type ProbeStream struct {
	Index         int               `json:"index"`
	CodecName     string            `json:"codec_name"`
	CodecLongName string            `json:"codec_long_name"`
	CodecTag      string            `json:"codec_tag"`
	Profile       string            `json:"profile"`
	Level         int               `json:"level"`
	Channels      int               `json:"channels"`
	ChannelLayout string            `json:"channel_layout"`
	CodecType     string            `json:"codec_type"`
	BitRate       string            `json:"bit_rate"`
	Width         int               `json:"width"`
	Height        int               `json:"height"`
	Extradata     string            `json:"extradata"`
	Tags          map[string]string `json:"tags"`
	Disposition   map[string]int    `json:"disposition"`
	TimeBase      string            `json:"time_base"`
	DurationTs    int               `json:"duration_ts"`
	RFrameRate    string            `json:"r_frame_rate"`
}

func FilterProbeStreamByCodecType

func FilterProbeStreamByCodecType(streams []ProbeStream, codecType string) []ProbeStream

func (*ProbeStream) GetMime

func (self *ProbeStream) GetMime() string

func (*ProbeStream) String

func (ps *ProbeStream) String() string

type Representation

type Representation struct {
	RepresentationId string

	// The rest is just metadata for display
	BitRate int
	Height  int
	Width   int
	// e.g. "video/mp4"
	Container string
	// codecs string ready for DASH/HLS serving
	Codecs string

	// Mutually exclusive
	Transcoded bool
	Transmuxed bool
	// contains filtered or unexported fields
}

type Segment

type Segment struct {
	Interval
	SegmentId int
}

func BuildConstantSegmentDurations

func BuildConstantSegmentDurations(interval Interval, segmentDuration time.Duration, startSegmentIndex int) []Segment

type Stream

type Stream struct {
	StreamKey

	TotalDuration time.Duration

	TimeBase         *big.Rat
	TotalDurationDts DtsTimestamp
	// codecs string ready for DASH/HLS serving
	Codecs    string
	CodecName string
	Profile   string
	BitRate   int64
	FrameRate *big.Rat

	Width  int
	Height int

	// "audio", "video", "subtitle"
	StreamType string
	// Only relevant for audio and subtitles. Language code.
	Language string
	// User-visible string for this audio or subtitle track
	Title            string
	EnabledByDefault bool
}

func GetStream

func GetStream(streamKey StreamKey) (Stream, error)

type StreamKey

type StreamKey struct {
	FileLocator filesystem.FileLocator
	// StreamId from ffmpeg
	// StreamId is always 0 for transmuxing
	StreamId int64
}

type StreamRepresentation

type StreamRepresentation struct {
	Stream         Stream
	Representation Representation
}

func GetSimilarTranscodedRepresentation

func GetSimilarTranscodedRepresentation(stream Stream) StreamRepresentation

func GetStandardPresetVideoRepresentations

func GetStandardPresetVideoRepresentations(stream Stream) []StreamRepresentation

func GetSubtitleStreamRepresentation

func GetSubtitleStreamRepresentation(stream Stream) StreamRepresentation

func GetSubtitleStreamRepresentations

func GetSubtitleStreamRepresentations(streams []Stream) []StreamRepresentation

func GetTranscodedAudioRepresentation

func GetTranscodedAudioRepresentation(stream Stream, representationId string, encoderParams EncoderParams) StreamRepresentation

func GetTranscodedVideoRepresentation

func GetTranscodedVideoRepresentation(
	stream Stream,
	representationId string,
	encoderParams EncoderParams) StreamRepresentation

func GetTransmuxedOrTranscodedRepresentation

func GetTransmuxedOrTranscodedRepresentation(
	stream Stream,
	capabilities ClientCodecCapabilities) (StreamRepresentation, error)

func GetTransmuxedRepresentation

func GetTransmuxedRepresentation(stream Stream) StreamRepresentation

func StreamRepresentationFromRepresentationId

func StreamRepresentationFromRepresentationId(
	s Stream,
	representationId string) (StreamRepresentation, error)

TODO(Leon Handreke): Should this really return an error?

type Streams

type Streams struct {
	VideoStreams    []Stream
	AudioStreams    []Stream
	SubtitleStreams []Stream
}

func GetStreams

func GetStreams(fileLocator filesystem.FileLocator) (*Streams, error)

func (*Streams) GetVideoStream

func (s *Streams) GetVideoStream() Stream

type TranscodingSession

type TranscodingSession struct {
	Stream          StreamRepresentation
	OutputDir       string
	Terminated      bool
	Throttled       bool
	ProgressPercent float32
	// contains filtered or unexported fields
}

TranscodingSession contains many attributes which are only public because they are displayed on the debug page.

func NewAudioTranscodingSession

func NewAudioTranscodingSession(
	stream StreamRepresentation,
	startTime time.Duration,
	segmentStartIndex int,
	outputDirBase string,
	feedbackURL string) (*TranscodingSession, error)

func NewSubtitleSession

func NewSubtitleSession(
	stream StreamRepresentation,
	outputDirBase string) (*TranscodingSession, error)

func NewTranscodingSession

func NewTranscodingSession(s StreamRepresentation, segmentStartIndex int, feedbackURL string) (*TranscodingSession, error)

func NewTransmuxingSession

func NewTransmuxingSession(
	stream StreamRepresentation,
	startTime time.Duration,
	segmentStartIndex int,
	outputDirBase string,
	feedbackURL string) (*TranscodingSession, error)

NewTransmuxingSession starts a new transmuxing-only (aka "Direct Stream") session.

func NewVideoTranscodingSession

func NewVideoTranscodingSession(
	stream StreamRepresentation,
	startTime time.Duration,
	segmentStartIndex int,
	outputDirBase string,
	feedbackURL string) (*TranscodingSession, error)

func (*TranscodingSession) AvailableSegments

func (s *TranscodingSession) AvailableSegments() (map[int]string, error)

func (*TranscodingSession) Destroy

func (s *TranscodingSession) Destroy() error

func (*TranscodingSession) Start

func (s *TranscodingSession) Start() error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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