-
Notifications
You must be signed in to change notification settings - Fork 5
/
publisher.go
51 lines (47 loc) · 1.06 KB
/
publisher.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
package recordplugin
import (
"errors"
"io"
"os"
"path/filepath"
"time"
. "github.com/Monibuca/engine"
"github.com/Monibuca/engine/avformat"
)
type FlvFile struct {
InputStream
}
func PublishFlvFile(streamPath string) error {
if file, err := os.Open(filepath.Join(config.Path, streamPath+".flv")); err == nil {
stream := FlvFile{}
if stream.Publish(streamPath, &stream) {
defer stream.Close()
stream.UseTimestamp = true
file.Seek(int64(len(avformat.FLVHeader)), io.SeekStart)
var lastTime uint32
for {
if tag, err := avformat.ReadFLVTag(file); err == nil {
switch tag.Type {
case avformat.FLV_TAG_TYPE_AUDIO:
stream.PushAudio(tag)
case avformat.FLV_TAG_TYPE_VIDEO:
if tag.Timestamp != 0 {
if lastTime == 0 {
lastTime = tag.Timestamp
}
}
stream.PushVideo(tag)
time.Sleep(time.Duration(tag.Timestamp-lastTime) * time.Millisecond)
lastTime = tag.Timestamp
}
} else {
return err
}
}
} else {
return errors.New("Bad Name")
}
} else {
return err
}
}