Giter Site home page Giter Site logo

Comments (9)

baSSiLL avatar baSSiLL commented on June 1, 2024

Hi
It's not apparent from the image how it should look like normally. But as soon as vertical lines don't get inclined I suppose there's a constant shift in bitmap data. Probably, a wrong start of bitmap data is specified.
What is the source of frames? How do you pass frames to SharpAvi? Which encoder do you use?

from sharpavi.

stevehjohn avatar stevehjohn commented on June 1, 2024

Hi,

Thanks for responding. The bitmaps are captured from the screen with the following code:

https://github.com/stevehjohn/AoC/blob/a4bbe7321ff5b22fae0c65c936288eed8ad9dc00/AoC.Visualisations/Infrastructure/VisualisationBase.cs#L84

To test, I added some debug code to save the bitmap. When I opened it in Paint.Net, it looked correct.

You can see the video here: https://youtu.be/eAzu7xScquA?t=83
From about 1:20 there is a stream of water that should be at the very right hand edge of the frame, but as you can see, it is wrapped around to the left.

Thanks,

Steve.

from sharpavi.

baSSiLL avatar baSSiLL commented on June 1, 2024

I see. You should not save a bitmap to the BMP format before passing to SharpAvi. This way the array you pass to WriteFrame contains not only raw pixel data but also a few excess bytes in the beginning coming from the BMP header. Hence the shift in pixels.
Take a look to a similar code in the sample app.

var bits = bitmap.LockBits(new Rectangle(0, 0, screenWidth, screenHeight), ImageLockMode.ReadOnly, PixelFormat.Format32bppRgb);

You just call LockBits' to get a pointer to a Bitmap's pixel data. And then you can either copy it to an array, a MemoryStreamor other managed memory. Or use unsafe code and create aSpandirectly from the pointer which you can then pass toWriteFrame`.

var bits = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
var span = new Span<byte>(bits.Scan0.ToPointer(), bits.Stride * bits.Height);
videoStream.WriteFrame(true, span);
bitmap.UnlockBits(bits);

from sharpavi.

stevehjohn avatar stevehjohn commented on June 1, 2024

Hi,

That seems to have fixed the alignment issue. However the AVI is now upside-down.

Thanks,

Steve.

from sharpavi.

baSSiLL avatar baSSiLL commented on June 1, 2024

You use an uncompressed video stream without an encoder, it expects pixel data in the bottom-up direction. It worked with the BMP format because it also stores pixels in the bottom-up direction. While the Bitmap class stores its data in the top-down direction.
You can turn to UncompressedVideoEncoder which expects top-down data and performs the necessary vertical flipping under the hood. Note that you'll also need to change the bitmap format to PixelFormat.Format32bppRgb as all encoders in SharpAvi expect pixel data in this format.

from sharpavi.

stevehjohn avatar stevehjohn commented on June 1, 2024

Perfect, that all works now.

Thank-you for your help with this issue. I presume my original issue was caused by header information that is added when saving a bitmap?

Thanks,

Steve.

from sharpavi.

baSSiLL avatar baSSiLL commented on June 1, 2024

I presume my original issue was caused by header information that is added when saving a bitmap?

Correct

from sharpavi.

stevehjohn avatar stevehjohn commented on June 1, 2024

Cool.

Once again, thanks for your help with this!

Steve.

from sharpavi.

stevehjohn avatar stevehjohn commented on June 1, 2024

Appreciate your help, gave you a shout out here: https://www.outsidecontextproblem.com/threading.html

Cheers,

Steve.

from sharpavi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.