fix conversion of AV1/VP9 tracks from HLS/RTMP to RTSP (#2263)

This commit is contained in:
Alessandro Ros 2023-08-29 19:52:39 +02:00 committed by GitHub
parent 8e955d2119
commit bd1cb35022
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 83 additions and 6 deletions

View File

@ -79,8 +79,10 @@ func (s *hlsSource) run(ctx context.Context, cnf *conf.PathConf, reloadConf chan
switch tcodec := track.Codec.(type) {
case *codecs.AV1:
medi = &description.Media{
Type: description.MediaTypeVideo,
Formats: []format.Format{&format.AV1{}},
Type: description.MediaTypeVideo,
Formats: []format.Format{&format.AV1{
PayloadTyp: 96,
}},
}
c.OnDataAV1(track, func(pts time.Duration, tu [][]byte) {
@ -95,8 +97,10 @@ func (s *hlsSource) run(ctx context.Context, cnf *conf.PathConf, reloadConf chan
case *codecs.VP9:
medi = &description.Media{
Type: description.MediaTypeVideo,
Formats: []format.Format{&format.VP9{}},
Type: description.MediaTypeVideo,
Formats: []format.Format{&format.VP9{
PayloadTyp: 96,
}},
}
c.OnDataVP9(track, func(pts time.Duration, frame []byte) {

View File

@ -42,6 +42,7 @@ func newAV1(
func (t *formatProcessorAV1) createEncoder() error {
t.encoder = &rtpav1.Encoder{
PayloadMaxSize: t.udpMaxPayloadSize - 12,
PayloadType: t.format.PayloadTyp,
}
return t.encoder.Init()
}

View File

@ -252,7 +252,9 @@ func tracksFromMetadata(conn *Conn, payload []interface{}) (format.Format, forma
return nil, nil, fmt.Errorf("invalid AV1 configuration: %v", err)
}
videoTrack = &format.AV1{}
videoTrack = &format.AV1{
PayloadTyp: 96,
}
default: // VP9
var vpcc mp4.VpcC
@ -261,7 +263,9 @@ func tracksFromMetadata(conn *Conn, payload []interface{}) (format.Format, forma
return nil, nil, fmt.Errorf("invalid VP9 configuration: %v", err)
}
videoTrack = &format.VP9{}
videoTrack = &format.VP9{
PayloadTyp: 96,
}
}
}

View File

@ -242,6 +242,13 @@ func TestReadTracks(t *testing.T) {
},
nil,
},
{
"ffmpeg av1",
&format.AV1{
PayloadTyp: 96,
},
nil,
},
} {
t.Run(ca.name, func(t *testing.T) {
var buf bytes.Buffer
@ -680,6 +687,67 @@ func TestReadTracks(t *testing.T) {
Config: buf.Bytes(),
})
require.NoError(t, err)
case "ffmpeg av1":
err := mrw.Write(&message.DataAMF0{
ChunkStreamID: 4,
MessageStreamID: 1,
Payload: []interface{}{
"@setDataFrame",
"onMetaData",
flvio.AMFMap{
{
K: "duration",
V: float64(0),
},
{
K: "width",
V: float64(1920),
},
{
K: "height",
V: float64(1080),
},
{
K: "videodatarate",
V: float64(0),
},
{
K: "framerate",
V: float64(30),
},
{
K: "videocodecid",
V: float64(message.FourCCAV1),
},
{
K: "encoder",
V: "Lavf60.10.101",
},
{
K: "filesize",
V: float64(0),
},
},
},
})
require.NoError(t, err)
var buf bytes.Buffer
_, err = mp4.Marshal(&buf, hvcc, mp4.Context{})
require.NoError(t, err)
err = mrw.Write(&message.ExtendedSequenceStart{
ChunkStreamID: 6,
MessageStreamID: 0x1000000,
FourCC: message.FourCCAV1,
Config: []byte{
0x81, 0x08, 0x0c, 0x00, 0x0a, 0x0b, 0x00, 0x00,
0x00, 0x42, 0xab, 0xbf, 0xc3, 0x70, 0x0b, 0xe0,
0x01,
},
})
require.NoError(t, err)
}
c := newNoHandshakeConn(&buf)