question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BufferOverflowException with random pixel colors

See original GitHub issue

JCodec version: most recent commit (790187004ba801a98743a52fb40e02b8a22be712)

Minimal (non)working example:

import java.io.File;
import java.io.IOException;
import java.util.Random;

import org.jcodec.api.SequenceEncoder8Bit;
import org.jcodec.common.model.ColorSpace;
import org.jcodec.common.model.Picture8Bit;


public class CrashTest
{
    public static void main(String[] args) throws IOException
    {
        final SequenceEncoder8Bit seqEncoder = SequenceEncoder8Bit
                .createSequenceEncoder8Bit(new File("out.mp4"), 30);

        final Picture8Bit pic = Picture8Bit.create(1920, 1080, ColorSpace.RGB);

        byte[] picData = pic.getPlaneData(0);
        new Random().nextBytes(picData);

        seqEncoder.encodeNativeFrame(pic);

        seqEncoder.finish();
    }
}

Which results in:

Exception in thread "main" java.nio.BufferOverflowException
	at java.nio.Buffer.nextPutIndex(Buffer.java:521)
	at java.nio.HeapByteBuffer.put(HeapByteBuffer.java:169)
	at org.jcodec.common.io.BitWriter.putInt(BitWriter.java:43)
	at org.jcodec.common.io.BitWriter.writeNBit(BitWriter.java:66)
	at org.jcodec.codecs.h264.io.CAVLC.writeLevels(CAVLC.java:125)
	at org.jcodec.codecs.h264.io.CAVLC.writeBlockGen(CAVLC.java:100)
	at org.jcodec.codecs.h264.io.CAVLC.writeACBlock(CAVLC.java:52)
	at org.jcodec.codecs.h264.encode.MBEncoderI16x16.writeAC(MBEncoderI16x16.java:157)
	at org.jcodec.codecs.h264.encode.MBEncoderI16x16.chromaResidual(MBEncoderI16x16.java:88)
	at org.jcodec.codecs.h264.encode.MBEncoderI16x16.chroma(MBEncoderI16x16.java:69)
	at org.jcodec.codecs.h264.encode.MBEncoderI16x16.encodeMacroblock(MBEncoderI16x16.java:49)
	at org.jcodec.codecs.h264.H264Encoder.encodeMacroblock(H264Encoder.java:295)
	at org.jcodec.codecs.h264.H264Encoder.encodeSlice(H264Encoder.java:276)
	at org.jcodec.codecs.h264.H264Encoder.doEncodeFrame8Bit(H264Encoder.java:167)
	at org.jcodec.codecs.h264.H264Encoder.encodeFrame8Bit(H264Encoder.java:103)
	at org.jcodec.api.SequenceEncoder8Bit.encodeNativeFrame(SequenceEncoder8Bit.java:101)
	at CrashTest.main(CrashTest.java:22)

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:19 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
svitvitskiycommented, Jan 16, 2018

Fixed in cfcc80f1744f6f43033eb8a99ffa64d832a3ce5d

1reaction
dpeGitcommented, Apr 6, 2017

I managed to fix the problem. https://github.com/jcodec/jcodec/blob/master/src/main/java/org/jcodec/codecs/h264/H264Encoder.java#L241 I increased the buffer size by a factor of four works just fine now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Colorize all pixels of div with random colors. Javascript allowed
The solution can be broken down in the following steps: Allow passing explicit colors for specific areas in the target element; Generate random...
Read more >
Color | Android Developers
The Color class provides methods for creating, converting and manipulating colors. Colors have three different representations: Color ints, the most common ...
Read more >
BufferedImage (Java Platform SE 8 ) - Oracle Help Center
Represents an image with 8-bit RGBA color components with the colors Blue, ... Returns an integer pixel in the default RGB color model...
Read more >
Strange vertical lines with random pixel colours - iFixit
Not good ;-{. You have proved the issue is within the GPU logic. I'm suspecting the VRAM chips need replacing. If you have...
Read more >
Graphics2D (Java Platform SE 6)
Coordinates in device space usually refer to individual device pixels and ... The Graphics class defines only the setColor method to control the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found