av

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2020 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package av defines basic interfaces and data structures of container demux/mux and audio encode/decode.

Index

Constants

View Source
const (
	// U8 data
	U8 = SampleFormat(iota + 1) // U8 8-bit unsigned integer
	// S16 data
	S16 // signed 16-bit integer
	// S32 data
	S32 // signed 32-bit integer
	// FLT data
	FLT // 32-bit float
	// DBL data
	DBL // 64-bit float
	// U8P data
	U8P // 8-bit unsigned integer in planar
	// S16P data
	S16P // signed 16-bit integer in planar
	// S32P data
	S32P // signed 32-bit integer in planar
	// FLTP data
	FLTP // 32-bit float in planar
	// DBLP data
	DBLP // 64-bit float in planar
	// U32 data
	U32 // unsigned 32-bit integer
)
View Source
const (
	ChFrontCenter = ChannelLayout(1 << iota)
	ChFrontLeft
	ChFrontRight
	ChBackCenter
	ChBackLeft
	ChBackRight
	ChSideLeft
	ChSideRight
	ChLowFreq
	ChNr

	ChMono     = ChannelLayout(ChFrontCenter)
	ChStereo   = ChannelLayout(ChFrontLeft | ChFrontRight)
	Ch21       = ChannelLayout(ChStereo | ChBackCenter)
	Ch2Point1  = ChannelLayout(ChStereo | ChLowFreq)
	ChSurround = ChannelLayout(ChStereo | ChFrontCenter)
	Ch3Point1  = ChannelLayout(ChSurround | ChLowFreq)
)

define Audio channel layout

Variables

View Source
var (
	TEXT = CodecType(0)
	// define video
	H264 = MakeVideoCodecType(avCodecTypeMagic + 1)
	JPEG = MakeVideoCodecType(avCodecTypeMagic + 2)
	HEVC = MakeVideoCodecType(avCodecTypeMagic + 3)

	// define audio
	AAC  = MakeAudioCodecType(avCodecTypeMagic + 1)
	PCMU = MakeAudioCodecType(avCodecTypeMagic + 2)
	PCMA = MakeAudioCodecType(avCodecTypeMagic + 3)
	MP3  = MakeAudioCodecType(avCodecTypeMagic + 4)
)

Define Codec type

Functions

This section is empty.

Types

type AudioCodecData

type AudioCodecData interface {
	CodecData
	SampleFormat() SampleFormat                   // audio sample format
	SampleRate() int                              // audio sample rate
	ChannelLayout() ChannelLayout                 // audio channel layout
	PacketDuration([]byte) (time.Duration, error) // get audio compressed packet duration
}

AudioCodecData AudioCodecData

type AudioDecoder

type AudioDecoder interface {
	Decode([]byte) (bool, AudioFrame, error) // decode one compressed audio packet
	Close()                                  // close decode, free cgo contexts
}

AudioDecoder can decode compressed audio packets into raw audio frame. use ffmpeg.NewAudioDecoderParam to create it.

type AudioEncoder

type AudioEncoder interface {
	CodecData() (AudioCodecData, error)   // encoder's codec data can put into container
	Encode(AudioFrame) ([][]byte, error)  // encode raw audio frame into compressed pakcet(s)
	Close()                               // close encoder, free cgo contexts
	SetSampleRate(int) error              // set encoder sample rate
	SetChannelLayout(ChannelLayout) error // set encoder channel layout
	SetSampleFormat(SampleFormat) error   // set encoder sample format
	SetBitrate(int) error                 // set encoder bitrate
	SetOption(string, interface{}) error  // encoder setopt, in ffmpeg is av_opt_set_dict()
	GetOption(string, interface{}) error  // encoder getopt
}

AudioEncoder can encode raw audio frame into compressed audio packets. cgo/ffmpeg inplements AudioEncoder, using ffmpeg.NewAudioEncoder to create it.

type AudioFrame

type AudioFrame struct {
	SampleFormat  SampleFormat  // audio sample format, e.g: S16,FLTP,...
	ChannelLayout ChannelLayout // audio channel layout, e.g: ChMono,ChStereo,...
	SampleCount   int           // sample count in this frame
	SampleRate    int           // sample rate
	Data          [][]byte      // data array for planar format len(Data) > 1
}

AudioFrame Raw audio frame.

func (AudioFrame) Concat

func (frame AudioFrame) Concat(in AudioFrame) AudioFrame

Concat two audio frames.

func (AudioFrame) Duration

func (frame AudioFrame) Duration() time.Duration

Duration Duration

func (AudioFrame) HasSameFormat

func (frame AudioFrame) HasSameFormat(other AudioFrame) bool

HasSameFormat Check this audio frame has same format as other audio frame.

func (AudioFrame) Slice

func (frame AudioFrame) Slice(start int, end int) (out AudioFrame)

Slice Split sample audio sample from this frame.

type AudioResampler

