mirror of https://bitbucket.org/ausocean/av.git
Ready for debugging tomorrow
This commit is contained in:
parent
a9df7b7adc
commit
a276809ec9
|
@ -21,6 +21,7 @@ type Config struct {
|
||||||
RtmpEncodingMethod uint8
|
RtmpEncodingMethod uint8
|
||||||
FramesPerClip int
|
FramesPerClip int
|
||||||
RtmpUrl string
|
RtmpUrl string
|
||||||
|
RtmpMethod uint8
|
||||||
Bitrate string
|
Bitrate string
|
||||||
OutputFileName string
|
OutputFileName string
|
||||||
InputFileName string
|
InputFileName string
|
||||||
|
@ -51,6 +52,7 @@ const (
|
||||||
Ffmpeg = 11
|
Ffmpeg = 11
|
||||||
Revid = 12
|
Revid = 12
|
||||||
Flv = 13
|
Flv = 13
|
||||||
|
LibRtmp = 14
|
||||||
)
|
)
|
||||||
|
|
||||||
// Default config settings
|
// Default config settings
|
||||||
|
@ -108,13 +110,6 @@ func (config *Config) Validate(r *revidInst) error {
|
||||||
case Http:
|
case Http:
|
||||||
case File:
|
case File:
|
||||||
case Rtmp:
|
case Rtmp:
|
||||||
switch config.RtmpEncodingMethod {
|
|
||||||
case Revid:
|
|
||||||
case Ffmpeg:
|
|
||||||
case NothingDefined:
|
|
||||||
r.Log(Warning, "No RTMP encoding method defined, defautling to ffmpeg!")
|
|
||||||
config.RtmpEncodingMethod = Ffmpeg
|
|
||||||
}
|
|
||||||
if config.RtmpUrl == "" {
|
if config.RtmpUrl == "" {
|
||||||
return errors.New("Bad RTMP URL")
|
return errors.New("Bad RTMP URL")
|
||||||
}
|
}
|
||||||
|
@ -125,6 +120,16 @@ func (config *Config) Validate(r *revidInst) error {
|
||||||
return errors.New("Bad output type defined in config!")
|
return errors.New("Bad output type defined in config!")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch config.RtmpMethod {
|
||||||
|
case LibRtmp:
|
||||||
|
case Ffmpeg:
|
||||||
|
case NothingDefined:
|
||||||
|
r.Log(Warning, "No RTMP encoding method defined, defautling to ffmpeg!")
|
||||||
|
config.RtmpEncodingMethod = Ffmpeg
|
||||||
|
default:
|
||||||
|
return errors.New("Bad rtmp method defined in config!")
|
||||||
|
}
|
||||||
|
|
||||||
switch config.Packetization {
|
switch config.Packetization {
|
||||||
case None:
|
case None:
|
||||||
case Mpegts:
|
case Mpegts:
|
||||||
|
|
|
@ -41,6 +41,7 @@ import (
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
"rtmp"
|
||||||
|
|
||||||
//"bitbucket.org/ausocean/av/parser"
|
//"bitbucket.org/ausocean/av/parser"
|
||||||
//"bitbucket.org/ausocean/av/tsgenerator"
|
//"bitbucket.org/ausocean/av/tsgenerator"
|
||||||
|
@ -50,6 +51,7 @@ import (
|
||||||
//"bitbucket.org/ausocean/av/ringbuffer"
|
//"bitbucket.org/ausocean/av/ringbuffer"
|
||||||
//"bitbucket.org/ausocean/utils/smartLogger"
|
//"bitbucket.org/ausocean/utils/smartLogger"
|
||||||
"../ringbuffer"
|
"../ringbuffer"
|
||||||
|
"../rtmp"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Misc constants
|
// Misc constants
|
||||||
|
@ -108,6 +110,7 @@ type revidInst struct {
|
||||||
getFrame func() []byte
|
getFrame func() []byte
|
||||||
flushData func()
|
flushData func()
|
||||||
sendClip func(clip []byte) error
|
sendClip func(clip []byte) error
|
||||||
|
rtmpSession rtmp.RTMPSession
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewRevidInstance returns a pointer to a new revidInst with the desired
|
// NewRevidInstance returns a pointer to a new revidInst with the desired
|
||||||
|
@ -147,8 +150,14 @@ func (r *revidInst) ChangeState(config Config) error {
|
||||||
r.sendClip = r.sendClipToFile
|
r.sendClip = r.sendClipToFile
|
||||||
r.setupOutput = r.setupOutputForFile
|
r.setupOutput = r.setupOutputForFile
|
||||||
case Rtmp:
|
case Rtmp:
|
||||||
r.setupOutput = r.setupOutputForRtmp
|
switch r.config.RtmpMethod {
|
||||||
r.sendClip = r.sendClipToRtmp
|
case Ffmpeg:
|
||||||
|
r.setupOutput = r.setupOutputForFfmpegRtmp
|
||||||
|
r.sendClip = r.sendClipToFfmpegRtmp
|
||||||
|
case LibRtmp:
|
||||||
|
r.setupOutput = r.setupOutputForLibRtmp
|
||||||
|
r.sendClip = r.sendClipToLibRtmp
|
||||||
|
}
|
||||||
case Http:
|
case Http:
|
||||||
r.sendClip = r.sendClipToHTTP
|
r.sendClip = r.sendClipToHTTP
|
||||||
}
|
}
|
||||||
|
@ -368,7 +377,7 @@ func (r *revidInst) sendClipToHTTP(clip []byte) error {
|
||||||
|
|
||||||
// Start invokes a revidInst to start processing video from a defined input
|
// Start invokes a revidInst to start processing video from a defined input
|
||||||
// and packetising to a defined output.
|
// and packetising to a defined output.
|
||||||
func (r *revidInst) sendClipToRtmp(clip []byte) error {
|
func (r *revidInst) sendClipToFfmpegRtmp(clip []byte) error {
|
||||||
fmt.Println("Outputting!")
|
fmt.Println("Outputting!")
|
||||||
_, err := r.ffmpegStdin.Write(clip)
|
_, err := r.ffmpegStdin.Write(clip)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -377,9 +386,13 @@ func (r *revidInst) sendClipToRtmp(clip []byte) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *revidInst) sendClipToLibRtmp(clip []byte) error {
|
||||||
|
return r.rtmpSession.WriteFrame(clip,len(clip))
|
||||||
|
}
|
||||||
|
|
||||||
// Start invokes a revidInst to start processing video from a defined input
|
// Start invokes a revidInst to start processing video from a defined input
|
||||||
// and packetising to a defined output.
|
// and packetising to a defined output.
|
||||||
func (r *revidInst) setupOutputForRtmp() error {
|
func (r *revidInst) setupOutputForFfmpegRtmp() error {
|
||||||
r.ffmpegCmd = exec.Command(ffmpegPath,
|
r.ffmpegCmd = exec.Command(ffmpegPath,
|
||||||
"-f", "h264",
|
"-f", "h264",
|
||||||
"-r", r.config.FrameRate,
|
"-r", r.config.FrameRate,
|
||||||
|
@ -411,6 +424,11 @@ func (r *revidInst) setupOutputForRtmp() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *revidInst) setupOutputForLibRtmp() error {
|
||||||
|
r.rtmpSession = NewRTMPSession(r.config.RtmpUrl, rtmpConnectionTimout)
|
||||||
|
return rtmp.StartSession()
|
||||||
|
}
|
||||||
|
|
||||||
func (r *revidInst) setupOutputForFile() (err error) {
|
func (r *revidInst) setupOutputForFile() (err error) {
|
||||||
r.outputFile, err = os.Create(r.config.OutputFileName)
|
r.outputFile, err = os.Create(r.config.OutputFileName)
|
||||||
return
|
return
|
||||||
|
|
|
@ -144,3 +144,25 @@ func TestFlvOutputFile(t *testing.T) {
|
||||||
revidInst.Stop()
|
revidInst.Stop()
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// Test h264 inputfile to flv format into rtmp using librtmp c wrapper
|
||||||
|
func TestRtmpOutputUsingLibRtmp(t *testing.T){
|
||||||
|
config := Config{
|
||||||
|
Input: File,
|
||||||
|
InputFileName: "testInput.h264",
|
||||||
|
InputCodec: H264,
|
||||||
|
Output: Rtmp,
|
||||||
|
RtmpMethod: LibRtmp,
|
||||||
|
RtmpUrl: "",
|
||||||
|
Packetization: Flv,
|
||||||
|
FrameRate: "25",
|
||||||
|
}
|
||||||
|
revidInst, err := NewRevidInstance(config)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Should not of have got an error!: %v\n", err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
revidInst.Start()
|
||||||
|
time.Sleep(30*time.Second)
|
||||||
|
revidInst.Stop()
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue