package main import ( "flag" "fmt" "os" "time" "github.com/zhangpeihao/goflv" rtmp "github.com/zhangpeihao/gortmp" "github.com/zhangpeihao/log" ) const ( programName = "RtmpPublisher" version = "0.0.1" ) var ( url *string = flag.String("URL", "rtmp://video-center.alivecdn.com/AppName/StreamName?vhost=live.gz-app.com", "The rtmp url to connect.") streamName *string = flag.String("Stream", "camstream", "Stream name to play.") flvFileName *string = flag.String("FLV", "./v_4097.flv", "FLV file to publishs.") ) var obConn rtmp.OutboundConn var createStreamChan chan rtmp.OutboundStream var videoDataSize int64 var audioDataSize int64 var flvFile *flv.File var status uint func publish(stream rtmp.OutboundStream) { startTs := uint32(0) startAt := time.Now().UnixNano() preTs := uint32(0) for status == rtmp.OUTBOUND_CONN_STATUS_CREATE_STREAM_OK { fmt.Printf("@@@@@@@@@@@@@@diff1 header(%+v), startTs: %d\n", header, startTs) if err = stream.PublishData(header.TagType, data, diff1); err != nil { fmt.Println("PublishData() error:", err) break } } } func main() { createStreamChan = make(chan rtmp.OutboundStream) testHandler := &TestOutboundConnHandler{} fmt.Println("to dial") fmt.Println("a") var err error obConn, err = rtmp.Dial(*url, testHandler, 100) if err != nil { fmt.Println("Dial error", err) os.Exit(-1) } fmt.Println("b") defer obConn.Close() fmt.Println("to connect") err = obConn.Connect() if err != nil { fmt.Printf("Connect error: %s", err.Error()) os.Exit(-1) } fmt.Println("c") for { select { case stream := <-createStreamChan: // Publish stream.Attach(testHandler) err = stream.Publish(*streamName, "live") if err != nil { fmt.Printf("Publish error: %s", err.Error()) os.Exit(-1) } case <-time.After(1 * time.Second): fmt.Printf("Audio size: %d bytes; Vedio size: %d bytes\n", audioDataSize, videoDataSize) } } }