-
Notifications
You must be signed in to change notification settings - Fork 549
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support zerocopy from MMAL camera to video encoding #487
Comments
Is this like the pass through #124 and substream #123 enhancements that we already have listed but instead doing it for MMAL? If there is a concern on the framerate and resolution, has the bcm module been evaluated to determine whether it provides better performance? e.g. |
This is not pass-through recording nor sub-stream processing. It is also not simply MMAL providing better performance than bcm2835-v4l2. This is how the zerocopy setup looks like: I have been testing various setup that uses h264_omx encoder on all models of Raspberry Pis, and the bottleneck on all of them is the memory bandwidth (from copying frames everywhere). This zerocopy feature aims to eliminate the bottleneck, thus giving big performance improvement. |
The concern on this would be that it would be very platform centric. While there are many PI users, I don't believe that the majority of them would be able to use the feature since it couldn't be packaged. (See issue on Stretch and the MMAL camera). So the only users would be those that have the knowledge to build the application which isn't where I was wanting to move the application to. I was really trying to push the project to be a "packaged" application rather than a "build from source" application. Now with that said, there is some room for negotiation. If the changes are benefiting all platforms, or are consolidated and isolated into a separate module, then we can evaluate it. However if the changes would be putting #IFs into a large number of modules/functions, then I'm not sure that it is really suited for the project. |
I had a quick look at the motion source code to see how much change is needed. Basically, these are the changes required:
The main motivation of zerocopy feature is to benefit MotionEyeOS users. Having said all that, I haven't proven that this zerocopy chain will work. I was having issues with zerocopy, reported as issue #433 and raspberrypi/firmware#851. |
This is way too difficult to get working properly. It requires a lot of code changes in motion to handle the buffers. After all that, it still locks up with certain versions of kernel. When it doesn't lock up, it works great, but encoding pauses for 2 seconds after every 20 seconds. |
Hi, currently working a little to use RPI HW encoder but instead of using the h264_omx, I'm going to use MMAL directly (like raspivid does). Using the prefered codec you've added, I think the following changes will work:
This result in the following buffer pipe: MMAL raw frames (stored in GPU/ARM shared memory) ---> motion (motion detection & draw text & timestamp on the frame in shared memory) ---> h264_mmal (encodes the edited frame without copying the frame into GPU memory) -> ffmpeg_put_image (using copy codec) Change will be limited in ffmpeg.c. What do you think of it? |
Sorry, this is a very late comment, but the bugs is still present in RPI for h264_omx prefered_codec (I've just checked and still deadlock). |
@dfgweb I have implemented the zero copy version some time ago, and I had to make significant changes to motion for zero copy to work. From memory, these are the changes I did:
Essentially, motion has to receive this image buffer from mmalcam, pass it along to motion's image ring buffer (used for motion detection & pre-capture), and pass it to ffmpeg(h264_omx) for encoding, and when ffmpeg is done with the image, release the image buffer back to MMAL pool. You can replace ffmpeg part by calling MMAL directly to encode, but you still need to do all the proper image buffer handling. I did a quick hack as a proof of concept, and it was more trouble than it's worth for various reasons:
I gave up at that point because it wasn't worth it. If you want to look at my hack, you can find it here: https://github.com/jasaw/motion/tree/support-mmal-zerocopy |
The idea is to take the frames from MMAL camera, process them in motion, and pass the processed frames to the encoder, all without copying the frame, i.e. zerocopy. Zerocopy will greatly improve the maximum resolution and framerate a system can handle, and will also reduce memory usage.
The text was updated successfully, but these errors were encountered: