ffmpeg

package
v0.0.0-...-ced71c4 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: MIT Imports: 21 Imported by: 7

Documentation

Index

Constants

View Source
const (
	PixelFormatNone        int = C.AV_PIX_FMT_NONE
	PixelFormatYUV420P     int = C.AV_PIX_FMT_YUV420P
	PixelFormatYUYV422     int = C.AV_PIX_FMT_YUYV422
	PixelFormatYUV422P     int = C.AV_PIX_FMT_YUV422P
	PixelFormatYUV444P     int = C.AV_PIX_FMT_YUV444P
	PixelFormatUYVY422     int = C.AV_PIX_FMT_UYVY422
	PixelFormatNV12        int = C.AV_PIX_FMT_NV12
	PixelFormatNV21        int = C.AV_PIX_FMT_NV21
	PixelFormatYUV420P10BE int = C.AV_PIX_FMT_YUV420P10BE
	PixelFormatYUV420P10LE int = C.AV_PIX_FMT_YUV420P10LE
	PixelFormatYUV422P10BE int = C.AV_PIX_FMT_YUV422P10BE
	PixelFormatYUV422P10LE int = C.AV_PIX_FMT_YUV422P10LE
	PixelFormatYUV444P10BE int = C.AV_PIX_FMT_YUV444P10BE
	PixelFormatYUV444P10LE int = C.AV_PIX_FMT_YUV444P10LE
	PixelFormatYUV420P16LE int = C.AV_PIX_FMT_YUV420P16LE
	PixelFormatYUV420P16BE int = C.AV_PIX_FMT_YUV420P16BE
	PixelFormatYUV422P16LE int = C.AV_PIX_FMT_YUV422P16LE
	PixelFormatYUV422P16BE int = C.AV_PIX_FMT_YUV422P16BE
	PixelFormatYUV444P16LE int = C.AV_PIX_FMT_YUV444P16LE
	PixelFormatYUV444P16BE int = C.AV_PIX_FMT_YUV444P16BE
	PixelFormatYUV420P12BE int = C.AV_PIX_FMT_YUV420P12BE
	PixelFormatYUV420P12LE int = C.AV_PIX_FMT_YUV420P12LE
	PixelFormatYUV422P12BE int = C.AV_PIX_FMT_YUV422P12BE
	PixelFormatYUV422P12LE int = C.AV_PIX_FMT_YUV422P12LE
	PixelFormatYUV444P12BE int = C.AV_PIX_FMT_YUV444P12BE
	PixelFormatYUV444P12LE int = C.AV_PIX_FMT_YUV444P12LE
)
View Source
const (
	FFLogTrace   = C.LPMS_LOG_TRACE
	FFLogDebug   = C.LPMS_LOG_DEBUG
	FFLogVerbose = C.LPMS_LOG_VERBOSE
	FFLogInfo    = C.LPMS_LOG_INFO
	FFLogWarning = C.LPMS_LOG_WARNING
	FFLogError   = C.LPMS_LOG_ERROR
	FFLogFatal   = C.LPMS_LOG_FATAL
	FFLogPanic   = C.LPMS_LOG_PANIC
	FFLogQuiet   = C.LPMS_LOG_QUIET
)
View Source
const (
	GOPIntraOnly time.Duration = -1

	// Must always be last. Renumber as needed.
	GOPInvalid = -2
)

For additional "special" GOP values enumerate backwards from here

Variables

