Documentation
¶
Overview ¶
Package goavpipe contains the parts of the avpipe library that may be used by other go packages without relying on the actual libavpipe that does the transcoding. In particular, packages that process the transcode parameters may rely on this to avoid needing a more complex toolchain.
Index ¶
- Constants
- Variables
- func AllLogMapsEmpty() bool
- func AssociateGIDWithHandle(handle int32)
- func DeleteMuxOutputHandler(fd int64)
- func DissociateGIDFromHandle()
- func GIDHandle() (int32, bool)
- func InitIOHandler(inputOpener InputOpener, outputOpener OutputOpener)
- func InitMuxIOHandler(inputOpener InputOpener, muxOutputOpener MuxOutputOpener)
- func InitUrlIOHandler(url string, inputOpener InputOpener, outputOpener OutputOpener)
- func InitUrlIOHandlerIfNotPresent(url string, inputOpener InputOpener, outputOpener OutputOpener) (inSet bool, outSet bool)
- func InitUrlMuxIOHandler(url string, inputOpener InputOpener, muxOutputOpener MuxOutputOpener)
- func Mux(params *XcParams) error
- func PutMuxOutputOpener(fd int64, muxOutputHandler OutputHandler)
- func RegisterWarnErrChanForHandle(handle *int32, errChan chan string)
- func RemoveUrlMuxIOHandler(url string)
- func SetMuxFn(fn muxFnT) muxFnT
- func SetXcCancelFn(fn xcCancelFnT) xcCancelFnT
- func SetXcFn(fn xcFnT) xcFnT
- func SetXcInitFn(fn xcInitFnT) xcInitFnT
- func SetXcRunFn(fn xcRunFnT) xcRunFnT
- func XCEnded()
- func Xc(params *XcParams) error
- func XcCancel(handle int32) error
- func XcInit(params *XcParams) (int32, error)
- func XcRun(handle int32) error
- type AVClass
- type AVFieldOrder
- type AVMediaType
- type AVStatType
- type AVType
- type CryptScheme
- type GlobalsT
- func (g *GlobalsT) AssignOutputOpener(opener OutputOpener) (fd int64)
- func (g *GlobalsT) DeleteCIOHandlerAndOutputOpeners(fd int64)
- func (g *GlobalsT) GetCIOHandler(fd int64) (any, bool)
- func (g *GlobalsT) GetMuxOutputHandler(fd int64) OutputHandler
- func (g *GlobalsT) GetNextFD() int64
- func (g *GlobalsT) PutCIOHandler(fd int64, h any)
- func (g *GlobalsT) RemoveURLHandlers(url string)
- type ImageType
- type InputHandler
- type InputOpener
- type MuxOutputOpener
- type OutputHandler
- type OutputOpener
- type XcParams
- type XcProfile
- type XcType
Constants ¶
const ( AV_IN_STAT_BYTES_READ = 1 AV_IN_STAT_AUDIO_FRAME_READ = 2 AV_IN_STAT_VIDEO_FRAME_READ = 3 AV_IN_STAT_DECODING_AUDIO_START_PTS = 4 AV_IN_STAT_DECODING_VIDEO_START_PTS = 5 AV_OUT_STAT_BYTES_WRITTEN = 6 AV_OUT_STAT_FRAME_WRITTEN = 7 AV_IN_STAT_FIRST_KEYFRAME_PTS = 8 AV_OUT_STAT_ENCODING_END_PTS = 9 AV_OUT_STAT_START_FILE = 10 AV_OUT_STAT_END_FILE = 11 AV_IN_STAT_DATA_SCTE35 = 12 )
const ( XcProfileNone XcProfile = iota XcProfileH264BaseLine = 66 // C.AV_PROFILE_H264_BASELINE XcProfileH264Heigh = 100 // C.AV_PROFILE_H264_HIGH XcProfileH264Heigh10 = 110 // C.AV_PROFILE_H264_HIGH_10 )
const ( UnknownImage = iota PngImage JpgImage GifImage )
const ( AVMEDIA_TYPE_UNKNOWN = -1 AVMEDIA_TYPE_VIDEO = 0 AVMEDIA_TYPE_AUDIO = 1 AVMEDIA_TYPE_DATA = 2 ///< Opaque data information usually continuous AVMEDIA_TYPE_SUBTITLE = 3 AVMEDIA_TYPE_ATTACHMENT = 4 ///< Opaque data information usually sparse AVMEDIA_TYPE_NB = 5 )
const ( AV_FIELD_UNKNOWN = 0 AV_FIELD_PROGRESSIVE = 1 AV_FIELD_TT = 2 //< Top coded_first, top displayed first AV_FIELD_BB = 3 //< Bottom coded first, bottom displayed first AV_FIELD_TB = 4 //< Top coded first, bottom displayed first AV_FIELD_BT = 5 //< Bottom coded first, top displayed first )
const AvNoPtsValue = uint64(0x8000000000000000)
This is corresponding to AV_NOPTS_VALUE
Variables ¶
var AVClassE = struct { Mez AVClass Abr AVClass Manifest AVClass Mux AVClass Frame AVClass Unknown AVClass }{ Mez: "mez", Abr: "abr", Manifest: "manifest", Mux: "mux", Frame: "frame", Unknown: "unknown", }
var AVFieldOrderNames = map[AVFieldOrder]string{ AV_FIELD_UNKNOWN: "", AV_FIELD_PROGRESSIVE: "progressive", AV_FIELD_TT: "tt", AV_FIELD_BB: "bb", AV_FIELD_TB: "tb", AV_FIELD_BT: "bt", }
var AVMediaTypeNames = map[AVMediaType]string{ AVMEDIA_TYPE_UNKNOWN: "unknown", AVMEDIA_TYPE_VIDEO: "video", AVMEDIA_TYPE_AUDIO: "audio", AVMEDIA_TYPE_DATA: "data", AVMEDIA_TYPE_SUBTITLE: "subtitle", AVMEDIA_TYPE_ATTACHMENT: "attachment", AVMEDIA_TYPE_NB: "nb", }
var Globals = &GlobalsT{}
var Log = logWrapper{/* contains filtered or unexported fields */}
Functions ¶
func AllLogMapsEmpty ¶ added in v1.23.0
func AllLogMapsEmpty() bool
AllLogMapsEmpty returns true if all log maps are empty It should be used for testing purposes only
func AssociateGIDWithHandle ¶ added in v1.23.0
func AssociateGIDWithHandle(handle int32)
AssociateGIDWithHandle associates the current go-routine ID (GID) with the given handle In case the goroutine had a channel associated with it, it will be associated with the handle
func DeleteMuxOutputHandler ¶ added in v1.26.0
func DeleteMuxOutputHandler(fd int64)
DeleteMuxOutputHandler removes the mux output handler entry for fd. Called from AVPipeCloseMuxOutput.
func DissociateGIDFromHandle ¶ added in v1.24.0
func DissociateGIDFromHandle()
DissociateGIDFromHandle removes the association between the current goroutine ID and its handle
func InitIOHandler ¶ added in v1.23.0
func InitIOHandler(inputOpener InputOpener, outputOpener OutputOpener)
InitIOHandler is used to set global input/output opener for avpipe If there is no specific input/output opener for a URL, the global input/output opener will be used.
func InitMuxIOHandler ¶ added in v1.23.0
func InitMuxIOHandler(inputOpener InputOpener, muxOutputOpener MuxOutputOpener)
InitMuxIOHandler sets the global handlers for muxing (similar to InitIOHandler for transcoding)
func InitUrlIOHandler ¶ added in v1.23.0
func InitUrlIOHandler(url string, inputOpener InputOpener, outputOpener OutputOpener)
InitUrlIOHandler is used to set input/output opener specific to a URL. The input/output opener set by this function, is only valid for the URL and will be unset after Xc() or Probe() is complete.
func InitUrlIOHandlerIfNotPresent ¶ added in v1.23.0
func InitUrlIOHandlerIfNotPresent(url string, inputOpener InputOpener, outputOpener OutputOpener) (inSet bool, outSet bool)
func InitUrlMuxIOHandler ¶ added in v1.23.0
func InitUrlMuxIOHandler(url string, inputOpener InputOpener, muxOutputOpener MuxOutputOpener)
InitUrlMuxIOHandler sets specific IO handler for muxing a url/file (similar to InitUrlIOHandler) To clean up - call RemoveUrlMuxIOHandler.
func PutMuxOutputOpener ¶ added in v1.23.0
func PutMuxOutputOpener(fd int64, muxOutputHandler OutputHandler)
PutMuxOutputOpener registers a mux output handler keyed by fd. To clean up - call DeleteMuxOutputHandler.
func RegisterWarnErrChanForHandle ¶ added in v1.23.0
RegisterWarnErrChanForHandle registers a channel to send error logs to for a given handle. Ownership of the channel is taken by avpipe, and the channel will be closed once the transcode completes. If handle is nil, then channel will be registered with a handle that is created on this goroutine.
func RemoveUrlMuxIOHandler ¶ added in v1.26.0
func RemoveUrlMuxIOHandler(url string)
RemoveUrlMuxIOHandler removes IO handlers used for muxing a url/file
func SetMuxFn ¶ added in v1.22.8
func SetMuxFn(fn muxFnT) muxFnT
SetMuxFn sets the function to be used for muxing, and returns the previous value.
func SetXcCancelFn ¶ added in v1.22.8
func SetXcCancelFn(fn xcCancelFnT) xcCancelFnT
SetXcCancelFn sets the function to be used for canceling transcoding, and returns the previous value.
func SetXcFn ¶ added in v1.22.8
func SetXcFn(fn xcFnT) xcFnT
SetXcFn sets the function to be used for transcoding, and returns the previous value.
func SetXcInitFn ¶ added in v1.22.8
func SetXcInitFn(fn xcInitFnT) xcInitFnT
SetXcInitFn sets the function to be used for initializing transcoding, and returns the previous value.
func SetXcRunFn ¶ added in v1.22.8
func SetXcRunFn(fn xcRunFnT) xcRunFnT
SetXcRunFn sets the function to be used for running transcoding, and returns the previous value.
Types ¶
type AVFieldOrder ¶
type AVFieldOrder int
type AVMediaType ¶
type AVMediaType int
type AVStatType ¶ added in v1.23.0
type AVStatType int
func (AVStatType) Name ¶ added in v1.23.0
func (a AVStatType) Name() string
type AVType ¶
type AVType int
AVType ...
const ( // Unknown 0 Unknown AVType = iota // DASHManifest 1 DASHManifest // DASHVideoInit 2 DASHVideoInit // DASHVideoSegment 3 DASHVideoSegment // DASHAudioInit 4 DASHAudioInit // DASHAudioSegment 5 DASHAudioSegment // HLSMasterM3U 6 HLSMasterM3U // HLSVideoM3U 7 HLSVideoM3U // HLSAudioM3U 8 HLSAudioM3U // AES128Key 9 AES128Key // MP4Stream 10 MP4Stream // FMP4Stream 11 (Fragmented MP4) FMP4Stream // MP4Segment 12 MP4Segment // FMP4VideoSegment 13 FMP4VideoSegment // FMP4AudioSegment 14 FMP4AudioSegment // MuxSegment 15 MuxSegment // FrameImage 16 FrameImage // MpegtsSegment 17 MpegtsSegment )
type CryptScheme ¶
type CryptScheme int
CryptScheme is the content encryption scheme
const ( // CryptNone - clear CryptNone CryptScheme = iota // CryptAES128 - AES-128 CryptAES128 // CryptCENC - CENC AES-CTR CryptCENC // CryptCBC1 - CENC AES-CBC CryptCBC1 // CryptCENS - CENC AES-CTR Pattern CryptCENS // CryptCBCS - CENC AES-CBC Pattern CryptCBCS )
type GlobalsT ¶ added in v1.23.0
type GlobalsT struct{}
GlobalsT wraps the global variables used in avpipe. It should be gradually replaced in the future, but for now is a global singleton.
func (*GlobalsT) AssignOutputOpener ¶ added in v1.23.0
func (g *GlobalsT) AssignOutputOpener(opener OutputOpener) (fd int64)
func (*GlobalsT) DeleteCIOHandlerAndOutputOpeners ¶ added in v1.23.0
func (*GlobalsT) GetCIOHandler ¶ added in v1.23.0
GetCIOHandler returns an 'any' type so that it can exist with the rest of the globals, yet does not require C to be built.
func (*GlobalsT) GetMuxOutputHandler ¶ added in v1.23.0
func (g *GlobalsT) GetMuxOutputHandler(fd int64) OutputHandler
func (*GlobalsT) PutCIOHandler ¶ added in v1.23.0
func (*GlobalsT) RemoveURLHandlers ¶ added in v1.23.0
type InputHandler ¶ added in v1.23.0
type InputHandler interface {
// Read reads from input stream into buf.
// Returns (0, nil) to indicate EOF.
Read(buf []byte) (int, error)
// Seek to specific offset of the input.
Seek(offset int64, whence int) (int64, error)
// Close the input.
Close() error
// Size returns the size of input, if the size is not known returns 0 or -1.
Size() int64
// Stat reports some stats
Stat(streamIndex int, statType AVStatType, statArgs interface{}) error
}
type InputOpener ¶ added in v1.23.0
type InputOpener interface {
// Open returns an InputHandler or an error
// fd determines uniquely opening input.
// url determines input string for transcoding
Open(fd int64, url string) (InputHandler, error)
}
func GetGlobalInputOpener ¶ added in v1.23.0
func GetGlobalInputOpener() InputOpener
func GetInputOpener ¶ added in v1.23.0
func GetInputOpener(url string) InputOpener
type MuxOutputOpener ¶ added in v1.23.0
type MuxOutputOpener interface {
// Open returns an OutputHandler or an error
// url and fd determines uniquely opening output.
Open(url string, fd int64, outType AVType) (OutputHandler, error)
}
func GetMuxOutputOpener ¶ added in v1.23.0
func GetMuxOutputOpener(url string) MuxOutputOpener
type OutputHandler ¶ added in v1.23.0
type OutputHandler interface {
// Write writes encoded stream to the output.
Write(buf []byte) (int, error)
// Seek to specific offset of the output.
Seek(offset int64, whence int) (int64, error)
// Close the output.
Close() error
// Stat reports some stats
Stat(streamIndex int, avType AVType, statType AVStatType, statArgs interface{}) error
}
type OutputOpener ¶ added in v1.23.0
type OutputOpener interface {
// Open returns an OutputHandler or an error
// h determines uniquely opening input.
// fd determines uniquely opening output.
Open(h, fd int64, streamIndex, segIndex int, pts int64, outType AVType) (OutputHandler, error)
}
func GetOutputOpener ¶ added in v1.23.0
func GetOutputOpener(url string) OutputOpener
func GetOutputOpenerByHandler ¶ added in v1.23.0
func GetOutputOpenerByHandler(h int64) OutputOpener
type XcParams ¶
type XcParams struct {
Url string `json:"url"`
BypassTranscoding bool `json:"bypass,omitempty"`
Format string `json:"format,omitempty"`
StartTimeTs int64 `json:"start_time_ts,omitempty"`
StartPts int64 `json:"start_pts,omitempty"` // Start PTS for output
DurationTs int64 `json:"duration_ts,omitempty"`
StartSegmentStr string `json:"start_segment_str,omitempty"`
VideoBitrate int32 `json:"video_bitrate,omitempty"`
AudioBitrate int32 `json:"audio_bitrate,omitempty"`
SampleRate int32 `json:"sample_rate,omitempty"` // Audio sampling rate
RcMaxRate int32 `json:"rc_max_rate,omitempty"`
RcBufferSize int32 `json:"rc_buffer_size,omitempty"`
CrfStr string `json:"crf_str,omitempty"`
Preset string `json:"preset,omitempty"`
AudioSegDurationTs int64 `json:"audio_seg_duration_ts,omitempty"`
VideoSegDurationTs int64 `json:"video_seg_duration_ts,omitempty"`
SegDuration string `json:"seg_duration,omitempty"`
StartFragmentIndex int32 `json:"start_fragment_index,omitempty"`
ForceKeyInt int32 `json:"force_keyint,omitempty"`
Ecodec string `json:"ecodec,omitempty"` // Video encoder
Ecodec2 string `json:"ecodec2,omitempty"` // Audio encoder
Dcodec string `json:"dcodec,omitempty"` // Video decoder
Dcodec2 string `json:"dcodec2,omitempty"` // Audio decoder
GPUIndex int32 `json:"gpu_index,omitempty"` // GPU index if encoder/decoder is GPU (nvidia)
EncHeight int32 `json:"enc_height,omitempty"`
EncWidth int32 `json:"enc_width,omitempty"`
CryptIV string `json:"crypt_iv,omitempty"`
CryptKey string `json:"crypt_key,omitempty"`
CryptKID string `json:"crypt_kid,omitempty"`
CryptKeyURL string `json:"crypt_key_url,omitempty"`
CryptScheme CryptScheme `json:"crypt_scheme,omitempty"`
XcType XcType `json:"xc_type,omitempty"`
// UseCustomLiveReader is used to indicate that the custom live reader should be used
// for reading the input stream, and possibly preprocessing it. If this is set to true, the
// caller should either have already provided a custom live reader via `InitUrlIOHandler`. If it
// has not been set by the time `XcInit` or `Xc` is called, the default input reader will be
// used.
UseCustomLiveReader bool `json:"use_custom_live_reader,omitempty"`
// If true, the input MPEGTS stream will be copied to the output without any processing
// TODO(Nate): Remove this to have better semantics, but for now adding a field is one of the
// easiest ways to implement this. Likely change this before merging, or have the `CopyMpegts` field have values:
// - "": no copy
// - "raw": copy the input MPEGTS stream unedited
// - "parsed": copy the MPEGTS stream as we do now from ffmpeg outputs
CopyMpegtsFromInput bool `json:"copy_mpegts_from_input,omitempty"`
CopyMpegts bool `json:"copy_mpegts,omitempty"`
Seekable bool `json:"seekable,omitempty"`
WatermarkText string `json:"watermark_text,omitempty"`
WatermarkTimecode string `json:"watermark_timecode,omitempty"`
WatermarkTimecodeRate float32 `json:"watermark_timecode_rate,omitempty"`
WatermarkXLoc string `json:"watermark_xloc,omitempty"`
WatermarkYLoc string `json:"watermark_yloc,omitempty"`
WatermarkRelativeSize float32 `json:"watermark_relative_size,omitempty"`
WatermarkFontColor string `json:"watermark_font_color,omitempty"`
WatermarkShadow bool `json:"watermark_shadow,omitempty"`
WatermarkShadowColor string `json:"watermark_shadow_color,omitempty"`
WatermarkOverlay string `json:"watermark_overlay,omitempty"` // Buffer containing overlay image
WatermarkOverlayLen int `json:"watermark_overlay_len,omitempty"` // Length of overlay image
WatermarkOverlayType ImageType `json:"watermark_overlay_type,omitempty"` // Type of overlay image (i.e PngImage, ...)
StreamId int32 `json:"stream_id"` // Specify stream by ID (instead of index)
AudioIndex []int32 `json:"audio_index"` // the length of this is equal to the number of audios
ChannelLayout int `json:"channel_layout"` // Audio channel layout
MaxCLL string `json:"max_cll,omitempty"`
MasterDisplay string `json:"master_display,omitempty"`
VideoLayout int32 `json:"video_layout,omitempty"`
BitDepth int32 `json:"bitdepth,omitempty"`
SyncAudioToStreamId int `json:"sync_audio_to_stream_id"`
ForceEqualFDuration bool `json:"force_equal_frame_duration,omitempty"`
MuxingSpec string `json:"muxing_spec,omitempty"`
Listen bool `json:"listen"`
ConnectionTimeout int `json:"connection_timeout"`
FilterDescriptor string `json:"filter_descriptor"`
SkipDecoding bool `json:"skip_decoding"`
DebugFrameLevel bool `json:"debug_frame_level"`
ExtractImageIntervalTs int64 `json:"extract_image_interval_ts,omitempty"`
ExtractImagesTs []int64 `json:"extract_images_ts,omitempty"`
VideoTimeBase int `json:"video_time_base,omitempty"`
VideoFrameDurationTs int `json:"video_frame_duration_ts,omitempty"`
Rotate int `json:"rotate,omitempty"`
Profile string `json:"profile,omitempty"`
Level int `json:"level,omitempty"`
Deinterlace int `json:"deinterlace,omitempty"`
Timecode string `json:"timecode,omitempty"`
}
XcParams should match with txparams_t in avpipe_xc.h
func NewXcParams ¶
func NewXcParams() *XcParams
NewXcParams initializes a XcParams struct with unset/default values
func (*XcParams) UnmarshalJSON ¶
Custom unmarshalJSON for XcParams to make things backwards compatible with prior serialization
Explanations of backwards compatible serializations:
- NEW: The number of audios is specified by the length of the `AudioIndex` slice. OLD: The number of audios was specified by a larger `AudioIndex` array and a `n_audio` field specifying the number. CONVERSION: If a `n_audio` field exists, the `AudioIndex` slice is shortened to be that length.
func (*XcParams) UnmarshalMap ¶
type XcType ¶
type XcType int
const ( XcNone XcType = iota XcVideo XcType = 1 XcAudio XcType = 2 XcAll XcType = 3 // XcAudio | XcVideo XcAudioMerge XcType = 6 // XcAudio | 0x04 XcAudioJoin XcType = 10 // XcAudio | 0x08 XcAudioPan XcType = 18 // XcAudio | 0x10 XcMux XcType = 32 XcExtractImages XcType = 65 // XcVideo | 2^6 XcExtractAllImages XcType = 129 // XcVideo | 2^7 Xcprobe XcType = 256 )