flv

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SoundFormatLinearPCMPlatformEndian         = 0
	SoundFormatADPCM                           = 1
	SoundFormatMP3                             = 2
	SoundFormatLinearPCMLittleEndian           = 3
	SoundFormatNellymoser16kHzMono             = 4
	SoundFormatNellymoser8kHzMono              = 5
	SoundFormatNellymoser                      = 6
	SoundFormatReservedG711AlawLogarithmicPCM  = 7
	SoundFormatReservedG711MuLawLogarithmicPCM = 8
	SoundFormatReserved                        = 9
	SoundFormatAAC                             = 10
	SoundFormatSpeex                           = 11
	SoundFormatReservedMP3Of8kHz               = 14
	SoundFormatReservedDeviceSpecificSound     = 15
	SoundFormatReserved1                       = 16
)

SoundFormat UB [4] Format of SoundData. The following values are defined:

0 = Linear PCM, platform endian
1 = ADPCM
2 = MP3
3 = Linear PCM, little endian
4 = Nellymoser 16 kHz mono
5 = Nellymoser 8 kHz mono
6 = Nellymoser
7 = G.711 A-law logarithmic PCM
8 = G.711 mu-law logarithmic PCM
9 = reserved
10 = AAC
11 = Speex
14 = MP3 8 kHz
15 = Device-specific sound

Formats 7, 8, 14, and 15 are reserved. AAC is supported in Flash Player 9,0,115,0 and higher. Speex is supported in Flash Player 10 and higher.

View Source
const (
	SoundRate5512     = 0
	SoundRate11025    = 1
	SoundRate22050    = 2
	SoundRate44100    = 3
	SoundRateReserved = 4
)

the FLV/RTMP supported audio sample rate. Sampling rate. The following values are defined: 0 = 5.5 kHz = 5512 Hz 1 = 11 kHz = 11025 Hz 2 = 22 kHz = 22050 Hz 3 = 44 kHz = 44100 Hz

View Source
const (
	SoundeSize8bit     = 0
	SoundeSize16bit    = 1
	SoundeSizeReserved = 2
)

the FLV/RTMP supported audio sample size. Size of each audio sample. This parameter only pertains to uncompressed formats. Compressed formats always decode to 16 bits internally. 0 = 8-bit samples 1 = 16-bit samples

View Source
const (
	SoundTypeMono     = 0
	SoundTypeStereo   = 1
	SoundTypeReserved = 2
)

the FLV/RTMP supported audio sound type/channel. Mono or stereo sound 0 = Mono sound 1 = Stereo sound

View Source
const (
	AACPacketTypeSequenceHeader = 0 // 序列头
	AACPacketTypeRawData        = 1 // 原始数据
	AACPacketTypeReserved       = 2
)

flv format AACPacketType IF SoundFormat == 10 UI8 The following values are defined:

0 = AAC sequence header
1 = AAC raw
View Source
const (
	FlvHeaderSize   = 9
	TypeFlagsVideo  = 0x04
	TypeFlagsAudio  = 0x01
	TypeFlagsOffset = 4
)

flv Header Size, total is 9Byte.

Signatures	3Byte	'FLV' = 0x46 0x4c 0x56
Version		1Byte	0x01
TypeFlags	1Byte 	bit0:audio bit2:video
DataOffset	4Byte	FLV Header Length
View Source
const (
	MetaDataAudioCodecID    = "audiocodecid"    // Number	音频编解码器 ID
	MetaDataAudioDateRate   = "audiodatarate"   // Number	音频码率,单位 kbps
	MetaDataAudioDelay      = "audiodelay"      // Number	由音频编解码器引入的延时,单位秒
	MetaDataAudioSampleRate = "audiosamplerate" // Number	音频采样率
	MetaDataAudioSampleSize = "audiosamplesize" // Number	音频采样点尺寸
	MetaDataStereo          = "stereo"          // Boolean	音频立体声标志
	MetaDataCanSeekToEnd    = "canSeekToEnd"    // Boolean	指示最后一个视频帧是否是关键帧
	MetaDataCreationDate    = "creationdate"    // String	创建日期与时间
	MetaDataDuration        = "duration"        // Number	文件总时长,单位秒
	MetaDataFileSize        = "filesize"        // Number	文件总长度,单位字节
	MetaDataFrameRate       = "framerate"       // Number	视频帧率
	MetaDataHeight          = "height"          // Number	视频高度,单位像素
	MetaDataVideoCodecID    = "videocodecid"    // Number	视频编解码器 ID
	MetaDataVideoDataRate   = "videodatarate"   // Number	视频码率,单位 kbps
	MetaDataWidth           = "width"           // Number	视频宽度,单位像素
)

