Comments (5)
Hi,
This project hasn't been worked on for a few years now due to the Pi Foundation moving away from MMAL in favour of libcamera. However if you're still using this library, I'd recommend looking at the wiki for more information as I spent a long time making that area comprehensive.
What resolution are you taking images in? If you're not configuring this, it'll be defaulting to 1280x720 which will be rather large. Regarding quality, I would like to say that if you set the quality
against a MMALPortConfig
instance that it would have an impact on quality as it's essentially MJPEG - but I can't remember if this has an impact for rapid still capture, sorry.
Regarding the MMALNullSinkComponent, this is necessary for calculating exposure compensation, please see here for info.
Thanks,
Ian
from mmalsharp.
Wow, I didn't expect to get an answer that fast for a project that hasn't been worked on for a few years. Thanks again!
Since Libcamera is probably not for C#, I am not interested in it ;) So far I am quite happy with your Lib.
This is my Code:
public async Task TakePictureFromVideoPort()
{
try
{
MMALCamera cam = MMALCamera.Instance;
MMALCameraConfig.VideoResolution = new Resolution(640, 400);
MMALCameraConfig.VideoFramerate = new MMAL_RATIONAL_T(40, 1);
using (var myCaptureHandler = new MyInMemoryCaptureHandler())
using (var splitter = new MMALSplitterComponent())
using (var imgEncoder = new MMALImageEncoder(continuousCapture: true))
{
cam.ConfigureCameraSettings();
var portConfig = new MMALPortConfig(MMALEncoding.JPEG, MMALEncoding.I420, 10);
imgEncoder.ConfigureOutputPort(portConfig, myCaptureHandler);
cam.Camera.VideoPort.ConnectTo(splitter);
splitter.Outputs[0].ConnectTo(imgEncoder);
await Task.Delay(2000);
await cam.ProcessAsync(cam.Camera.VideoPort);
}
cam.Cleanup();
}
catch (Exception e)
{
Console.WriteLine("Error in Camera.TakePictureFromVideoPort(): " + e.Message);
}
}
public class MyInMemoryCaptureHandler : InMemoryCaptureHandler
{
public override void Process(ImageContext context)
{
try
{
base.Process(context);
if (context.Eos)
{
byte[] data = base.WorkingData.ToArray();
this.WorkingData.Clear();
Net.SendJPEG(data);
// This works for lowering the quality, but it is far too slow (2fps) and the size is not less^^
//using (MemoryStream stream = new MemoryStream(data))
//{
// Image image = Image.Load(data);
// image.SaveAsJpeg(stream, new JpegEncoder() { Quality = 50 });
// Net.SendJPEG(stream.ToArray());
// image.Dispose();
//}
//Console.WriteLine("Framesize: " + data.Length);
}
}
catch (Exception e)
{
Console.WriteLine("Error in Camera.Process() : " + e.Message);
}
}
}
from mmalsharp.
No problem, I've enjoyed my time supporting this library over the years but as to its future, I'm unsure due to my previous statement.
If you're looking to further reduce the overall size of your images, you could potentially look to using a different pixel format which has a lower bit depth per pixel. At the moment you're using I420 (YUV420) as defined against your MMALPortConfig
which is a 16 bit format; what you could do is look at using something like YV12 or NV12 which are 12 bit, or YUV10COL which is a 10 bit format - I cannot guarantee that these will work, but apart from lowering your resolution more I'm unsure what more you can do to reduce the overall size of your images when in rapid capture mode unfortunately.
A list of the pixel formats available in MMALSharp can be found here and search for EncodingType.PixelFormat
- have a play with some and see what they do.
Out of interest, what filesize are the images when you store them?
from mmalsharp.
To use only 10bit for colors is actually a really nice idea. This reminds me of the old days when I set my computer's screen colors to 8bit so that the games ran more smoothly ;)
But unfortunately that doesn't seem to work. Because YUV10COL is strangely not available under MMALEncoding. YV12 and NV12 is there but it makes no difference. It probably doesn't matter what value I enter as PixelDecoding, the size doesn't change.
Right now I have 70kbyte per image. With 40fps I have about 22mbit/s at the moment. This is too much. I could also just create an h.264 stream using v4l2rtspserver, but if the connection is bad, the rtsp player always stops.
If I just send the JPEGs over with your lib, that's no problem, and the latency is much better (100ms)
from mmalsharp.
Ah I see, I did have my suspicions the pixel format change may not work, the native library can seemingly accept a change for certain operations but not actually honour this. Can you not lower the requested FPS to a lower value to achieve your goal?
from mmalsharp.
Related Issues (20)
- TakePicture not setting ImageContext resolution HOT 4
- Bitmap.Save writes a raw RGB array as BGR HOT 4
- Unnecessary file output to post-process still captures
- Add user provided name to MMALPortConfig
- Allow user provided buffer number and size for camera ports HOT 1
- Setting ShutterSpeed not taking HOT 5
- Raw ImageContext output and padded resolutions HOT 1
- StereoMode not being set HOT 1
- Default motion detection example for v0.6 throws "Unhandled exception. System.TypeInitializationException: The type initializer for 'Gdip' threw an exception." HOT 10
- How to set camera number to capture from HOT 3
- MMALCamera.ProcessAsync sometimes hangs indefinitely HOT 7
- Question: LineDetection in Video HOT 3
- Capturing still image to memory stream no longer working HOT 2
- Camera warmup time question HOT 5
- Investigate use of ArrayPool to reduce allocations
- MMALSharp not working with new Raspbian GNU/Linux 11 (bullseye) OS HOT 4
- MMAP gives exception when initialising camera HOT 1
- Howto change PreviewPort after cam.Camera.PreviewPort.ConnectTo(video)
- MMALCameraConfig.IntraPeriod not working?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mmalsharp.