View Source
var (
	P720p60fps16x9 = VideoProfile{Name: "P720p60fps16x9", Bitrate: "6000k", Framerate: 60, AspectRatio: "16:9", Resolution: "1280x720"}
	P720p30fps16x9 = VideoProfile{Name: "P720p30fps16x9", Bitrate: "4000k", Framerate: 30, AspectRatio: "16:9", Resolution: "1280x720"}
	P720p25fps16x9 = VideoProfile{Name: "P720p25fps16x9", Bitrate: "3500k", Framerate: 25, AspectRatio: "16:9", Resolution: "1280x720"}
	P720p30fps4x3  = VideoProfile{Name: "P720p30fps4x3", Bitrate: "3500k", Framerate: 30, AspectRatio: "4:3", Resolution: "960x720"}
	P576p30fps16x9 = VideoProfile{Name: "P576p30fps16x9", Bitrate: "1500k", Framerate: 30, AspectRatio: "16:9", Resolution: "1024x576"}
	P576p25fps16x9 = VideoProfile{Name: "P576p25fps16x9", Bitrate: "1500k", Framerate: 25, AspectRatio: "16:9", Resolution: "1024x576"}
	P360p30fps16x9 = VideoProfile{Name: "P360p30fps16x9", Bitrate: "1200k", Framerate: 30, AspectRatio: "16:9", Resolution: "640x360"}
	P360p25fps16x9 = VideoProfile{Name: "P360p25fps16x9", Bitrate: "1000k", Framerate: 25, AspectRatio: "16:9", Resolution: "640x360"}
	P360p30fps4x3  = VideoProfile{Name: "P360p30fps4x3", Bitrate: "1000k", Framerate: 30, AspectRatio: "4:3", Resolution: "480x360"}
	P240p30fps16x9 = VideoProfile{Name: "P240p30fps16x9", Bitrate: "600k", Framerate: 30, AspectRatio: "16:9", Resolution: "426x240"}
	P240p25fps16x9 = VideoProfile{Name: "P240p25fps16x9", Bitrate: "600k", Framerate: 25, AspectRatio: "16:9", Resolution: "426x240"}
	P240p30fps4x3  = VideoProfile{Name: "P240p30fps4x3", Bitrate: "600k", Framerate: 30, AspectRatio: "4:3", Resolution: "320x240"}
	P144p30fps16x9 = VideoProfile{Name: "P144p30fps16x9", Bitrate: "400k", Framerate: 30, AspectRatio: "16:9", Resolution: "256x144"}
	P144p25fps16x9 = VideoProfile{Name: "P144p25fps16x9", Bitrate: "400k", Framerate: 25, AspectRatio: "16:9", Resolution: "256x144"}
)

Some sample video profiles

View Source
var AccelerationNameLookup = map[Acceleration]string{
	Software: "SW",
	Nvidia:   "Nvidia",
	Amd:      "Amd",
	Netint:   "Netint",
}
View Source
var EncoderProfileLookup = map[string]Profile{
	"":                    ProfileNone,
	"none":                ProfileNone,
	"h264baseline":        ProfileH264Baseline,
	"h264main":            ProfileH264Main,
	"h264high":            ProfileH264High,
	"h264constrainedhigh": ProfileH264ConstrainedHigh,
}
View Source
var ErrCodecName = fmt.Errorf("unknown codec name")
View Source
var ErrEmptyData = errors.New("EmptyData")
View Source
var ErrProfName = fmt.Errorf("unknown VideoProfile profile name")
View Source
var ErrSignCompare = errors.New("InvalidSignData")
View Source
var ErrTranscoderClipConfig = errors.New("TranscoderInvalidClipConfig")
View Source
var ErrTranscoderDev = errors.New("TranscoderIncompatibleDevices")
View Source
var ErrTranscoderFmt = errors.New("TranscoderUnrecognizedFormat")
View Source
var ErrTranscoderGOP = errors.New("TranscoderInvalidGOP")
View Source
var ErrTranscoderHw = errors.New("TranscoderInvalidHardware")
View Source
var ErrTranscoderInp = errors.New("TranscoderInvalidInput")
View Source
var ErrTranscoderPixelformat = errors.New("TranscoderInvalidPixelformat")
View Source
var ErrTranscoderPrf = errors.New("TranscoderUnrecognizedProfile")
View Source
var ErrTranscoderRes = errors.New("TranscoderInvalidResolution")
View Source
var ErrTranscoderStp = errors.New("TranscoderStopped")
View Source
var ErrTranscoderVid = errors.New("TranscoderInvalidVideo")
View Source
var ErrVideoCompare = errors.New("InvalidVideoData")
View Source
var ErrorMap = error_map()
View Source
var ExtensionFormats = map[string]Format{
	".ts":  FormatMPEGTS,
	".mp4": FormatMP4,
}
View Source
var FfEncoderLookup = map[Acceleration]map[VideoCodec]string{
	Software: {
		H264: "libx264",
		H265: "libx265",
		VP8:  "libvpx",
		VP9:  "libvpx-vp9",
	},
	Nvidia: {
		H264: "h264_nvenc",
		H265: "hevc_nvenc",
	},
	Netint: {
		H264: "h264_ni_enc",
		H265: "h265_ni_enc",
	},
}
View Source
var FfmpegNameToVideoCodec = map[string]VideoCodec{
	"h264": H264,
	"hevc": H265,
	"vp8":  VP8,
	"vp9":  VP9,
}
View Source
var FormatExtensions = map[Format]string{
	FormatNone:   ".ts",
	FormatMPEGTS: ".ts",
	FormatMP4:    ".mp4",
}
View Source
var LogTranscodeErrors = true

Switch to turn off logging transcoding errors, when doing test transcoding