MetaData 常见属性名

View Source
const (
	TagTypeAudio    = 0x08
	TagTypeVideo    = 0x09
	TagTypeAmf0Data = 0x12 // 18
)

flv 标记类型ID

View Source
const (
	FrameTypeReserved             = 0
	FrameTypeKeyFrame             = 1 // video h264 key frame
	FrameTypeInterFrame           = 2 // video h264 inter frame
	FrameTypeDisposableInterFrame = 3
	FrameTypeGeneratedKeyFrame    = 4
	FrameTypeVideoInfoFrame       = 5
	FrameTypeReserved1            = 6
)

E.4.3.1 VIDEODATA 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
View Source
const (
	CodecIDReserved               = 0
	CodecIDReserved1              = 1
	CodecIDSorensonH263           = 2
	CodecIDScreenVideo            = 3
	CodecIDOn2VP6                 = 4
	CodecIDOn2VP6WithAlphaChannel = 5
	CodecIDScreenVideoVersion2    = 6
	CodecIDAVC                    = 7 // h264
	CodecIDReserved2              = 8
	CodecIDHEVC                   = 12 // 事实扩展标识 h265
)

E.4.3.1 VIDEODATA 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 / H264
13 = HEVC / H265
View Source
const (
	H2645PacketTypeSequenceHeader    = 0
	H2645PacketTypeNALU              = 1
	H2645PacketTypeSequenceHeaderEOF = 2
	H2645PacketTypeReserved          = 3
)

H2645PacketType IF CodecID == 7 or 12 UI8 The following values are defined:

0 = AVC sequence header
1 = AVC NALU
2 = AVC end of sequence (lower level NALU sequence ender is
    not required or supported)
View Source
const (
	ScriptOnMetaData = "onMetaData"
)

数据名称常量,如元数据

View Source
const (
	TagHeaderSize = 11
)

flv Tag Header Size, total is 11Byte.

filter + type 1Byte
data size 	3Byte
timestamp 	3Byte
timestampEx 1Byte
streamID 	3Byte always is 0

Variables

This section is empty.

Functions

func CodecIDName

func CodecIDName(codecID int32) string

CodecIDName 视频编解码器名称

func SoundFormatName

func SoundFormatName(codec int32) string

SoundFormatName 音频格式名称

Types

type AVCDecoderConfigurationRecord

type AVCDecoderConfigurationRecord struct {
	ConfigurationVersion byte
	AVCProfileIndication byte
	ProfileCompatibility byte
	AVCLevelIndication   byte
	SPS                  []byte
	PPS                  []byte
}
    bit(3) reserved = '111'b;
    unsigned int(5) numOfSequenceParameterSets;

    for (i=0; i< numOfSequenceParameterSets; i++) {
    	unsigned int(16) sequenceParameterSetLength ;
        bit(8*sequenceParameterSetLength) sequenceParameterSetNALUnit;
    }
    unsigned int(8) numOfPictureParameterSets;
    for (i=0; i< numOfPictureParameterSets; i++) {
    	unsigned int(16) pictureParameterSetLength;
    	bit(8*pictureParameterSetLength) pictureParameterSetNALUnit;
    }
}

func NewAVCDecoderConfigurationRecord

func NewAVCDecoderConfigurationRecord(sps, pps []byte) *AVCDecoderConfigurationRecord

NewAVCDecoderConfigurationRecord creates and initializes a new AVCDecoderConfigurationRecord

func (*AVCDecoderConfigurationRecord) Marshal

func (record *AVCDecoderConfigurationRecord) Marshal() ([]byte, error)

Marshal .

func (*AVCDecoderConfigurationRecord) MarshalSize

func (record *AVCDecoderConfigurationRecord) MarshalSize() int

MarshalSize .

func (*AVCDecoderConfigurationRecord) Unmarshal

func (record *AVCDecoderConfigurationRecord) Unmarshal(data []byte) error

Unmarshal . Note: Unmarshal not copy the data

type AudioData

type AudioData struct {
	SoundFormat   byte   // 4 bits; 音频编码格式
	SoundRate     byte   // 2 bits; 音频采样率
	SoundSize     byte   // 1 bits; 音频采用大小
	SoundType     byte   // 1 bits; 音频通道类型
	AACPacketType byte   // 8 bits; AAC 编码音频的包类型,仅但 SoundFormat 为 AAC 有效
	Body          []byte // 原始音频
}

