ffmpeg

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2020 License: AGPL-3.0 Imports: 22 Imported by: 1

Documentation

Index

Constants

View Source
const (
	Mp4                Container  = "mp4"
	M4v                Container  = "m4v"
	Mov                Container  = "mov"
	Wmv                Container  = "wmv"
	Webm               Container  = "webm"
	Matroska           Container  = "matroska"
	Avi                Container  = "avi"
	Flv                Container  = "flv"
	Mpegts             Container  = "mpegts"
	Aac                AudioCodec = "aac"
	Mp3                AudioCodec = "mp3"
	Opus               AudioCodec = "opus"
	Vorbis             AudioCodec = "vorbis"
	MissingUnsupported AudioCodec = ""
	Mp4Ffmpeg          string     = "mov,mp4,m4a,3gp,3g2,mj2" // browsers support all of them
	M4vFfmpeg          string     = "mov,mp4,m4a,3gp,3g2,mj2" // so we don't care that ffmpeg
	MovFfmpeg          string     = "mov,mp4,m4a,3gp,3g2,mj2" // can't differentiate between them
	WmvFfmpeg          string     = "asf"
	WebmFfmpeg         string     = "matroska,webm"
	MatroskaFfmpeg     string     = "matroska,webm"
	AviFfmpeg          string     = "avi"
	FlvFfmpeg          string     = "flv"
	MpegtsFfmpeg       string     = "mpegts"
	H264               string     = "h264"
	H265               string     = "h265" // found in rare cases from a faulty encoder
	Hevc               string     = "hevc"
	Vp8                string     = "vp8"
	Vp9                string     = "vp9"
	MimeWebm           string     = "video/webm"
	MimeMkv            string     = "video/x-matroska"
)

Variables

maps user readable container strings to ffprobe's format_name on some formats ffprobe can't differentiate

View Source
var FrameRegex = regexp.MustCompile(`frame=\s*([0-9]+)`)
View Source
var TimeRegex = regexp.MustCompile(`time=\s*(\d+):(\d+):(\d+.\d+)`)
View Source
var ValidCodecs = []string{H264, H265, Vp8, Vp9}

Functions

func Download

func Download(configDirectory string) error

func GetFrameFromRegex

func GetFrameFromRegex(str string) int

func GetPaths

func GetPaths(configDirectory string) (string, string)

func GetTimeFromRegex

func GetTimeFromRegex(str string) float64

func IsValidAudio added in v0.2.0

func IsValidAudio(audio AudioCodec, ValidCodecs []AudioCodec) bool

func IsValidAudioForContainer added in v0.2.0

func IsValidAudioForContainer(audio AudioCodec, format Container) bool

func IsValidCodec

func IsValidCodec(codecName string) bool

func IsValidCombo added in v0.2.0

func IsValidCombo(codecName string, format Container) bool

extend stream validation check to take into account container

func IsValidForContainer added in v0.2.0

func IsValidForContainer(format Container, validContainers []Container) bool

func KillRunningEncoders

func KillRunningEncoders(path string)

Types

type AudioCodec added in v0.2.0

type AudioCodec string

type Container added in v0.2.0

type Container string

func MagicContainer added in v0.2.0

func MagicContainer(file_path string) Container

returns container as string ("" on error or no match) implements only mkv or webm as ffprobe can't distinguish between them and not all browsers support mkv

func MatchContainer added in v0.2.0

func MatchContainer(format string, filePath string) Container

type Encoder

type Encoder struct {
	Path string
}

func NewEncoder

func NewEncoder(ffmpegPath string) Encoder

func (*Encoder) CopyVideo added in v0.2.0

func (e *Encoder) CopyVideo(probeResult VideoFile, options TranscodeOptions)

copy the video stream as is, drop audio

func (*Encoder) SceneMarkerImage

func (e *Encoder) SceneMarkerImage(probeResult VideoFile, options SceneMarkerOptions) error

func (*Encoder) SceneMarkerVideo

func (e *Encoder) SceneMarkerVideo(probeResult VideoFile, options SceneMarkerOptions) error

func (*Encoder) ScenePreviewVideoChunk

func (e *Encoder) ScenePreviewVideoChunk(probeResult VideoFile, options ScenePreviewChunkOptions, preset string)

func (*Encoder) ScenePreviewVideoChunkCombine

func (e *Encoder) ScenePreviewVideoChunkCombine(probeResult VideoFile, concatFilePath string, outputPath string)

func (*Encoder) ScenePreviewVideoToImage

func (e *Encoder) ScenePreviewVideoToImage(probeResult VideoFile, width int, videoPreviewPath string, outputPath string) error

