How can I apply chromakey to data coming from an RTMP packet and add another video to the transparent area?
Can you please help? I can't find any resources
for {
// Rtmp stream read packet
pkt, err := c.ReadPacket()
switch pkt.Type {
case av.H264:
naluSize := binary.BigEndian.Uint32(pkt.Data[:4])
img := pkt.Data[4+naluSize:]
//????
newImg := image.NewRGBA(img.Bounds())
backgroundColor, _ := colorful.Hex("#72971E") // yeşil renk
usingPix(img, *newImg, backgroundColor)
}
}
To apply to the frame;
func usingPix(img image.Image, newImg image.RGBA, targetColor colorful.Color) {
bounds := img.Bounds()
width, height := bounds.Max.X, bounds.Max.Y
rgba := image.NewRGBA(bounds)
draw.Draw(rgba, bounds, img, bounds.Min, draw.Src)
for y := 0; y < height; y++ {
for x := 0; x < width; x++ {
index := (y*width + x) * 4
pix := rgba.Pix[index : index+4]
clr := color.RGBA{pix[0], pix[1], pix[2], 255}
clra,_ := colorful.MakeColor(clr)
a := targetColor.DistanceCIE94(clra)
if a < 0.11{
newImg.Set(x, y, color.RGBA{0, 0, 0, 0})
} else {
newImg.Set(x, y, clr)
}
}
}
}
How can I apply chromakey to data coming from an RTMP packet and add another video to the transparent area? Can you please help? I can't find any resources
To apply to the frame;