View Source
var NonRetryableErrs = non_retryable_errs()
View Source
var ProfileParameters = map[Profile]string{
	ProfileNone:                "",
	ProfileH264Baseline:        "baseline",
	ProfileH264Main:            "main",
	ProfileH264High:            "high",
	ProfileH264ConstrainedHigh: "high",
}
View Source
var VideoCodecName = map[VideoCodec]string{
	H264: "H.264",
	H265: "HEVC",
	VP8:  "VP8",
	VP9:  "VP9",
}
View Source
var VideoProfileLookup = map[string]VideoProfile{
	"P720p60fps16x9": P720p60fps16x9,
	"P720p30fps16x9": P720p30fps16x9,
	"P720p25fps16x9": P720p25fps16x9,
	"P720p30fps4x3":  P720p30fps4x3,
	"P576p30fps16x9": P576p30fps16x9,
	"P576p25fps16x9": P576p25fps16x9,
	"P360p30fps16x9": P360p30fps16x9,
	"P360p25fps16x9": P360p25fps16x9,
	"P360p30fps4x3":  P360p30fps4x3,
	"P240p30fps16x9": P240p30fps16x9,
	"P240p25fps16x9": P240p25fps16x9,
	"P240p30fps4x3":  P240p30fps4x3,
	"P144p30fps16x9": P144p30fps16x9,
}

Functions

func CompareSignatureByBuffer

func CompareSignatureByBuffer(data1 []byte, data2 []byte) (bool, error)

compare two signature buffers whether those matches or not

func CompareSignatureByPath

func CompareSignatureByPath(fname1 string, fname2 string) (bool, error)

compare two signature files whether those matches or not

func CompareVideoByBuffer

func CompareVideoByBuffer(data1 []byte, data2 []byte) (bool, error)

compare two video buffers whether those matches or not

func CompareVideoByPath

func CompareVideoByPath(fname1 string, fname2 string) (bool, error)

compare two vidoe files whether those matches or not

func DefaultProfileName

func DefaultProfileName(width int, height int, bitrate int) string

func FfmpegGetLogLevel

func FfmpegGetLogLevel() int

func FfmpegSetLogLevel

func FfmpegSetLogLevel(level int)

func GetCodecInfo

func GetCodecInfo(fname string) (CodecStatus, MediaFormatInfo, error)

func GetCodecInfoBytes

func GetCodecInfoBytes(data []byte) (CodecStatus, MediaFormatInfo, error)

GetCodecInfo opens the segment and attempts to get video and audio codec names. Additionally, first return value indicates whether the segment has zero video frames

func HasZeroVideoFrameBytes

func HasZeroVideoFrameBytes(data []byte) (bool, error)

HasZeroVideoFrameBytes opens video and returns true if it has video stream with 0-frame

func InitFFmpeg

func InitFFmpeg()

func InitFFmpegWithLogLevel

func InitFFmpegWithLogLevel(level LogLevel)

func RTMPToHLS

func RTMPToHLS(localRTMPUrl string, outM3U8 string, tmpl string, seglen_secs string, seg_start int) error

func Strerror

func Strerror(errnum int) string

Strerror returns a descriptive string of the given return code.

C-Function: av_strerror

func Transcode

func Transcode(input string, workDir string, ps []VideoProfile) error

func Transcode2

func Transcode2(input *TranscodeOptionsIn, ps []TranscodeOptions) error

func VideoProfileResolution

func VideoProfileResolution(p VideoProfile) (int, int, error)

func VideoProfileToVariantParams

func VideoProfileToVariantParams(p VideoProfile) m3u8.VariantParams

Types

type Acceleration

type Acceleration int
const (
	Software Acceleration = iota
	Nvidia
	Amd
	Netint
)

type ByName

type ByName []VideoProfile

func (ByName) Len

func (a ByName) Len() int

func (ByName) Less

func (a ByName) Less(i, j int) bool

func (ByName) Swap

func (a ByName) Swap(i, j int)

type ChromaSubsampling

type ChromaSubsampling int
const (
	ChromaSubsampling420 ChromaSubsampling = iota
	ChromaSubsampling422
	ChromaSubsampling444
)

type CodecStatus

type CodecStatus int
const (
	CodecStatusInternalError CodecStatus = -1
	CodecStatusOk            CodecStatus = 0
	CodecStatusNeedsBypass   CodecStatus = 1
	CodecStatusMissing       CodecStatus = 2
)

type CodingSizeLimit

type CodingSizeLimit struct {
	WidthMin, HeightMin int
	WidthMax, HeightMax int
}

func (*CodingSizeLimit) Clamp

func (l *CodingSizeLimit) Clamp(p *VideoProfile, format MediaFormatInfo) error

type ColorDepthBits

type ColorDepthBits int

hold bit number minus 8; ColorDepthBits + 8 == bit number

const (
	ColorDepth8Bit  ColorDepthBits = 0
	ColorDepth10Bit ColorDepthBits = 2
	ColorDepth12Bit ColorDepthBits = 4
	ColorDepth16Bit ColorDepthBits = 8
)

