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 {
|
||||
dst io.Writer
|
||||
|
||||
fps int
|
||||
audio bool
|
||||
video bool
|
||||
lastTagSize int
|
||||
header Header
|
||||
start time.Time
|
||||
fps int
|
||||
audio bool
|
||||
video bool
|
||||
header Header
|
||||
start time.Time
|
||||
}
|
||||
|
||||
// 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 {
|
||||
var frameType 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()
|
||||
// Do we have video to send off?
|
||||
if e.video {
|
||||
|
|
|
@ -79,6 +79,8 @@ type Header struct {
|
|||
}
|
||||
|
||||
func (h *Header) Bytes() []byte {
|
||||
// See https://download.macromedia.com/f4v/video_file_format_spec_v10_1.pdf
|
||||
// section E.2.
|
||||
const headerLength = 9
|
||||
b := [headerLength]byte{
|
||||
0: 'F', 1: 'L', 2: 'V', 3: version,
|
||||
|
|
Loading…
Reference in New Issue