2018-02-27 18:10:38 +03:00
|
|
|
/*
|
|
|
|
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"
|
2018-02-12 10:58:29 +03:00
|
|
|
"fmt"
|
2018-02-10 16:25:55 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2018-02-11 09:06:59 +03:00
|
|
|
headerLength = 72
|
|
|
|
version = 0x01
|
|
|
|
maxVideoTagSize = 10000
|
|
|
|
maxAudioTagSize = 10000
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2018-02-27 18:10:38 +03:00
|
|
|
VideoTagType = 9
|
|
|
|
AudioTagType = 8
|
|
|
|
KeyFrameType = 1
|
|
|
|
InterFrameType = 2
|
|
|
|
H264 = 7
|
|
|
|
AVCNALU = 1
|
|
|
|
SequenceHeader = 0
|
|
|
|
DataHeaderLength = 5
|
2018-02-12 16:31:19 +03:00
|
|
|
NoTimestampExtension = 0
|
2018-02-27 18:10:38 +03:00
|
|
|
AACAudioFormat = 10
|
|
|
|
PCMAudioFormat = 0
|
2018-02-10 16:25:55 +03:00
|
|
|
)
|
|
|
|
|
2018-02-27 18:10:38 +03:00
|
|
|
var flvHeaderCode = []byte{0x46, 0x4C, 0x56}
|
|
|
|
|
2018-02-10 16:25:55 +03:00
|
|
|
type Header struct {
|
2018-02-11 09:06:59 +03:00
|
|
|
AudioFlag bool
|
|
|
|
VideoFlag bool
|
2018-02-10 16:25:55 +03:00
|
|
|
}
|
|
|
|
|
2018-02-27 18:10:38 +03:00
|
|
|
func btb(b bool) byte {
|
|
|
|
return tools.BoolToByte(b)
|
|
|
|
}
|
|
|
|
|
2018-02-12 10:58:29 +03:00
|
|
|
func (h *Header) ToByteSlice() (output []byte) {
|
2018-02-11 09:06:59 +03:00
|
|
|
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{
|
2018-02-11 09:06:59 +03:00
|
|
|
version,
|
2018-02-27 18:10:38 +03:00
|
|
|
0x00 | btb(h.AudioFlag)<<2 | btb(h.VideoFlag),
|
2018-02-12 10:58:29 +03:00
|
|
|
0x00, 0x00, 0x00, byte(9),
|
2018-02-11 09:06:59 +03:00
|
|
|
}...)
|
2018-02-12 10:58:29 +03:00
|
|
|
fmt.Println(output)
|
2018-02-11 09:06:59 +03:00
|
|
|
return
|
2018-02-10 16:25:55 +03:00
|
|
|
}
|