mirror of https://bitbucket.org/ausocean/av.git
Still trying
This commit is contained in:
parent
a38b86236c
commit
182cfeef88
|
@ -19,6 +19,7 @@ const (
|
||||||
InterFrameType = 2
|
InterFrameType = 2
|
||||||
H264 = 7
|
H264 = 7
|
||||||
AVCNALU = 1
|
AVCNALU = 1
|
||||||
|
SequenceHeader = 0
|
||||||
DataHeaderLength = 5
|
DataHeaderLength = 5
|
||||||
NoTimestampExtension = 0
|
NoTimestampExtension = 0
|
||||||
AACAudioFormat = 10
|
AACAudioFormat = 10
|
||||||
|
|
|
@ -91,12 +91,80 @@ func (g *flvGenerator) ResetTimestamp() {
|
||||||
g.currentTimestamp = 0
|
g.currentTimestamp = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isKeyFrame(frame []byte) bool {
|
||||||
|
byteChannel := make(chan byte, len(frame))
|
||||||
|
for i := range frame {
|
||||||
|
byteChannel <- frame[i]
|
||||||
|
}
|
||||||
|
for len(byteChannel) >= 5{
|
||||||
|
aByte := <-byteChannel
|
||||||
|
for i:=1; aByte == 0x00 && i != 4; i++ {
|
||||||
|
aByte = <-byteChannel
|
||||||
|
if ( aByte == 0x01 && i == 2 ) || ( aByte == 0x01 && i == 3 ) {
|
||||||
|
aByte = <-byteChannel
|
||||||
|
nalType := aByte & 0x1F
|
||||||
|
switch nalType {
|
||||||
|
case 1:
|
||||||
|
return false
|
||||||
|
case 5:
|
||||||
|
return true
|
||||||
|
case 6:
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func isSequenceHeader(frame []byte) bool {
|
||||||
|
byteChannel := make(chan byte, len(frame))
|
||||||
|
for i := range frame {
|
||||||
|
byteChannel <- frame[i]
|
||||||
|
}
|
||||||
|
for len(byteChannel) >= 5{
|
||||||
|
aByte := <-byteChannel
|
||||||
|
for i:=1; aByte == 0x00 && i != 4; i++ {
|
||||||
|
aByte = <-byteChannel
|
||||||
|
if ( aByte == 0x01 && i == 2 ) || ( aByte == 0x01 && i == 3 ) {
|
||||||
|
aByte = <-byteChannel
|
||||||
|
nalType := aByte & 0x1F
|
||||||
|
switch nalType {
|
||||||
|
case 1:
|
||||||
|
return false
|
||||||
|
case 5:
|
||||||
|
return false
|
||||||
|
case 6:
|
||||||
|
return true
|
||||||
|
case 7:
|
||||||
|
return true
|
||||||
|
case 8:
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func (g *flvGenerator) generate() {
|
func (g *flvGenerator) generate() {
|
||||||
g.GenHeader()
|
g.GenHeader()
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case videoFrame := <-g.inputChan:
|
case videoFrame := <-g.inputChan:
|
||||||
nalType :=
|
var frameType byte
|
||||||
|
if isKeyFrame(videoFrame) {
|
||||||
|
frameType = flv.KeyFrameType
|
||||||
|
} else {
|
||||||
|
frameType = flv.InterFrameType
|
||||||
|
}
|
||||||
|
var packetType byte
|
||||||
|
if isSequenceHeader(videoFrame){
|
||||||
|
packetType = flv.SequenceHeader
|
||||||
|
} else {
|
||||||
|
packetType = flv.AVCNALU
|
||||||
|
|
||||||
|
}
|
||||||
timeStamp := g.getNextTimestamp()
|
timeStamp := g.getNextTimestamp()
|
||||||
videoTag := flv.VideoTag{
|
videoTag := flv.VideoTag{
|
||||||
PrevTagSize: uint32(g.lastTagSize),
|
PrevTagSize: uint32(g.lastTagSize),
|
||||||
|
@ -104,9 +172,9 @@ func (g *flvGenerator) generate() {
|
||||||
DataSize: uint32(len(videoFrame)) + flv.DataHeaderLength,
|
DataSize: uint32(len(videoFrame)) + flv.DataHeaderLength,
|
||||||
Timestamp: timeStamp,
|
Timestamp: timeStamp,
|
||||||
TimestampExtended: flv.NoTimestampExtension,
|
TimestampExtended: flv.NoTimestampExtension,
|
||||||
FrameType: flv.InterFrameType,
|
FrameType: frameType,
|
||||||
Codec: flv.H264,
|
Codec: flv.H264,
|
||||||
PacketType: flv.AVCNALU,
|
PacketType: packetType,
|
||||||
CompositionTime: 0,
|
CompositionTime: 0,
|
||||||
Data: videoFrame,
|
Data: videoFrame,
|
||||||
}
|
}
|
||||||
|
@ -125,20 +193,20 @@ func (g *flvGenerator) generate() {
|
||||||
audioTag := flv.AudioTag{
|
audioTag := flv.AudioTag{
|
||||||
PrevTagSize: uint32(g.lastTagSize),
|
PrevTagSize: uint32(g.lastTagSize),
|
||||||
TagType: uint8(flv.AudioTagType),
|
TagType: uint8(flv.AudioTagType),
|
||||||
DataSize: 1 + 10,
|
DataSize: 7,
|
||||||
Timestamp: timeStamp,
|
Timestamp: timeStamp,
|
||||||
TimestampExtended: flv.NoTimestampExtension,
|
TimestampExtended: flv.NoTimestampExtension,
|
||||||
SoundFormat: flv.AACAudioFormat,
|
SoundFormat: flv.AACAudioFormat,
|
||||||
SoundRate: 0,
|
SoundRate: 3,
|
||||||
SoundSize: false,
|
SoundSize: true,
|
||||||
SoundType: false,
|
SoundType: true,
|
||||||
Data: soundData,
|
Data: []byte{0x00,0x12,0x08,0x56,0xe5,0x00},
|
||||||
}
|
}
|
||||||
audioTagAsByteSlice := audioTag.ToByteSlice()
|
audioTagAsByteSlice := audioTag.ToByteSlice()
|
||||||
g.lastTagSize = len(audioTagAsByteSlice)
|
g.lastTagSize = len(audioTagAsByteSlice)
|
||||||
g.outputChan<-audioTagAsByteSlice
|
g.outputChan<-audioTagAsByteSlice
|
||||||
|
|
||||||
time.Sleep(40*time.Millisecond)
|
time.Sleep(60*time.Millisecond)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,30 @@
|
||||||
|
/*
|
||||||
|
NAME
|
||||||
|
RtpToTsConverter.go - provides utilities for the conversion of Rtp packets
|
||||||
|
to equivalent MpegTs packets.
|
||||||
|
|
||||||
|
DESCRIPTION
|
||||||
|
See Readme.md
|
||||||
|
|
||||||
|
AUTHOR
|
||||||
|
Saxon Nelson-Milton <saxon.milton@gmail.com>
|
||||||
|
|
||||||
|
LICENSE
|
||||||
|
RtpToTsConverter.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).
|
||||||
|
*/
|
||||||
package parser
|
package parser
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -62,7 +89,7 @@ func (p *h264Parser)parse() {
|
||||||
}
|
}
|
||||||
aByte = <-p.inputChan
|
aByte = <-p.inputChan
|
||||||
outputBuffer = append(outputBuffer, aByte)
|
outputBuffer = append(outputBuffer, aByte)
|
||||||
if nalType := aByte & 0x1F; nalType == 1 || nalType == 5 {
|
if nalType := aByte & 0x1F; nalType == 1 || nalType == 5 || nalType == 8{
|
||||||
searchingForEnd = true
|
searchingForEnd = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -127,10 +127,10 @@ func TestRtmpOutput(t *testing.T){
|
||||||
func TestFlvOutputFile(t *testing.T) {
|
func TestFlvOutputFile(t *testing.T) {
|
||||||
config := Config{
|
config := Config{
|
||||||
Input: File,
|
Input: File,
|
||||||
InputFileName: "testInput.h264",
|
InputFileName: "betterInput.h264",
|
||||||
InputCodec: H264,
|
InputCodec: H264,
|
||||||
Output: File,
|
Output: File,
|
||||||
OutputFileName: "pls.flv",
|
OutputFileName: "saxonOut.flv",
|
||||||
Packetization: Flv,
|
Packetization: Flv,
|
||||||
FrameRate: "25",
|
FrameRate: "25",
|
||||||
}
|
}
|
||||||
|
@ -147,11 +147,12 @@ func TestFlvOutputFile(t *testing.T) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Test h264 inputfile to flv format into rtmp using librtmp c wrapper
|
// Test h264 inputfile to flv format into rtmp using librtmp c wrapper
|
||||||
func TestRtmpOutputUsingLibRtmp(t *testing.T){
|
func TestRtmpOutputUsingLibRtmp(t *testing.T){
|
||||||
config := Config{
|
config := Config{
|
||||||
Input: File,
|
Input: File,
|
||||||
InputFileName: "testInput.h264",
|
InputFileName: "betterInput.h264",
|
||||||
InputCodec: H264,
|
InputCodec: H264,
|
||||||
Output: Rtmp,
|
Output: Rtmp,
|
||||||
RtmpMethod: LibRtmp,
|
RtmpMethod: LibRtmp,
|
||||||
|
|
Binary file not shown.
BIN
rtmp/rtmpTesting
BIN
rtmp/rtmpTesting
Binary file not shown.
|
@ -10,7 +10,7 @@ package rtmp
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
const (
|
const (
|
||||||
inputFile = "pls.flv"
|
inputFile = "saxonOut.flv"
|
||||||
outputUrl = "rtmp://a.rtmp.youtube.com/live2/w44c-mkuu-aezg-ceb1"
|
outputUrl = "rtmp://a.rtmp.youtube.com/live2/w44c-mkuu-aezg-ceb1"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
BIN
rtmp/sample.flv
BIN
rtmp/sample.flv
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue