flv

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AVC_SEQUENCE_HEADER = 0
	AVC_NALU            = 1
)
View Source
const (
	AAC_SEQUENCE_HEADER = 0
	AAC_RAW             = 1
)
View Source
const (
	PacketTypeSequenceStart        = 0
	PacketTypeCodedFrames          = 1
	PacketTypeSequenceEnd          = 2
	PacketTypeCodedFramesX         = 3
	PacketTypeMetadata             = 4
	PacketTypeMPEG2TSSequenceStart = 5
)

enhanced-rtmp Table 4

View Source
const FLVTAG_SIZE uint32 = 11

Variables

This section is empty.

Functions

func CovertFlvAudioCodecId2MpegCodecId

func CovertFlvAudioCodecId2MpegCodecId(cid FLV_SOUND_FORMAT) codec.CodecID

func CovertFlvVideoCodecId2MpegCodecId

func CovertFlvVideoCodecId2MpegCodecId(cid FLV_VIDEO_CODEC_ID) codec.CodecID

func GetTagLenByAudioCodec

func GetTagLenByAudioCodec(cid FLV_SOUND_FORMAT) int

func GetTagLenByVideoCodec

func GetTagLenByVideoCodec(cid FLV_VIDEO_CODEC_ID) int

func GetUint24

func GetUint24(b []byte) (v uint32)

func PutUint24

func PutUint24(b []byte, v uint32)

func WriteAudioTag

func WriteAudioTag(data []byte, cid FLV_SOUND_FORMAT, sampleRate int, channelCount int, isSequenceHeader bool) []byte

func WriteVideoTag

func WriteVideoTag(data []byte, isKey bool, cid FLV_VIDEO_CODEC_ID, cts int32, isSequenceHeader bool) []byte

Types

type AACMuxer

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

func NewAACMuxer

func NewAACMuxer() *AACMuxer

func (*AACMuxer) Write

func (muxer *AACMuxer) Write(frames []byte, pts uint32, dts uint32) [][]byte

type AACTagDemuxer

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

func NewAACTagDemuxer

func NewAACTagDemuxer() *AACTagDemuxer

func (*AACTagDemuxer) Decode

func (demuxer *AACTagDemuxer) Decode(data []byte) error

func (*AACTagDemuxer) OnFrame

func (demuxer *AACTagDemuxer) OnFrame(onframe OnAudioFrameCallBack)

type AVCMuxer

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

func NewAVCMuxer

func NewAVCMuxer() *AVCMuxer

func (*AVCMuxer) Write

func (muxer *AVCMuxer) Write(frames []byte, pts uint32, dts uint32) [][]byte

type AVCTagDemuxer

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

func NewAVCTagDemuxer

func NewAVCTagDemuxer() *AVCTagDemuxer

func (*AVCTagDemuxer) Decode

func (demuxer *AVCTagDemuxer) Decode(data []byte) error

func (*AVCTagDemuxer) OnFrame

func (demuxer *AVCTagDemuxer) OnFrame(onframe OnVideoFrameCallBack)

type AVTagMuxer

type AVTagMuxer interface {
	Write(frames []byte, pts uint32, dts uint32) [][]byte
}

func CreateAudioMuxer

func CreateAudioMuxer(cid FLV_SOUND_FORMAT) AVTagMuxer

func CreateVideoMuxer

func CreateVideoMuxer(cid FLV_VIDEO_CODEC_ID) AVTagMuxer

type AudioTag

type AudioTag struct {
	SoundFormat   uint8
	SoundRate     uint8
	SoundSize     uint8
	SoundType     uint8
	AACPacketType uint8
}

func (*AudioTag) Decode

func (atag *AudioTag) Decode(data []byte) error

func (AudioTag) Encode

func (atag AudioTag) Encode() (tag []byte)

type AudioTagDemuxer

type AudioTagDemuxer interface {
	Decode(data []byte) error
	OnFrame(onframe OnAudioFrameCallBack)
}

func CreateAudioTagDemuxer

func CreateAudioTagDemuxer(formats FLV_SOUND_FORMAT) (demuxer AudioTagDemuxer)

type FLVSAMPLEINDEX

type FLVSAMPLEINDEX int
const (
	FLV_SAMPLE_5500 FLVSAMPLEINDEX = iota
	FLV_SAMPLE_11000
	FLV_SAMPLE_22000
	FLV_SAMPLE_44000
)

type FLV_PARSER_STATE

