Add support rawvideo format

This commit is contained in:
Alex X
2024-05-25 08:22:38 +03:00
parent 8749562c96
commit f8bc25d0ae
7 changed files with 248 additions and 3 deletions
+21
View File
@@ -3,6 +3,10 @@ package mjpeg
import (
"bytes"
"image/jpeg"
"github.com/AlexxIT/go2rtc/pkg/core"
"github.com/AlexxIT/go2rtc/pkg/y4m"
"github.com/pion/rtp"
)
// FixJPEG - reencode JPEG if it has wrong header
@@ -33,3 +37,20 @@ func FixJPEG(b []byte) []byte {
}
return buf.Bytes()
}
func Encoder(codec *core.Codec, handler core.HandlerFunc) core.HandlerFunc {
newImage := y4m.NewImage(codec.FmtpLine)
return func(packet *rtp.Packet) {
img := newImage(packet.Payload)
buf := bytes.NewBuffer(nil)
if err := jpeg.Encode(buf, img, nil); err != nil {
return
}
clone := *packet
clone.Payload = buf.Bytes()
handler(&clone)
}
}