type AudioResampler interface {
	Resample(AudioFrame) (AudioFrame, error) // convert raw audio frames
}

AudioResampler can convert raw audio frames in different sample rate/format/channel layout.

type ChannelLayout

type ChannelLayout uint16

ChannelLayout Audio channel layout.

func (ChannelLayout) Count

func (layout ChannelLayout) Count() (n int)

Count Count

func (ChannelLayout) String

func (layout ChannelLayout) String() string

String channel layout string

type CodecData

type CodecData interface {
	Type() CodecType // Video/Audio codec type
}

CodecData is some important bytes for initializing audio/video decoder, can be converted to VideoCodecData or AudioCodecData using:

codecdata.(AudioCodecData) or codecdata.(VideoCodecData)

for H264, CodecData is AVCDecoderConfigure bytes, includes SPS/PPS.

type CodecType

type CodecType uint32

CodecType Video/Audio codec type. can be H264/AAC/SPEEX/...

func MakeAudioCodecType

func MakeAudioCodecType(base uint32) (c CodecType)

MakeAudioCodecType Make a new audio codec type.

func MakeVideoCodecType

func MakeVideoCodecType(base uint32) (c CodecType)

MakeVideoCodecType Make a new video codec type.

func (CodecType) CodecName

func (ctype CodecType) CodecName() string

CodecName CodecType to string name

func (CodecType) IsAudio

func (ctype CodecType) IsAudio() bool

IsAudio IsAudio

func (CodecType) IsVideo

func (ctype CodecType) IsVideo() bool

IsVideo IsVideo

func (CodecType) String

func (ctype CodecType) String() string

String CodecType to string name

type DemuxCloser

type DemuxCloser interface {
	Demuxer
	Close() error
}

DemuxCloser Demuxer with Close() method

type Demuxer

type Demuxer interface {
	PacketReader                   // read compressed audio/video packets
	Streams() ([]CodecData, error) // reads the file header, contains video/audio meta infomations
}

Demuxer can read compressed audio/video packets from container formats like MP4/FLV/MPEG-TS.

type H264VideoCodecData

type H264VideoCodecData interface {
	VideoCodecData
	SPS() []byte
	PPS() []byte
}

H264VideoCodecData for h264 info

type H265VideoCodecData added in v1.0.5

type H265VideoCodecData interface {
	VideoCodecData
	VPS() []byte
	SPS() []byte
	PPS() []byte
}

H265VideoCodecData for h264 info

type MPEG4AudioCodecData

type MPEG4AudioCodecData interface {
	AudioCodecData
	MPEG4AudioConfigBytes() []byte
}

MPEG4AudioCodecData audio codec data for aac

type MuxCloser

type MuxCloser interface {
	Muxer
	Close() error
}

MuxCloser Muxer with Close() method

type Muxer

type Muxer interface {
	WriteHeader([]CodecData) error // write the file header
	PacketWriter                   // write compressed audio/video packets
	WriteTrailer() error           // finish writing file, this func can be called only once
}

Muxer describes the steps of writing compressed audio/video packets into container formats like MP4/FLV/MPEG-TS.

Container formats, rtmp.Conn, and transcode.Muxer implements Muxer interface.

type Packet

type Packet struct {
	IsKeyFrame      bool          // video packet is key frame
	Idx             int8          // stream index in container format
	CompositionTime time.Duration // packet presentation time minus decode time for H264 B-Frame
	Time            time.Duration // packet decode time
	Data            []byte        // packet data
}

Packet stores compressed audio/video data.

type PacketReader

type PacketReader interface {
	ReadPacket() (Packet, error)
}

PacketReader PacketReader

type PacketWriter

type PacketWriter interface {
	WritePacket(Packet) error
}

PacketWriter PacketWriter

type SampleFormat

type SampleFormat uint8

SampleFormat Audio sample format.

func (SampleFormat) BytesPerSample

func (format SampleFormat) BytesPerSample() int

BytesPerSample BytesPerSample

func (SampleFormat) IsPlanar

func (format SampleFormat) IsPlanar() bool

IsPlanar Check if this sample format is in planar.

func (SampleFormat) String

func (format SampleFormat) String() string

type VideoCodecData

type VideoCodecData interface {
	CodecData
	Width() int  // Video width
	Height() int // Video height
}

VideoCodecData VideoCodecData

Directories

Path Synopsis
Package pktque provides packet Filter interface and structures used by other components.
Package pktque provides packet Filter interface and structures used by other components.
Package pubsub implements publisher-subscribers model used in multi-channel streaming.
Package pubsub implements publisher-subscribers model used in multi-channel streaming.
Package transcode implements Transcoder based on Muxer/Demuxer and AudioEncoder/AudioDecoder interface.
Package transcode implements Transcoder based on Muxer/Demuxer and AudioEncoder/AudioDecoder interface.

Jump to

Keyboard shortcuts

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