type ComponentOptions

type ComponentOptions struct {
	Name string
	Opts map[string]string
}

type Format

type Format int
const (
	FormatNone Format = iota
	FormatMPEGTS
	FormatMP4
)

type JsonProfile

type JsonProfile struct {
	Name         string            `json:"name"`
	Width        int               `json:"width"`
	Height       int               `json:"height"`
	Bitrate      int               `json:"bitrate"`
	FPS          uint              `json:"fps"`
	FPSDen       uint              `json:"fpsDen"`
	Profile      string            `json:"profile"`
	GOP          string            `json:"gop"`
	Encoder      string            `json:"encoder"`
	ColorDepth   ColorDepthBits    `json:"colorDepth"`
	ChromaFormat ChromaSubsampling `json:"chromaFormat"`
	Quality      uint              `json:"quality"`
}

type LogLevel

type LogLevel C.enum_LPMSLogLevel

type MediaFormatInfo

type MediaFormatInfo struct {
	Acodec, Vcodec string
	PixFormat      PixelFormat
	Width, Height  int
}

func (*MediaFormatInfo) ScaledHeight

func (f *MediaFormatInfo) ScaledHeight(width int) int

func (*MediaFormatInfo) ScaledWidth

func (f *MediaFormatInfo) ScaledWidth(height int) int

type MediaInfo

type MediaInfo struct {
	Frames int
	Pixels int64
}

type PixelFormat

type PixelFormat struct {
	RawValue int
}

func (PixelFormat) Properties

func (pixelFormat PixelFormat) Properties() (ChromaSubsampling, ColorDepthBits, error)

type Profile

type Profile int
const (
	ProfileNone Profile = iota
	ProfileH264Baseline
	ProfileH264Main
	ProfileH264High
	ProfileH264ConstrainedHigh
)

func EncoderProfileNameToValue

func EncoderProfileNameToValue(profile string) (Profile, error)

type Size

type Size struct {
	W, H int
}

func (*Size) Valid

func (s *Size) Valid(l *CodingSizeLimit) bool

type TranscodeOptions

type TranscodeOptions struct {
	Oname    string
	Profile  VideoProfile
	Accel    Acceleration
	Device   string
	CalcSign bool
	From     time.Duration
	To       time.Duration

	Muxer        ComponentOptions
	VideoEncoder ComponentOptions
	AudioEncoder ComponentOptions
}

type TranscodeOptionsIn

type TranscodeOptionsIn struct {
	Fname       string
	Accel       Acceleration
	Device      string
	Transmuxing bool
}

type TranscodeResults

type TranscodeResults struct {
	Decoded MediaInfo
	Encoded []MediaInfo
}

func Transcode3

func Transcode3(input *TranscodeOptionsIn, ps []TranscodeOptions) (*TranscodeResults, error)

type Transcoder

type Transcoder struct {
	// contains filtered or unexported fields
}

func NewTranscoder

func NewTranscoder() *Transcoder

func (*Transcoder) Discontinuity

func (t *Transcoder) Discontinuity()

func (*Transcoder) StopTranscoder

func (t *Transcoder) StopTranscoder()

func (*Transcoder) Transcode

func (t *Transcoder) Transcode(input *TranscodeOptionsIn, ps []TranscodeOptions) (*TranscodeResults, error)

type VideoCodec

type VideoCodec int
const (
	H264 VideoCodec = iota
	H265
	VP8
	VP9
)

func CodecNameToValue

func CodecNameToValue(encoder string) (VideoCodec, error)

type VideoProfile

type VideoProfile struct {
	Name string
	// Bitrate is used to set min, avg, and max bitrate
	Bitrate      string
	Framerate    uint
	FramerateDen uint
	Resolution   string
	AspectRatio  string
	Format       Format
	Profile      Profile
	GOP          time.Duration
	Encoder      VideoCodec
	ColorDepth   ColorDepthBits
	ChromaFormat ChromaSubsampling
	// Quality is used to set CRF and CQ
	// If set, then constant rate factor is used instead of constant bitrate
	// If both Quality and Bitrate are set, then Bitrate is used only as max bitrate
	Quality uint
}

Standard Profiles: 1080p60fps: 9000kbps 1080p30fps: 6000kbps 720p60fps: 6000kbps 720p30fps: 4000kbps 480p30fps: 2000kbps 360p30fps: 1000kbps 240p30fps: 700kbps 144p30fps: 400kbps

func ParseProfiles

func ParseProfiles(injson []byte) ([]VideoProfile, error)

func ParseProfilesFromJsonProfileArray

func ParseProfilesFromJsonProfileArray(profiles []JsonProfile) ([]VideoProfile, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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