forked from deepch/vdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
muxer.go
59 lines (52 loc) · 1.01 KB
/
muxer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package nvr
import (
"log"
"os"
"time"
"github.com/ogsts/vdk/av"
)
type Muxer struct {
name string
patch string
started bool
file *os.File
codec []av.CodecData
buffer []*av.Packet
bufferDur time.Duration
seqDur time.Duration
}
//NewMuxer func
func NewMuxer(codec []av.CodecData, name, patch string, seqDur time.Duration) *Muxer {
return &Muxer{
codec: codec,
name: name,
patch: patch,
seqDur: seqDur,
}
}
//WritePacket func
func (obj *Muxer) CodecUpdate(val []av.CodecData) {
obj.codec = val
}
//WritePacket func
func (obj *Muxer) WritePacket(pkt *av.Packet) (err error) {
if !obj.started && pkt.IsKeyFrame {
obj.started = true
}
if obj.started {
if pkt.IsKeyFrame && obj.bufferDur >= obj.seqDur {
log.Println("write to drive", len(obj.buffer), obj.bufferDur)
obj.buffer = nil
obj.bufferDur = 0
}
obj.buffer = append(obj.buffer, pkt)
if pkt.Idx == 0 {
obj.bufferDur += pkt.Duration
}
}
return nil
}
//Close func
func (obj *Muxer) Close() {
return
}