func (*Encoder) Screenshot

func (e *Encoder) Screenshot(probeResult VideoFile, options ScreenshotOptions) error

func (*Encoder) StreamMkvTranscodeAudio added in v0.2.0

func (e *Encoder) StreamMkvTranscodeAudio(probeResult VideoFile, startTime string, maxTranscodeSize models.StreamingResolutionEnum) (io.ReadCloser, *os.Process, error)

it is very common in MKVs to have just the audio codec unsupported copy the video stream, transcode the audio and serve as Matroska

func (*Encoder) StreamTranscode

func (e *Encoder) StreamTranscode(probeResult VideoFile, startTime string, maxTranscodeSize models.StreamingResolutionEnum) (io.ReadCloser, *os.Process, error)

func (*Encoder) StreamTranscodeVideo added in v0.2.0

func (e *Encoder) StreamTranscodeVideo(probeResult VideoFile, startTime string, maxTranscodeSize models.StreamingResolutionEnum) (io.ReadCloser, *os.Process, error)

transcode the video, remove the audio in some videos where the audio codec is not supported by ffmpeg ffmpeg fails if you try to transcode the audio

func (*Encoder) Transcode

func (e *Encoder) Transcode(probeResult VideoFile, options TranscodeOptions)

func (*Encoder) TranscodeAudio added in v0.2.0

func (e *Encoder) TranscodeAudio(probeResult VideoFile, options TranscodeOptions)

copy the video stream as is, transcode audio

func (*Encoder) TranscodeVideo added in v0.2.0

func (e *Encoder) TranscodeVideo(probeResult VideoFile, options TranscodeOptions)

transcode the video, remove the audio in some videos where the audio codec is not supported by ffmpeg ffmpeg fails if you try to transcode the audio

type FFProbeJSON

type FFProbeJSON struct {
	Format struct {
		BitRate        string `json:"bit_rate"`
		Duration       string `json:"duration"`
		Filename       string `json:"filename"`
		FormatLongName string `json:"format_long_name"`
		FormatName     string `json:"format_name"`
		NbPrograms     int    `json:"nb_programs"`
		NbStreams      int    `json:"nb_streams"`
		ProbeScore     int    `json:"probe_score"`
		Size           string `json:"size"`
		StartTime      string `json:"start_time"`
		Tags           struct {
			CompatibleBrands string          `json:"compatible_brands"`
			CreationTime     models.JSONTime `json:"creation_time"`
			Encoder          string          `json:"encoder"`
			MajorBrand       string          `json:"major_brand"`
			MinorVersion     string          `json:"minor_version"`
			Title            string          `json:"title"`
			Comment          string          `json:"comment"`
		} `json:"tags"`
	} `json:"format"`
	Streams []FFProbeStream `json:"streams"`
	Error   struct {
		Code   int    `json:"code"`
		String string `json:"string"`
	} `json:"error"`
}

type FFProbeStream

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

type SceneMarkerOptions

type SceneMarkerOptions struct {
	ScenePath  string
	Seconds    int
	Width      int
	OutputPath string
}

type ScenePreviewChunkOptions

type ScenePreviewChunkOptions struct {
	Time       int
	Width      int
	OutputPath string
}

type ScreenshotOptions

type ScreenshotOptions struct {
	OutputPath string
	Quality    int
	Time       float64
	Width      int
	Verbosity  string
}

type TranscodeOptions

type TranscodeOptions struct {
	OutputPath       string
	MaxTranscodeSize models.StreamingResolutionEnum
}

type VideoFile

type VideoFile struct {
	JSON        FFProbeJSON
	AudioStream *FFProbeStream
	VideoStream *FFProbeStream

	Path         string
	Title        string
	Comment      string
	Container    string
	Duration     float64
	StartTime    float64
	Bitrate      int64
	Size         int64
	CreationTime time.Time

	VideoCodec   string
	VideoBitrate int64
	Width        int
	Height       int
	FrameRate    float64
	Rotation     int64

	AudioCodec string
}

func NewVideoFile

func NewVideoFile(ffprobePath string, videoPath string) (*VideoFile, error)

Execute exec command and bind result to struct.

func (*VideoFile) GetAudioStream

func (v *VideoFile) GetAudioStream() *FFProbeStream

func (*VideoFile) GetVideoStream

func (v *VideoFile) GetVideoStream() *FFProbeStream

func (*VideoFile) SetTitleFromPath

func (v *VideoFile) SetTitleFromPath()

Jump to

Keyboard shortcuts

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