zhangpeihao / gortmp

Implement RTMP protocol by golang
MIT License
523 stars 162 forks source link

How to publish MetaData(eg: subtitle) with each video frame? #39

Closed falconray0704 closed 7 years ago

falconray0704 commented 7 years ago

Hi, I publish one text string after each video frame use message type id 18 (0x13) for AMF3 encoding, but make the stream closed. And I have tried message type id 15 (0x0f) for AMF0 encoding, it made the stream closed too.

the codes i make in demo/publisher as following:

    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
    }
    if header.TagType == flv.VIDEO_TAG {
        subTitleHeader := *header
        subTitleHeader.TagType = byte(0x13)
        subTitle := fmt.Sprintf("+++ video frame Timestamp:%d +++\n", subTitleHeader.Timestamp)
        subTitleData := make([]byte, len(subTitle)+1)
        subTitleHeader.DataSize = uint32(len(subTitle))
        copy(subTitleData, subTitle[:])
        subTitleData[len(subTitle)] = 0x00
            if err = stream.PublishData(subTitleHeader.TagType, subTitleData, diff1); err != nil {
                fmt.Println("PublishData() subtitle error:", err)
                break
            }
    }

The error logs I got: ray@TF:/md/gows/src/github.com/falconray0704/gortmp/demo/publisher$ ./rtmp_publisher -URL "rtmp://10.1.51.20:1935/myapp/" -Stream cv -FLV "/md/videos/aWalkToUnionSquare.flv" to dial a b to connect c @@@@@@@@@@@@@status: 3, err: ReceviedRtmpCommand: &{IsFlex:false Name:_result TransactionID:1 Objects:[map[fmsVer:FMS/3,0,1,123 capabilities:31] map[level:status code:NetConnection.Connect.Success description:Connection succeeded. objectEncoding:0]]} @@@@@@@@@@@@@status: 5, err: Stream created: 1 ReceviedRtmpCommand: &{IsFlex:false Name:_result TransactionID:2 Objects:[ 1]} 1 2 3 @@@@@@@@@@@@@@diff1 header(&{TagType:18 DataSize:372 Timestamp:0}), startTs: 0 @@@@@@@@@@@@@@diff1 header(&{TagType:18 DataSize:372 Timestamp:0}), startTs: 0 @@@@@@@@@@@@@@diff1 header(&{TagType:8 DataSize:418 Timestamp:0}), startTs: 0 @@@@@@@@@@@@@@diff1 header(&{TagType:8 DataSize:418 Timestamp:0}), startTs: 0 @@@@@@@@@@@@@@diff1 header(&{TagType:9 DataSize:180804 Timestamp:25}), startTs: 25 @@@@@@@@@@@@@@diff1 header(&{TagType:9 DataSize:180804 Timestamp:25}), startTs: 25 @@@@@@@@@@@@@@diff1 header(&{TagType:8 DataSize:419 Timestamp:26}), startTs: 25 @@@@@@@@@@@@@@diff1 header(&{TagType:8 DataSize:419 Timestamp:52}), startTs: 25 @@@@@@@@@@@@@@diff1 header(&{TagType:9 DataSize:216201 Timestamp:59}), startTs: 25 @@@@@@@@@@@@@@diff1 header(&{TagType:8 DataSize:419 Timestamp:78}), startTs: 25 @@@@@@@@@@@@@@diff1 header(&{TagType:9 DataSize:64624 Timestamp:94}), startTs: 25 @@@@@@@@@@@@@@diff1 header(&{TagType:8 DataSize:419 Timestamp:104}), startTs: 25 @@@@@@@@@@@@@@diff1 header(&{TagType:9 DataSize:43542 Timestamp:128}), startTs: 25 @@@@@@@@@@@@@status: 0, err: @@@@@@@@@@@@@Closed Audio size: 2094 bytes; Vedio size: 505171 bytes Audio size: 2094 bytes; Vedio size: 505171 bytes ^C ray@TF:/md/gows/src/github.com/falconray0704/gortmp/demo/publisher$

Actually I want to streaming subtitle for each video frame with the same timestamp.
Which way could I make it?

Thanks.

zhangpeihao commented 6 years ago

Do not support subtitle now.