aws / amazon-kinesis-video-streams-parser-library

Amazon Kinesis Video Streams parser library is for developers to include in their applications that makes it easy to work with the output of video streams such as retrieving frame-level objects, metadata for fragments, and more.
Apache License 2.0
102 stars 52 forks source link

Not able to convert frames to images where video resolution is 1604x992px #107

Closed divyaJainPhilips closed 4 years ago

divyaJainPhilips commented 4 years ago

I have multiple video sources putting data into KVS. At consumer side reading the stream and converting frames to images. this works fine when my video resolution is 1920x1080px but for the videos of resolution 1604x992px when i am trying to create the images from frames the images are distorted.

Code snippet to convert frames to images final int pixelWidth = trackMetadata.getPixelWidth().get().intValue(); final int pixelHeight = trackMetadata.getPixelHeight().get().intValue();

                    final Picture rgb = Picture.create(pixelWidth, pixelHeight, ColorSpace.RGB);
                    final BufferedImage renderImage = new BufferedImage(pixelWidth, pixelHeight,
                            BufferedImage.TYPE_3BYTE_BGR);
                    final AvcCBox avcC = AvcCBox
                            .parseAvcCBox(ByteBuffer.wrap(trackMetadata.getCodecPrivateData().array()));
                    decoder.addSps(avcC.getSpsList());
                    decoder.addPps(avcC.getPpsList());

                    final Picture buf = Picture.create(pixelWidth + ((16 - (pixelWidth % 16)) % 16),pixelHeight + ((16 - (pixelHeight % 16)) % 16), ColorSpace.YUV420J);
                    final List<ByteBuffer> byteBuffers = splitMOVPacket(frameBuffer, avcC);
                    final Picture pic = decoder.decodeFrameFromNals(byteBuffers, buf.getData());

                    if (pic != null) {
                        final byte[][] dataTemp = new byte[3][pic.getData().length];
                        dataTemp[0] = pic.getPlaneData(0);
                        dataTemp[1] = pic.getPlaneData(2);
                        dataTemp[2] = pic.getPlaneData(1);

                        final Picture tmpBuf = Picture.createPicture(pixelWidth, pixelHeight, dataTemp,ColorSpace.YUV420J);
                        transform.transform(tmpBuf, rgb);
                        AWTUtil.toBufferedImage(rgb, renderImage);
lherman-cs commented 4 years ago

@divyaJainPhilips do you mind to share the decoded pic's resolution? If the resolution is correct, 1604x992px, I'm afraid the problem is related to your JCodec image transformation logics. In this case, https://github.com/jcodec/jcodec would be more appropriate for your question.

lherman-cs commented 4 years ago

Since there's not enough information and the question is related to JCodec, I'll mark this as resolved. Please feel free to reopen it for further assistance!