Documentation
¶
Overview ¶
The oryx FLV package support bytes from/to FLV tags.
Index ¶
Examples ¶
Constants ¶
const ( // For FLV, only support 5, 11, 22, 44KHz sampling rate. AudioSamplingRate5kHz AudioSamplingRate = iota // 0 = 5.5 kHz AudioSamplingRate11kHz // 1 = 11 kHz AudioSamplingRate22kHz // 2 = 22 kHz AudioSamplingRate44kHz // 3 = 44 kHz // For Opus, support 8, 12, 16, 24, 48KHz // We will write a UINT8 sampling rate after FLV audio tag header. // @doc https://tools.ietf.org/html/rfc6716#section-2 AudioSamplingRateNB8kHz = 8 // NB (narrowband) AudioSamplingRateMB12kHz = 12 // MB (medium-band) AudioSamplingRateWB16kHz = 16 // WB (wideband) AudioSamplingRateSWB24kHz = 24 // SWB (super-wideband) AudioSamplingRateFB48kHz = 48 // FB (fullband) AudioSamplingRateForbidden )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AudioChannels ¶
type AudioChannels uint8
The audio channels, FLV named it the SoundType. Refer to @doc video_file_format_spec_v10.pdf, @page 77, @section E.4.2 Audio Tags
const ( AudioChannelsMono AudioChannels = iota // 0 = Mono sound AudioChannelsStereo // 1 = Stereo sound AudioChannelsForbidden )
func (*AudioChannels) From ¶
func (v *AudioChannels) From(a aac.Channels)
func (AudioChannels) String ¶
func (v AudioChannels) String() string
type AudioCodec ¶
type AudioCodec uint8
The audio codec id, FLV named it the SoundFormat. Refer to @doc video_file_format_spec_v10.pdf, @page 76, @section E.4.2 Audio Tags It's 4bits, that is 0-16.
const ( AudioCodecLinearPCM AudioCodec = iota // 0 = Linear PCM, platform endian AudioCodecADPCM // 1 = ADPCM AudioCodecMP3 // 2 = MP3 AudioCodecLinearPCMle // 3 = Linear PCM, little endian AudioCodecNellymoser16kHz // 4 = Nellymoser 16 kHz mono AudioCodecNellymoser8kHz // 5 = Nellymoser 8 kHz mono AudioCodecNellymoser // 6 = Nellymoser AudioCodecG711Alaw // 7 = G.711 A-law logarithmic PCM AudioCodecG711MuLaw // 8 = G.711 mu-law logarithmic PCM AudioCodecReserved // 9 = reserved AudioCodecAAC // 10 = AAC AudioCodecSpeex // 11 = Speex AudioCodecUndefined12 // For FLV, it's undefined, we define it as Opus for WebRTC. AudioCodecOpus // 13 = Opus AudioCodecMP3In8kHz // 14 = MP3 8 kHz AudioCodecDeviceSpecific // 15 = Device-specific sound AudioCodecForbidden )
func (AudioCodec) String ¶
func (v AudioCodec) String() string
type AudioFrame ¶
type AudioFrame struct {
SoundFormat AudioCodec
SoundRate AudioSamplingRate
SoundSize AudioSampleBits
SoundType AudioChannels
Trait AudioFrameTrait
AudioLevel uint16
Raw []byte
}
type AudioFrameTrait ¶
type AudioFrameTrait uint8
The Audio AAC frame trait, whether sequence header(ASC) or raw data. Refer to @doc video_file_format_spec_v10.pdf, @page 77, @section E.4.2 Audio Tags
const ( // For AAC, the frame trait. AudioFrameTraitSequenceHeader AudioFrameTrait = 0 // 0 = AAC sequence header AudioFrameTraitRaw AudioFrameTrait = 1 // 1 = AAC raw // For Opus, the frame trait, may has more than one traits. AudioFrameTraitOpusRaw AudioFrameTrait = 0x02 // 2, Has RAW Opus data. AudioFrameTraitOpusSamplingRate AudioFrameTrait = 0x04 // 4, Has Opus SamplingRate. AudioFrameTraitOpusAudioLevel AudioFrameTrait = 0x08 // 8, Has audio level data, 16bits. AudioFrameTraitForbidden AudioFrameTrait = 0xff )
func (AudioFrameTrait) String ¶
func (v AudioFrameTrait) String() string
type AudioPackager ¶
type AudioPackager interface {
// Encode the audio frame to FLV audio tag.
Encode(frame *AudioFrame) (tag []byte, err error)
// Decode the FLV audio tag to audio frame.
Decode(tag []byte) (frame *AudioFrame, err error)
}
The packager used to codec the FLV audio tag body. Refer to @doc video_file_format_spec_v10.pdf, @page 76, @section E.4.2 Audio Tags
func NewAudioPackager ¶
func NewAudioPackager() (AudioPackager, error)
type AudioSampleBits ¶
type AudioSampleBits uint8
The audio sample bits, FLV named it the SoundSize. Refer to @doc video_file_format_spec_v10.pdf, @page 76, @section E.4.2 Audio Tags
const ( AudioSampleBits8bits AudioSampleBits = iota // 0 = 8-bit samples AudioSampleBits16bits // 1 = 16-bit samples AudioSampleBitsForbidden )
func (AudioSampleBits) String ¶
func (v AudioSampleBits) String() string
type AudioSamplingRate ¶
type AudioSamplingRate uint8
The audio sampling rate, FLV named it the SoundRate. Refer to @doc video_file_format_spec_v10.pdf, @page 76, @section E.4.2 Audio Tags
func (*AudioSamplingRate) From ¶
func (v *AudioSamplingRate) From(a aac.SampleRateIndex)
For FLV, convert aac sample rate index to FLV sampling rate.
func (*AudioSamplingRate) OpusFrom ¶ added in v0.0.6
func (v *AudioSamplingRate) OpusFrom(a aac.SampleRateIndex)
For Opus, convert aac sample rate index to FLV sampling rate.
func (AudioSamplingRate) OpusToHz ¶ added in v0.0.6
func (v AudioSamplingRate) OpusToHz() int
Parse the Opus sampling rate to Hz.
func (AudioSamplingRate) String ¶
func (v AudioSamplingRate) String() string
func (AudioSamplingRate) ToHz ¶
func (v AudioSamplingRate) ToHz() int
Parse the FLV sampling rate to Hz.
type Demuxer ¶
type Demuxer interface {
// Read the FLV header, return the version of FLV, whether hasVideo or hasAudio in header.
ReadHeader() (version uint8, hasVideo, hasAudio bool, err error)
// Read the FLV tag header, return the tag information, especially the tag size,
// then user can read the tag payload.
ReadTagHeader() (tagType TagType, tagSize, timestamp uint32, err error)
// Read the FLV tag body, drop the next 4 bytes previous tag size.
ReadTag(tagSize uint32) (tag []byte, err error)
// Close the demuxer.
Close() error
}
FLV Demuxer is used to demux FLV file. Refer to @doc video_file_format_spec_v10.pdf, @page 74, @section Annex E. The FLV File Format A FLV file must consist the bellow parts:
- A FLV header, refer to @doc video_file_format_spec_v10.pdf, @page 8, @section The FLV header
- One or more tags, refer to @doc video_file_format_spec_v10.pdf, @page 9, @section FLV tags
@remark We always ignore the previous tag size.
Example ¶
package main
import (
"github.com/ossrs/go-oryx-lib/flv"
"io"
)
func main() {
// To open a flv file, or http flv stream.
var r io.Reader
var err error
var f flv.Demuxer
if f, err = flv.NewDemuxer(r); err != nil {
return
}
defer f.Close()
var version uint8
var hasVideo, hasAudio bool
if version, hasVideo, hasAudio, err = f.ReadHeader(); err != nil {
return
}
// Optional, user can check the header.
_ = version
_ = hasAudio
_ = hasVideo
var tagType flv.TagType
var tagSize, timestamp uint32
if tagType, tagSize, timestamp, err = f.ReadTagHeader(); err != nil {
return
}
var tag []byte
if tag, err = f.ReadTag(tagSize); err != nil {
return
}
// Using the FLV tag type, dts and body.
// Refer to @doc video_file_format_spec_v10.pdf, @page 9, @section FLV tags
_ = tagType
_ = timestamp
_ = tag
}
type Muxer ¶
type Muxer interface {
// Write the FLV header.
WriteHeader(hasVideo, hasAudio bool) (err error)
// Write A FLV tag.
WriteTag(tagType TagType, timestamp uint32, tag []byte) (err error)
// Close the muxer.
Close() error
}
The FLV muxer is used to write packet in FLV protocol. Refer to @doc video_file_format_spec_v10.pdf, @page 74, @section Annex E. The FLV File Format
Example ¶
package main
import (
"github.com/ossrs/go-oryx-lib/flv"
"io"
)
func main() {
// To open a flv file or http post stream.
var w io.Writer
var err error
var f flv.Muxer
if f, err = flv.NewMuxer(w); err != nil {
return
}
defer f.Close()
if err = f.WriteHeader(true, true); err != nil {
return
}
var tagType flv.TagType
var timestamp uint32
var tag []byte
// Get a FLV tag to write to muxer.
if err = f.WriteTag(tagType, timestamp, tag); err != nil {
return
}
}
type TagType ¶
type TagType uint8
FLV Tag Type is the type of tag, refer to @doc video_file_format_spec_v10.pdf, @page 9, @section FLV tags
type VideoCodec ¶
type VideoCodec uint8
The video codec id. Refer to @doc video_file_format_spec_v10.pdf, @page 78, @section E.4.3 Video Tags It's 4bits, that is 0-16.
const ( VideoCodecForbidden VideoCodec = iota + 1 VideoCodecH263 // 2 = Sorenson H.263 VideoCodecScreen // 3 = Screen video VideoCodecOn2VP6 // 4 = On2 VP6 VideoCodecOn2VP6Alpha // 5 = On2 VP6 with alpha channel VideoCodecScreen2 // 6 = Screen video version 2 VideoCodecAVC // 7 = AVC // See page 79 at @doc https://github.com/CDN-Union/H265/blob/master/Document/video_file_format_spec_v10_1_ksyun_20170615.doc VideoCodecHEVC VideoCodec = 12 // 12 = HEVC )
func (VideoCodec) String ¶
func (v VideoCodec) String() string
type VideoFrame ¶
type VideoFrame struct {
CodecID VideoCodec
FrameType VideoFrameType
Trait VideoFrameTrait
CTS int32
Raw []byte
}
func NewVideoFrame ¶ added in v0.0.4
func NewVideoFrame() *VideoFrame
type VideoFrameTrait ¶
type VideoFrameTrait uint8
The video AVC frame trait, whethere sequence header or not. Refer to @doc video_file_format_spec_v10.pdf, @page 78, @section E.4.3 Video Tags If AVC or HEVC, it's 8bits.
const ( VideoFrameTraitSequenceHeader VideoFrameTrait = iota // 0 = AVC/HEVC sequence header VideoFrameTraitNALU // 1 = AVC/HEVC NALU VideoFrameTraitSequenceEOF // 2 = AVC/HEVC end of sequence (lower level NALU sequence ender is VideoFrameTraitForbidden )
func (VideoFrameTrait) String ¶
func (v VideoFrameTrait) String() string
type VideoFrameType ¶
type VideoFrameType uint8
The video frame type. Refer to @doc video_file_format_spec_v10.pdf, @page 78, @section E.4.3 Video Tags
const ( VideoFrameTypeForbidden VideoFrameType = iota VideoFrameTypeKeyframe // 1 = key frame (for AVC, a seekable frame) VideoFrameTypeInterframe // 2 = inter frame (for AVC, a non-seekable frame) VideoFrameTypeDisposable // 3 = disposable inter frame (H.263 only) VideoFrameTypeGenerated // 4 = generated key frame (reserved for server use only) VideoFrameTypeInfo // 5 = video info/command frame )
func (VideoFrameType) String ¶
func (v VideoFrameType) String() string
type VideoPackager ¶
type VideoPackager interface {
// Decode the FLV video tag to video frame.
// @remark For RTMP/FLV: pts = dts + cts, where dts is timestamp in packet/tag.
Decode(tag []byte) (frame *VideoFrame, err error)
// Encode the video frame to FLV video tag.
Encode(frame *VideoFrame) (tag []byte, err error)
}
The packager used to codec the FLV video tag body. Refer to @doc video_file_format_spec_v10.pdf, @page 78, @section E.4.3 Video Tags
func NewVideoPackager ¶
func NewVideoPackager() (VideoPackager, error)