AudioData flv Tag 中的的音频数据

对于 SoundFormat == SoundFormatAAC,Body 值: IF AACPacketType == AACPacketTypeSequenceHeader  AudioSpecificConfig 参考 AAC.RawSPS ELSE  Raw AAC frame data

func (*AudioData) Marshal

func (audioData *AudioData) Marshal() ([]byte, error)

Marshal .

func (*AudioData) MarshalSize

func (audioData *AudioData) MarshalSize() int

MarshalSize .

func (*AudioData) Unmarshal

func (audioData *AudioData) Unmarshal(data []byte) error

Unmarshal . Note: Unmarshal not copy the data

type HEVCDecoderConfigurationRecord added in v1.1.0

type HEVCDecoderConfigurationRecord struct {
	ConfigurationVersion uint8

	GeneralProfileSpace              uint8
	GeneralTierFlag                  uint8
	GeneralProfileIDC                uint8
	GeneralProfileCompatibilityFlags uint32
	GeneralConstraintIndicatorFlags  uint64
	GeneralLevelIDC                  uint8

	LengthSizeMinusOne uint8

	MaxSubLayers          uint8
	TemporalIdNestingFlag uint8

	ChromaFormatIDC      uint8
	BitDepthLumaMinus8   uint8
	BitDepthChromaMinus8 uint8

	VPS []byte
	SPS []byte
	PPS []byte
}

HEVCDecoderConfigurationRecord .

func NewHEVCDecoderConfigurationRecord added in v1.1.0

func NewHEVCDecoderConfigurationRecord(vps, sps, pps []byte) *HEVCDecoderConfigurationRecord

NewHEVCDecoderConfigurationRecord creates and initializes a new HEVCDecoderConfigurationRecord

func (*HEVCDecoderConfigurationRecord) Marshal added in v1.1.0

func (record *HEVCDecoderConfigurationRecord) Marshal() ([]byte, error)

Marshal .

func (*HEVCDecoderConfigurationRecord) MarshalSize added in v1.1.0

func (record *HEVCDecoderConfigurationRecord) MarshalSize() int

MarshalSize .

func (*HEVCDecoderConfigurationRecord) Unmarshal added in v1.1.0

func (record *HEVCDecoderConfigurationRecord) Unmarshal(data []byte) error

Unmarshal .

type Muxer added in v1.1.0

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

Muxer flv muxer from av.Frame(H264[+AAC])

func NewMuxer added in v1.1.0

func NewMuxer(videoMeta *codec.VideoMeta, audioMeta *codec.AudioMeta, tagWriter TagWriter, logger *xlog.Logger) (*Muxer, error)

NewMuxer .

func (*Muxer) Close added in v1.1.0

func (muxer *Muxer) Close() error

Close .

func (*Muxer) TypeFlags added in v1.1.0

func (muxer *Muxer) TypeFlags() byte

TypeFlags 返回 flv header 中的 TypeFlags

func (*Muxer) WriteFrame added in v1.1.0

func (muxer *Muxer) WriteFrame(frame *codec.Frame) error

WriteFrame .

type Packetizer added in v1.1.0

type Packetizer interface {
	PacketizeSequenceHeader() error
	Packetize(frame *codec.Frame) error
}

Packetizer 封包器

func NewAacPacketizer added in v1.1.0

func NewAacPacketizer(meta *codec.AudioMeta, tagWriter TagWriter) Packetizer

func NewH264Packetizer added in v1.1.0

func NewH264Packetizer(meta *codec.VideoMeta, tagWriter TagWriter) Packetizer

func NewH265Packetizer added in v1.1.0

func NewH265Packetizer(meta *codec.VideoMeta, tagWriter TagWriter) Packetizer

type Reader

type Reader struct {
	Header [FlvHeaderSize]byte // flv header
	// contains filtered or unexported fields
}

Reader flv Reader

func NewReader

func NewReader(r io.Reader) (*Reader, error)

NewReader .

func (*Reader) HasAudio

func (r *Reader) HasAudio() bool

HasAudio flv include audio stream.

func (*Reader) HasVideo

func (r *Reader) HasVideo() bool

HasVideo flv include video stream.

func (*Reader) ReadFlvTag

func (r *Reader) ReadFlvTag() (*Tag, error)

ReadFlvTag read flv tag

type ScriptData

type ScriptData struct {
	Name  string
	Value interface{}
}

