mirror of https://github.com/q191201771/lal.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
84 lines
1.7 KiB
Go
84 lines
1.7 KiB
Go
5 years ago
|
// Copyright 2020, Chef. All rights reserved.
|
||
|
// https://github.com/q191201771/lal
|
||
|
//
|
||
|
// Use of this source code is governed by a MIT-style license
|
||
|
// that can be found in the License file.
|
||
|
//
|
||
|
// Author: Chef (191201771@qq.com)
|
||
|
|
||
|
package rtmp
|
||
|
|
||
|
import (
|
||
|
"bytes"
|
||
|
|
||
|
"github.com/q191201771/lal/pkg/base"
|
||
|
)
|
||
|
|
||
|
// TODO chef: 见ServerSession::doDataMessageAMF0
|
||
|
func ParseMetadata(b []byte) (ObjectPairArray, error) {
|
||
|
_, l, err := AMF0.ReadString(b)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
opa, _, err := AMF0.ReadObjectOrArray(b[l:])
|
||
|
return opa, err
|
||
|
}
|
||
|
|
||
|
// spec-video_file_format_spec_v10.pdf
|
||
|
// onMetaData
|
||
|
// - duration DOUBLE, seconds
|
||
|
// - width DOUBLE
|
||
|
// - height DOUBLE
|
||
|
// - videodatarate DOUBLE
|
||
|
// - framerate DOUBLE
|
||
|
// - videocodecid DOUBLE
|
||
|
// - audiosamplerate DOUBLE
|
||
|
// - audiosamplesize DOUBLE
|
||
|
// - stereo BOOL
|
||
|
// - audiocodecid DOUBLE
|
||
|
// - filesize DOUBLE, bytes
|
||
|
//
|
||
|
// - encoder
|
||
|
// - server
|
||
|
// - author
|
||
|
// - version
|
||
|
//
|
||
|
// @param audiocodecid AAC 10
|
||
|
// @param videocodecid AVC 7
|
||
|
//
|
||
|
func BuildMetadata(width int, height int, audiocodecid int, videocodecid int) ([]byte, error) {
|
||
|
buf := &bytes.Buffer{}
|
||
|
if err := AMF0.WriteString(buf, "onMetaData"); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
var opa ObjectPairArray
|
||
|
opa = append(opa, ObjectPair{
|
||
|
Key: "width",
|
||
|
Value: width,
|
||
|
})
|
||
|
opa = append(opa, ObjectPair{
|
||
|
Key: "height",
|
||
|
Value: height,
|
||
|
})
|
||
|
opa = append(opa, ObjectPair{
|
||
|
Key: "audiocodecid",
|
||
|
Value: audiocodecid,
|
||
|
})
|
||
|
opa = append(opa, ObjectPair{
|
||
|
Key: "videocodecid",
|
||
|
Value: videocodecid,
|
||
|
})
|
||
|
|
||
|
opa = append(opa, ObjectPair{
|
||
|
Key: "version",
|
||
|
Value: base.LALFullInfo,
|
||
|
})
|
||
|
|
||
|
if err := AMF0.WriteObject(buf, opa); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
return buf.Bytes(), nil
|
||
|
}
|