Documentation
¶
Overview ¶
Package avpipe has four main interfaces that has to be implemented by the client code:
InputOpener: is the input factory interface that needs an implementation to generate an InputHandler.
InputHandler: is the input handler with Read/Seek/Size/Close methods. An implementation of this interface is needed by ffmpeg to process input streams properly.
OutputOpener: is the output factory interface that needs an implementation to generate an OutputHandler.
OutputHandler: is the output handler with Write/Seek/Close methods. An implementation of this interface is needed by ffmpeg to write encoded streams properly.
* Defines various audio/video transcoding errors.
Index ¶
- Constants
- Variables
- func AVPipeCloseInput(fd C.int64_t) C.int
- func AVPipeCloseMuxOutput(fd C.int64_t) C.int
- func AVPipeCloseOutput(handler C.int64_t, fd C.int64_t) C.int
- func AVPipeOpenInput(url *C.char, size *C.int64_t) C.int64_t
- func AVPipeOpenMuxInput(out_url, url *C.char, size *C.int64_t) C.int64_t
- func AVPipeOpenMuxOutput(url *C.char, stream_type C.int) C.int64_t
- func AVPipeOpenOutput(handler C.int64_t, stream_index, seg_index C.int, pts C.int64_t, ...) C.int64_t
- func AVPipeReadInput(fd C.int64_t, buf *C.uint8_t, sz C.int) C.int
- func AVPipeSeekInput(fd C.int64_t, offset C.int64_t, whence C.int) C.int64_t
- func AVPipeSeekMuxOutput(fd C.int64_t, offset C.int64_t, whence C.int) C.int64_t
- func AVPipeSeekOutput(handler C.int64_t, fd C.int64_t, offset C.int64_t, whence C.int) C.int64_t
- func AVPipeStatInput(fd C.int64_t, stream_index C.int, avp_stat C.avp_stat_t, ...) C.int
- func AVPipeStatMuxOutput(fd C.int64_t, stream_index C.int, avp_stat C.avp_stat_t, ...) C.int
- func AVPipeStatOutput(handler C.int64_t, fd C.int64_t, stream_index C.int, ...) C.int
- func AVPipeWriteMuxOutput(fd C.int64_t, buf *C.uint8_t, sz C.int) C.int
- func AVPipeWriteOutput(handler C.int64_t, fd C.int64_t, buf *C.uint8_t, sz C.int) C.int
- func CDebug(msg *C.char) C.int
- func CError(msg *C.char) C.int
- func CInfo(msg *C.char) C.int
- func CLog(msg *C.char) C.int
- func CWarn(msg *C.char) C.int
- func ChannelLayout(name string) int
- func ChannelLayoutName(nbChannels, channelLayout int) string
- func GetPixelFormatName(pixFmt int) string
- func GetProfileName(codecId int, profile int) string
- func H264GuessLevel(profile int, bitrate int64, framerate, width, height int) int
- func H264GuessProfile(bitdepth, width, height int) int
- func InitIOHandler(inputOpener InputOpener, outputOpener OutputOpener)
- func InitMuxIOHandler(inputOpener InputOpener, muxOutputOpener MuxOutputOpener)
- func InitUrlIOHandler(url string, inputOpener InputOpener, outputOpener OutputOpener)
- func InitUrlMuxIOHandler(url string, inputOpener InputOpener, muxOutputOpener MuxOutputOpener)
- func Mux(params *XcParams) error
- func SetCLoggers()
- func Version() string
- func Xc(params *XcParams) error
- func XcCancel(handle int32) error
- func XcInit(params *XcParams) (int32, error)
- func XcRun(handle int32) error
- type AVFieldOrder
- type AVMediaType
- type AVStatType
- type AVType
- type ContainerInfo
- type CryptScheme
- type EncodingFrameStats
- type IOHandler
- type ImageType
- type InputHandler
- type InputOpener
- type MuxOutputOpener
- type OutputHandler
- type OutputOpener
- type ProbeInfo
- type SeekReadWriteCloser
- type SideDataDisplayMatrix
- type StreamInfo
- type XcParams
- type XcProfile
- type XcType
Constants ¶
const ( XcNone XcType = iota XcVideo = 1 XcAudio = 2 XcAll = 3 // XcAudio | XcVideo XcAudioMerge = 6 // XcAudio | 0x04 XcAudioJoin = 10 // XcAudio | 0x08 XcAudioPan = 18 // XcAudio | 0x10 XcMux = 32 XcExtractImages = 65 // XcVideo | 2^6 XcExtractAllImages = 129 // XcVideo | 2^7 Xcprobe = 256 )
const ( XcProfileNone XcProfile = iota XcProfileH264BaseLine = C.FF_PROFILE_H264_BASELINE // 66 XcProfileH264Heigh = C.FF_PROFILE_H264_HIGH // 100 XcProfileH264Heigh10 = C.FF_PROFILE_H264_HIGH_10 // 110 )
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 ( AV_IN_STAT_BYTES_READ = 1 AV_IN_STAT_AUDIO_FRAME_READ = 2 AV_IN_STAT_VIDEO_FRAME_READ = 4 AV_IN_STAT_DECODING_AUDIO_START_PTS = 8 AV_IN_STAT_DECODING_VIDEO_START_PTS = 16 AV_OUT_STAT_BYTES_WRITTEN = 32 AV_OUT_STAT_FRAME_WRITTEN = 64 AV_IN_STAT_FIRST_KEYFRAME_PTS = 128 AV_OUT_STAT_ENCODING_END_PTS = 256 AV_IN_STAT_DATA_SCTE35 = 512 )
const AvNoPtsValue = uint64(C.uint64_t(0x8000000000000000))
This is corresponding to AV_NOPTS_VALUE
const MaxAudioMux = C.MAX_STREAMS
Variables ¶
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 EAV_AUDIO_SAMPLE = errors.New("EAV_AUDIO_SAMPLE")
EAV_AUDIO_SAMPLE is the error returned when avpipe fails to convert audio samples.
var EAV_BAD_HANDLE = errors.New("EAV_BAD_HANDLE")
EAV_BAD_HANDLE is the error returned when the transcoding session handle is not valid
var EAV_CANCELLED = errors.New("EAV_CANCELLED")
EAV_CANCELLED is the error returned when a transcoding session is cancelled. This error is returned from Tx() or TxRun() if transcoding session is cancelled by calling TxCancel() and TxCancel() was successful.
var EAV_CANCEL_FAILED = errors.New("EAV_CANCEL_FAILED")
EAV_CANCEL_FAILED is the error returned when cancelling a transcoding session fails. This error is returned from TxCancel() if cancelling a transcoding fails.
var EAV_CODEC_CONTEXT = errors.New("EAV_CODEC_CONTEXT")
EAV_CODEC_CONTEXT is the error returned when - codec context doesn't exist for a stream index or - avpipe fails to find codec context for a stream or - avpipe fails to allocate codec format context
var EAV_CODEC_PARAM = errors.New("EAV_CODEC_PARAM")
EAV_CODEC_PARAM is the error returned when avpipe fails - to copy codec params to codec context for output stream or - codec parameters are not correct
var EAV_FILTER_INIT = errors.New("EAV_FILTER_INIT")
EAV_FILTER_INIT is the error returned when avpipe fails to initialize a filter.
var EAV_FILTER_STRING_INIT = errors.New("EAV_FILTER_STRING_INIT")
EAV_FILTER_STRING_INIT is the error returned when avpipe fails to obtain filter string.
var EAV_IO_TIMEOUT = errors.New("EAV_IO_TIMEOUT")
EAV_IO_TIMEOUT is the error returned when there is a timeout in network/disk io
var EAV_MEM_ALLOC = errors.New("EAV_MEM_ALLOC")
EAV_MEM_ALLOC is the error returned when avpipe fails to allocate memory for a frame, or a packet, or a context (i.e format context).
var EAV_NUM_STREAMS = errors.New("EAV_NUM_STREAMS")
EAV_NUM_STREAMS is the error returned when the number of streams are wrong while avpipe does transcoding
var EAV_OPEN_CODEC = errors.New("EAV_OPEN_CODEC")
EAV_OPEN_CODEC is the error returned when avpipe fails to open the codec.
var EAV_OPEN_INPUT = errors.New("EAV_OPEN_INPUT")
EAV_OPEN_INPUT is the error returned when avpipe fails to open the input or stream container due to invalid/corrupted data
var EAV_PARAM = errors.New("EAV_PARAM")
EAV_PARAM is the error returned when one of the transcoding params is not correct.
var EAV_PTS_WRAPPED = errors.New("EAV_PTS_WRAPPED")
EAV_PTS_WRAPPED is the error returned when PTS is wrapped in the source/input.
var EAV_READ_INPUT = errors.New("EAV_READ_INPUT")
EAV_READ_INPUT is the error returned when avpipe fails to read input packets.
var EAV_RECEIVE_FILTER_FRAME = errors.New("EAV_RECEIVE_FILTER_FRAME")
EAV_RECEIVE_FILTER_FRAME is the error returned when avpipe fails to receive frame from filter.
var EAV_RECEIVE_FRAME = errors.New("EAV_RECEIVE_FRAME")
EAV_RECEIVE_FRAME is the error returned when avpipe fails to receive frame from decoder or audio fifo.
var EAV_RECEIVE_PACKET = errors.New("EAV_RECEIVE_PACKET")
EAV_RECEIVE_PACKET is the error returned when avpipe fails to receive packets from encoder.
var EAV_SEEK = errors.New("EAV_SEEK")
EAV_SEEK is the error returned when avpipe fails to seek.
var EAV_SEND_PACKET = errors.New("EAV_SEND_PACKET")
EAV_SEND_PACKET is the error returned when avpipe fails to send packet to decoder. This error means the packet is invalid.
var EAV_STREAM_INDEX = errors.New("EAV_STREAM_INDEX")
EAV_STREAM_INDEX is the error returned when stream index is not correct.
var EAV_STREAM_INFO = errors.New("EAV_STREAM_INFO")
EAV_STREAM_INFO is the error returned when avpipe fails to obtain stream info.
var EAV_TIMEBASE = errors.New("EAV_TIMEBASE")
EAV_TIMEBASE is the error returned when the timebase is not correct. This can happen if the calculated codec context timebase doesn't match with output stream timebase.
var EAV_UNKNOWN = errors.New("EAV_UNKNOWN")
EAV_UNKNOWN is the error returned when error code doesn't exist in avpipeErrors table (below).
var EAV_WRITE_FRAME = errors.New("EAV_WRITE_FRAME")
EAV_WRITE_FRAME is the error returned when avpipe fails to write the frame into output stream or audio fifo.
var EAV_WRITE_HEADER = errors.New("EAV_WRITE_HEADER")
EAV_WRITE_HEADER is the error returned when avpipe fails to write the output stream header.
var EAV_XC_TABLE = errors.New("EAV_XC_TABLE")
EAV_XC_TABLE is the error returned when avpipe fails to find xc context in the xc_table.
Functions ¶
func AVPipeOpenOutput ¶
func AVPipeSeekMuxOutput ¶
func AVPipeSeekOutput ¶
func AVPipeStatInput ¶
func AVPipeStatMuxOutput ¶
func AVPipeStatOutput ¶
func AVPipeWriteOutput ¶
func ChannelLayout ¶
func ChannelLayoutName ¶
func GetPixelFormatName ¶
func GetProfileName ¶
func H264GuessLevel ¶
func H264GuessProfile ¶
func InitIOHandler ¶
func InitIOHandler(inputOpener InputOpener, outputOpener OutputOpener)
This 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 ¶
func InitMuxIOHandler(inputOpener InputOpener, muxOutputOpener MuxOutputOpener)
Sets the global handlers for muxing (similar to InitIOHandler for transcoding)
func InitUrlIOHandler ¶
func InitUrlIOHandler(url string, inputOpener InputOpener, outputOpener OutputOpener)
This 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 InitUrlMuxIOHandler ¶
func InitUrlMuxIOHandler(url string, inputOpener InputOpener, muxOutputOpener MuxOutputOpener)
Sets specific IO handler for muxing a url/file (similar to InitUrlIOHandler)
func SetCLoggers ¶
func SetCLoggers()
Types ¶
type AVFieldOrder ¶
type AVFieldOrder int
type AVMediaType ¶
type AVMediaType int
type AVStatType ¶
type AVStatType int
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 )
type ContainerInfo ¶
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 EncodingFrameStats ¶
type IOHandler ¶
type IOHandler interface { InReader(buf []byte) (int, error) InSeeker(offset C.int64_t, whence C.int) error InCloser() error InStat(stream_index C.int, avp_stat C.avp_stat_t, stat_args *C.void) error OutWriter(fd C.int, buf []byte) (int, error) OutSeeker(fd C.int, offset C.int64_t, whence C.int) (int64, error) OutCloser(fd C.int) error OutStat(stream_index C.int, avp_stat C.avp_stat_t, stat_args *C.void) error }
IOHandler defines handlers that will be called from the C interface functions
type InputHandler ¶
type InputHandler interface { // Reads from input stream into buf. // Returns (0, nil) to indicate EOF. Read(buf []byte) (int, error) // Seeks to specific offset of the input. Seek(offset int64, whence int) (int64, error) // Closes the input. Close() error // Returns the size of input, if the size is not known returns 0 or -1. Size() int64 // Reports some stats Stat(streamIndex int, statType AVStatType, statArgs interface{}) error }
type InputOpener ¶
type InputOpener interface { // fd determines uniquely opening input. // url determines input string for transcoding Open(fd int64, url string) (InputHandler, error) }
type MuxOutputOpener ¶
type MuxOutputOpener interface { // url and fd determines uniquely opening output. Open(url string, fd int64, out_type AVType) (OutputHandler, error) }
type OutputHandler ¶
type OutputHandler interface { // Writes encoded stream to the output. Write(buf []byte) (int, error) // Seeks to specific offset of the output. Seek(offset int64, whence int) (int64, error) // Closes the output. Close() error // Reports some stats Stat(streamIndex int, avType AVType, statType AVStatType, statArgs interface{}) error }
type OutputOpener ¶
type ProbeInfo ¶
type ProbeInfo struct { ContainerInfo ContainerInfo `json:"format"` StreamInfo []StreamInfo `json:"streams"` }
PENDING: use legacy_imf_dash_extract/media.Probe?
type SeekReadWriteCloser ¶
type SideDataDisplayMatrix ¶
type StreamInfo ¶
type StreamInfo struct { StreamIndex int `json:"stream_index"` StreamId int32 `json:"stream_id"` CodecType string `json:"codec_type"` CodecID int `json:"codec_id,omitempty"` CodecName string `json:"codec_name,omitempty"` DurationTs int64 `json:"duration_ts,omitempty"` TimeBase *big.Rat `json:"time_base,omitempty"` NBFrames int64 `json:"nb_frames,omitempty"` StartTime int64 `json:"start_time"` // in TS unit AvgFrameRate *big.Rat `json:"avg_frame_rate,omitempty"` FrameRate *big.Rat `json:"frame_rate,omitempty"` SampleRate int `json:"sample_rate,omitempty"` Channels int `json:"channels,omitempty"` ChannelLayout int `json:"channel_layout,omitempty"` TicksPerFrame int `json:"ticks_per_frame,omitempty"` BitRate int64 `json:"bit_rate,omitempty"` Has_B_Frames bool `json:"has_b_frame"` Width int `json:"width,omitempty"` // Video only Height int `json:"height,omitempty"` // Video only PixFmt int `json:"pix_fmt"` // Video only, it matches with enum AVPixelFormat in FFmpeg SampleAspectRatio *big.Rat `json:"sample_aspect_ratio,omitempty"` DisplayAspectRatio *big.Rat `json:"display_aspect_ratio,omitempty"` FieldOrder string `json:"field_order,omitempty"` Profile int `json:"profile,omitempty"` Level int `json:"level,omitempty"` SideData []interface{} `json:"side_data,omitempty"` Tags map[string]string `json:"tags,omitempty"` }
func StreamInfoAsArray ¶
func StreamInfoAsArray(s []StreamInfo) []StreamInfo
StreamInfoAsArray builds an array where each stream is at its corresponsing index by filling in non-existing index positions with codec type "unknown"
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"` 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"` 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"` VideoFrameDurationTs int `json:"video_frame_duration_ts"` Rotate int `json:"rotate"` Profile string `json:"profile"` Level int `json:"level"` }
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.