ScriptData .

func (*ScriptData) Marshal

func (scriptData *ScriptData) Marshal() ([]byte, error)

Marshal .

func (*ScriptData) Unmarshal

func (scriptData *ScriptData) Unmarshal(data []byte) (err error)

Unmarshal .

type Tag

type Tag struct {
	Reserved  byte   // 2 bits; 用于 FMS 的保留字段值为 0
	Filter    byte   // 1 bits; 未加密文件中此值为 0,加密文件中此值为 1
	TagType   byte   // 5 bits
	DataSize  uint32 // 24 bits; Tag 中 Data 长度
	Timestamp uint32 // 24 bits(Timestamp) + 8 bits(TimestampExtended); 单位是毫秒的时间戳,FLV 文件中第一个 Tag 的 DTS 总为 0
	StreamID  uint32 // 24 bits; 总为 0
	Data      []byte // Tag 包含的数据
}

Tag FLV Tag

func (*Tag) IsAACSequenceHeader

func (tag *Tag) IsAACSequenceHeader() bool

IsAACSequenceHeader 判断是否是 AAC 序列头 Tag

func (*Tag) IsAudio

func (tag *Tag) IsAudio() bool

IsAudio 判断是否是音频 Tag

func (*Tag) IsH2645KeyFrame added in v1.1.0

func (tag *Tag) IsH2645KeyFrame() bool

IsH2645KeyFrame 判断是否是 H264/H265 关键帧 Tag

func (*Tag) IsH2645SequenceHeader added in v1.1.0

func (tag *Tag) IsH2645SequenceHeader() bool

IsH2645SequenceHeader 判断是否是 H264/H265 序列头 Tag

func (*Tag) IsMetadata

func (tag *Tag) IsMetadata() bool

IsMetadata 判断是否是元数据 tag

func (*Tag) IsVideo

func (tag *Tag) IsVideo() bool

IsVideo 判断是否是视频 Tag

func (*Tag) Read

func (tag *Tag) Read(r io.Reader) error

Read 根据规范的格式从 r 中读取 flv Tag。

func (*Tag) Size

func (tag *Tag) Size() int

Size tag 的总大小(包括 Header + Data)

func (*Tag) Write

func (tag *Tag) Write(w io.Writer) error

Write 根据规范将 flv Tag 输出到 w。

type TagData

type TagData interface {
	Marshal() ([]byte, error)
	Unmarshal(data []byte) error
}

TagData tag data

type TagWriter

type TagWriter interface {
	WriteFlvTag(tag *Tag) error
}

TagWriter 包装 WriteTag 方法的接口

type VideoData

type VideoData struct {
	FrameType       byte   // 4 bits; 帧类型
	CodecID         byte   // 4 bits; 编解码器标识
	H2645PacketType byte   // 8 bits; 仅 AVC/HEVC 编码有效,AVC 包类型
	CompositionTime uint32 // 24 bits; 仅 AVC/HEVC 编码有效,表示PTS 与 DTS 的时间偏移值,单位 ms,记作 CTS。
	Body            []byte // 原始视频
}

VideoData flv Tag 中的的视频数据

对于 CodecID == CodecIDAVC,Body 值: IF AVCPacketType == AVCPacketTypeSequenceHeader

AVCDecoderConfigurationRecord

ELSE  One or more NALUs (Full frames are required)

对于 CodecID == CodecIDAVC,Body 值: IF H2645PacketType == H2645PacketTypeSequenceHeader

AVCDecoderConfigurationRecord

ELSE  One or more NALUs (Full frames are required)

对于 CodecID == CodecIDHEVC,Body 值: IF H2645PacketType == H2645PacketTypeSequenceHeader

HEVCDecoderConfigurationRecord

ELSE  One or more NALUs (Full frames are required)

func (*VideoData) Marshal

func (videoData *VideoData) Marshal() ([]byte, error)

Marshal .

func (*VideoData) MarshalSize

func (videoData *VideoData) MarshalSize() int

MarshalSize .

func (*VideoData) Unmarshal

func (videoData *VideoData) Unmarshal(data []byte) error

Unmarshal . Note: Unmarshal not copy the data

type Writer

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

Writer flv Writer

func NewWriter

func NewWriter(w io.Writer, typeFlags byte) (*Writer, error)

NewWriter .

func (*Writer) WriteFlvTag

func (w *Writer) WriteFlvTag(tag *Tag) error

WriteFlvTag write flv tag

Jump to

Keyboard shortcuts

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