bvibber / yuv-canvas

JS class to draw YUV image frame buffers to an HTML5 canvas
MIT License
273 stars 60 forks source link

some green shadow appear in the canvas。look at the pic #26

Closed numberwolf closed 4 years ago

numberwolf commented 4 years ago

here , see some green near the eggs image

if i use yuv-canvas, will have problem (this). if only canvas, no problem.

heres my code: pic format: yuv420p

 var format = YUVBuffer.format({
        width: width,
        height: height,
        chromaWidth: width/2,
        chromaHeight: height/2,
        displayWidth: width,
        displayHeight: height
    });
    var frame = YUVBuffer.frame(format);

    frame.y.bytes = imageBufferY;
    frame.u.bytes = imageBufferB;
    frame.v.bytes = imageBufferR;
bvibber commented 4 years ago

It looks like there's an offset on the chroma buffers maybe? Double-check that the buffers are aligned correctly, and check if there's a stride parameter for the planes that might be different from the widths or anything like that.

numberwolf commented 4 years ago

execuse me, i have add the stride value, But it didn't change.

i have put it online , address: http://hevc.aivideo.video

it has large frame size , and seems to play ok. no green shadow appeared.

so i think ,It's a matter of size ?
bvibber commented 4 years ago

In your code it looks like you're extracting the three planes from your WebAssembly memory assuming that they all run up against each other and that the width and stride are identical for each plane.

The visual output with the sample file that is having trouble looks to me like the buffer is offset by a few pixels. I don't think it's the stride as it's a constant offset; I think it may be the alignment of the buffers themselves...

Looking at the contents of the buffers on your demo they appear to be offset by about 8 bytes for the U and 16 bytes for the V plane, and the bytes appearing at the beginning of them look suspiciously like they encode a buffer length. Are they three separate allocations which just happen to be next to each other, or is there additional data encoded between them in your C structures?

numberwolf commented 4 years ago

You are right.

The reason was that I forgot to calculate the ptr size which in C structures , i add the ptr size and no problem now.

Thank you ,very much!
I can fall asleep now~~