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
|
||||
FramesPerClip int
|
||||
RtmpUrl string
|
||||
RtmpMethod uint8
|
||||
Bitrate string
|
||||
OutputFileName string
|
||||
InputFileName string
|
||||
|
@ -51,6 +52,7 @@ const (
|
|||
Ffmpeg = 11
|
||||
Revid = 12
|
||||
Flv = 13
|
||||
LibRtmp = 14
|
||||
)
|
||||
|
||||
// Default config settings
|
||||
|
@ -108,13 +110,6 @@ func (config *Config) Validate(r *revidInst) error {
|
|||
case Http:
|
||||
case File:
|
||||
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 == "" {
|
||||
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!")
|
||||
}
|
||||
|
||||
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 {
|
||||
case None:
|
||||
case Mpegts:
|
||||
|
|
|
@ -41,6 +41,7 @@ import (
|
|||
"os/exec"
|
||||
"strconv"
|
||||
"time"
|
||||
"rtmp"
|
||||
|
||||
//"bitbucket.org/ausocean/av/parser"
|
||||
//"bitbucket.org/ausocean/av/tsgenerator"
|
||||
|
@ -50,6 +51,7 @@ import (
|
|||
//"bitbucket.org/ausocean/av/ringbuffer"
|
||||
//"bitbucket.org/ausocean/utils/smartLogger"
|
||||
"../ringbuffer"
|
||||
"../rtmp"
|
||||
)
|
||||
|
||||
// Misc constants
|
||||
|
@ -108,6 +110,7 @@ type revidInst struct {
|
|||
getFrame func() []byte
|
||||
flushData func()
|
||||
sendClip func(clip []byte) error
|
||||
rtmpSession rtmp.RTMPSession
|
||||
}
|
||||
|
||||
// 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.setupOutput = r.setupOutputForFile
|
||||
case Rtmp:
|
||||
r.setupOutput = r.setupOutputForRtmp
|
||||
r.sendClip = r.sendClipToRtmp
|
||||
switch r.config.RtmpMethod {
|
||||
case Ffmpeg:
|
||||
r.setupOutput = r.setupOutputForFfmpegRtmp
|
||||
r.sendClip = r.sendClipToFfmpegRtmp
|
||||
case LibRtmp:
|
||||
r.setupOutput = r.setupOutputForLibRtmp
|
||||
r.sendClip = r.sendClipToLibRtmp
|
||||
}
|
||||
case Http:
|
||||
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
|
||||
// and packetising to a defined output.
|
||||
func (r *revidInst) sendClipToRtmp(clip []byte) error {
|
||||
func (r *revidInst) sendClipToFfmpegRtmp(clip []byte) error {
|
||||
fmt.Println("Outputting!")
|
||||
_, err := r.ffmpegStdin.Write(clip)
|
||||
if err != nil {
|
||||
|
@ -377,9 +386,13 @@ func (r *revidInst) sendClipToRtmp(clip []byte) error {
|
|||
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
|
||||
// and packetising to a defined output.
|
||||
func (r *revidInst) setupOutputForRtmp() error {
|
||||
func (r *revidInst) setupOutputForFfmpegRtmp() error {
|
||||
r.ffmpegCmd = exec.Command(ffmpegPath,
|
||||
"-f", "h264",
|
||||
"-r", r.config.FrameRate,
|
||||
|
@ -411,6 +424,11 @@ func (r *revidInst) setupOutputForRtmp() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (r *revidInst) setupOutputForLibRtmp() error {
|
||||
r.rtmpSession = NewRTMPSession(r.config.RtmpUrl, rtmpConnectionTimout)
|
||||
return rtmp.StartSession()
|
||||
}
|
||||
|
||||
func (r *revidInst) setupOutputForFile() (err error) {
|
||||
r.outputFile, err = os.Create(r.config.OutputFileName)
|
||||
return
|
||||
|
|
|
@ -144,3 +144,25 @@ func TestFlvOutputFile(t *testing.T) {
|
|||
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