type FLV_PARSER_STATE int
const (
	FLV_PARSER_INIT FLV_PARSER_STATE = iota + 1
	FLV_PARSER_FILE_HEAD
	FLV_PARSER_TAG_SIZE
	FLV_PARSER_FLV_TAG
	FLV_PARSER_DETECT_VIDEO
	FLV_PARSER_DETECT_AUDIO
	FLV_PARSER_VIDEO_TAG
	FLV_PARSER_AUDIO_TAG
	FLV_PARSER_SCRIPT_TAG
)

type FLV_SOUND_FORMAT

type FLV_SOUND_FORMAT int
const (
	FLV_MP3   FLV_SOUND_FORMAT = 2
	FLV_G711A FLV_SOUND_FORMAT = 7
	FLV_G711U FLV_SOUND_FORMAT = 8
	FLV_AAC   FLV_SOUND_FORMAT = 10
)

func CovertCodecId2SoundFromat

func CovertCodecId2SoundFromat(cid codec.CodecID) FLV_SOUND_FORMAT

func (FLV_SOUND_FORMAT) ToMpegCodecId

func (format FLV_SOUND_FORMAT) ToMpegCodecId() codec.CodecID

type FLV_VIDEO_CODEC_ID

type FLV_VIDEO_CODEC_ID int
const (
	FLV_AVC  FLV_VIDEO_CODEC_ID = 7
	FLV_HEVC FLV_VIDEO_CODEC_ID = 12
)

func CovertCodecId2FlvVideoCodecId

func CovertCodecId2FlvVideoCodecId(cid codec.CodecID) FLV_VIDEO_CODEC_ID

func GetFLVVideoCodecId

func GetFLVVideoCodecId(data []byte) (cid FLV_VIDEO_CODEC_ID)

type FLV_VIDEO_FRAME_TYPE

type FLV_VIDEO_FRAME_TYPE int
const (
	KEY_FRAME   FLV_VIDEO_FRAME_TYPE = 1
	INTER_FRAME FLV_VIDEO_FRAME_TYPE = 2
)

type FlvMuxer

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

func NewFlvMuxer

func NewFlvMuxer(vid FLV_VIDEO_CODEC_ID, aid FLV_SOUND_FORMAT) *FlvMuxer

func (*FlvMuxer) SetAudioCodeId

func (muxer *FlvMuxer) SetAudioCodeId(cid FLV_SOUND_FORMAT)

func (*FlvMuxer) SetVideoCodeId

func (muxer *FlvMuxer) SetVideoCodeId(cid FLV_VIDEO_CODEC_ID)

func (*FlvMuxer) WriteAudio

func (muxer *FlvMuxer) WriteAudio(frames []byte, pts uint32, dts uint32) ([][]byte, error)

func (*FlvMuxer) WriteFrames

func (muxer *FlvMuxer) WriteFrames(frameType TagType, frames []byte, pts uint32, dts uint32) ([][]byte, error)

func (*FlvMuxer) WriteVideo

func (muxer *FlvMuxer) WriteVideo(frames []byte, pts uint32, dts uint32) ([][]byte, error)

type FlvReader

type FlvReader struct {
	OnFrame func(cid codec.CodecID, frame []byte, pts uint32, dts uint32)
	// contains filtered or unexported fields
}

func CreateFlvReader

func CreateFlvReader() *FlvReader

func (*FlvReader) Input

func (f *FlvReader) Input(data []byte) (err error)

type FlvTag

type FlvTag struct {
	TagType           uint8
	DataSize          uint32
	Timestamp         uint32
	TimestampExtended uint8
	StreamID          uint32
}

func (*FlvTag) Decode

func (ftag *FlvTag) Decode(data []byte)

func (FlvTag) Encode

func (ftag FlvTag) Encode() []byte

type FlvWriter

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

func CreateFlvWriter

func CreateFlvWriter(writer io.Writer) *FlvWriter

func (*FlvWriter) WriteAAC

func (f *FlvWriter) WriteAAC(data []byte, pts uint32, dts uint32) error

adts aac frame

func (*FlvWriter) WriteFlvHeader

func (f *FlvWriter) WriteFlvHeader() (err error)

func (*FlvWriter) WriteG711A

func (f *FlvWriter) WriteG711A(data []byte, pts uint32, dts uint32) error

func (*FlvWriter) WriteG711U

func (f *FlvWriter) WriteG711U(data []byte, pts uint32, dts uint32) error

func (*FlvWriter) WriteH264

func (f *FlvWriter) WriteH264(data []byte, pts uint32, dts uint32) error

H264 Frame with startcode 0x0000001

func (*FlvWriter) WriteH265

func (f *FlvWriter) WriteH265(data []byte, pts uint32, dts uint32) error

func (*FlvWriter) WriteMp3

func (f *FlvWriter) WriteMp3(data []byte, pts uint32, dts uint32) error

type G711AMuxer

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

func NewG711AMuxer

func NewG711AMuxer(channelCount int, sampleRate int) *G711AMuxer

func (*G711AMuxer) Write

func (muxer *G711AMuxer) Write(frames []byte, pts uint32, dts uint32) [][]byte

type G711Demuxer

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

func NewG711Demuxer

func NewG711Demuxer(format FLV_SOUND_FORMAT) *G711Demuxer

func (*G711Demuxer) Decode

func (demuxer *G711Demuxer) Decode(data []byte) error

func (*G711Demuxer) OnFrame

func (demuxer *G711Demuxer) OnFrame(onframe OnAudioFrameCallBack)

type G711UMuxer

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

func NewG711UMuxer

func NewG711UMuxer(channelCount int, sampleRate int) *G711UMuxer

func (*G711UMuxer) Write

func (muxer *G711UMuxer) Write(frames []byte, pts uint32, dts uint32) [][]byte

type HevcMuxer

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

func NewHevcMuxer

func NewHevcMuxer() *HevcMuxer

func (*HevcMuxer) Write

func (muxer *HevcMuxer) Write(frames []byte, pts uint32, dts uint32) [][]byte

type HevcTagDemuxer

type HevcTagDemuxer struct {
	SpsPpsVps []byte
	// contains filtered or unexported fields
}

func NewHevcTagDemuxer

func NewHevcTagDemuxer() *HevcTagDemuxer

func (*HevcTagDemuxer) Decode

func (demuxer *HevcTagDemuxer) Decode(data []byte) error

func (*HevcTagDemuxer) OnFrame

func (demuxer *HevcTagDemuxer) OnFrame(onframe OnVideoFrameCallBack)

type Mp3Muxer

type Mp3Muxer struct {
}

func (*Mp3Muxer) Write

func (muxer *Mp3Muxer) Write(frames []byte, pts uint32, dts uint32) [][]byte

type OnAudioFrameCallBack

type OnAudioFrameCallBack func(codecid codec.CodecID, frame []byte)

type OnVideoFrameCallBack

type OnVideoFrameCallBack func(codecid codec.CodecID, frame []byte, cts int)

type TagType

type TagType int
const (
	AUDIO_TAG  TagType = 8
	VIDEO_TAG  TagType = 9
	SCRIPT_TAG TagType = 18
)

type VideoTag

type VideoTag struct {
	FrameType       uint8
	CodecId         uint8
	AVCPacketType   uint8
	CompositionTime int32
}

Video Tag VideoTagHeader ------------------------------------------------------------------------ Field type Comment ------------------------------------------------------------------------ Frame Type UB[4] Type of video frame. The following values are defined:

1 = key frame (for AVC, a seekable frame)
2 = inter frame (for AVC, a non-seekable frame)
3 = disposable inter frame (H.263 only)
4 = generated key frame (reserved for server use only)
5 = video info/command frame

CodecID UB[4] Codec Identifier. The following values are defined:

2 = Sorenson H.263
3 = Screen video
4 = On2 VP6
5 = On2 VP6 with alpha channel 6 = Screen video version 2
7 = AVC

AVCPacketType IF CodecID == 7 The following values are defined:

UI8               0 = AVC sequence header
                  1 = AVC NALU
                  2 = AVC end of sequence (lower level NALU sequence ender is not required or supported)

CompositionTime IF CodecID == 7 IF AVCPacketType == 1

SI24                    Composition time offset
                 ELSE
                      0

------------------------------------------------------------------------

func (*VideoTag) Decode

func (vtag *VideoTag) Decode(data []byte)

外部已经确保len(data) >= 5

func (VideoTag) Encode

func (vtag VideoTag) Encode() (tag []byte)

type VideoTagDemuxer

type VideoTagDemuxer interface {
	Decode(data []byte) error
	OnFrame(onframe OnVideoFrameCallBack)
}

func CreateFlvVideoTagHandle

func CreateFlvVideoTagHandle(cid FLV_VIDEO_CODEC_ID) (demuxer VideoTagDemuxer)

Jump to

Keyboard shortcuts

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