mirror of https://bitbucket.org/ausocean/av.git
stream/flv: write first previous tag size
This commit is contained in:
parent
7f07c4cb20
commit
9d70949e2e
|
@ -57,12 +57,11 @@ var (
|
||||||
type Encoder struct {
|
type Encoder struct {
|
||||||
dst io.Writer
|
dst io.Writer
|
||||||
|
|
||||||
fps int
|
fps int
|
||||||
audio bool
|
audio bool
|
||||||
video bool
|
video bool
|
||||||
lastTagSize int
|
header Header
|
||||||
header Header
|
start time.Time
|
||||||
start time.Time
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewEncoder retuns a new FLV encoder.
|
// NewEncoder retuns a new FLV encoder.
|
||||||
|
@ -193,6 +192,17 @@ func (s *frameScanner) readByte() (b byte, ok bool) {
|
||||||
func (e *Encoder) Encode(frame []byte) error {
|
func (e *Encoder) Encode(frame []byte) error {
|
||||||
var frameType byte
|
var frameType byte
|
||||||
var packetType byte
|
var packetType byte
|
||||||
|
if e.start.IsZero() {
|
||||||
|
// This is the first frame, so write the PreviousTagSize0.
|
||||||
|
//
|
||||||
|
// See https://download.macromedia.com/f4v/video_file_format_spec_v10_1.pdf
|
||||||
|
// section E.3.
|
||||||
|
var zero [4]byte
|
||||||
|
_, err := e.dst.Write(zero[:])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
timeStamp := e.getNextTimestamp()
|
timeStamp := e.getNextTimestamp()
|
||||||
// Do we have video to send off?
|
// Do we have video to send off?
|
||||||
if e.video {
|
if e.video {
|
||||||
|
|
|
@ -79,6 +79,8 @@ type Header struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Header) Bytes() []byte {
|
func (h *Header) Bytes() []byte {
|
||||||
|
// See https://download.macromedia.com/f4v/video_file_format_spec_v10_1.pdf
|
||||||
|
// section E.2.
|
||||||
const headerLength = 9
|
const headerLength = 9
|
||||||
b := [headerLength]byte{
|
b := [headerLength]byte{
|
||||||
0: 'F', 1: 'L', 2: 'V', 3: version,
|
0: 'F', 1: 'L', 2: 'V', 3: version,
|
||||||
|
|
Loading…
Reference in New Issue