av/flv/FLV.go

79 lines
1.7 KiB
Go
Raw Normal View History

/*
NAME
FLV.go
DESCRIPTION
See Readme.md
AUTHORS
Saxon A. Nelson-Milton <saxon@ausocean.org>
LICENSE
FLV.go is Copyright (C) 2017 the Australian Ocean Lab (AusOcean)
It is free software: you can redistribute it and/or modify them
under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
It is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with revid in gpl.txt. If not, see [GNU licenses](http://www.gnu.org/licenses).
*/
2018-02-10 16:25:55 +03:00
package flv
import (
2018-03-13 08:15:42 +03:00
"bitbucket.org/ausocean/av/tools"
//"../tools"
"fmt"
2018-02-10 16:25:55 +03:00
)
const (
headerLength = 72
version = 0x01
maxVideoTagSize = 10000
maxAudioTagSize = 10000
)
const (
VideoTagType = 9
AudioTagType = 8
KeyFrameType = 1
InterFrameType = 2
H264 = 7
AVCNALU = 1
SequenceHeader = 0
DataHeaderLength = 5
NoTimestampExtension = 0
AACAudioFormat = 10
PCMAudioFormat = 0
2018-02-10 16:25:55 +03:00
)
var flvHeaderCode = []byte{0x46, 0x4C, 0x56}
2018-02-10 16:25:55 +03:00
type Header struct {
AudioFlag bool
VideoFlag bool
2018-02-10 16:25:55 +03:00
}
func btb(b bool) byte {
return tools.BoolToByte(b)
}
func (h *Header) ToByteSlice() (output []byte) {
output = make([]byte, 0, headerLength)
2018-03-13 07:33:31 +03:00
output = append(output, flvHeaderCode...)
2018-03-14 04:18:03 +03:00
output = append(output, []byte{
version,
0x00 | btb(h.AudioFlag)<<2 | btb(h.VideoFlag),
0x00, 0x00, 0x00, byte(9),
}...)
fmt.Println(output)
return
2018-02-10 16:25:55 +03:00
}