{"id":15197071,"url":"https://github.com/t-moe/rpi_mmal_examples","last_synced_at":"2025-10-28T07:30:37.459Z","repository":{"id":91176341,"uuid":"150073538","full_name":"t-moe/rpi_mmal_examples","owner":"t-moe","description":"Hardware video encode/decode on the raspberry pi using the MMAL API","archived":false,"fork":false,"pushed_at":"2018-10-04T13:09:08.000Z","size":3658,"stargazers_count":29,"open_issues_count":1,"forks_count":12,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-01T12:44:11.391Z","etag":null,"topics":["c","mmal","raspberry-pi","raspberry-pi-camera","raspberrypi"],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/t-moe.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-09-24T08:25:12.000Z","updated_at":"2025-01-30T20:23:05.000Z","dependencies_parsed_at":"2023-07-21T19:53:24.700Z","dependency_job_id":null,"html_url":"https://github.com/t-moe/rpi_mmal_examples","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/t-moe%2Frpi_mmal_examples","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/t-moe%2Frpi_mmal_examples/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/t-moe%2Frpi_mmal_examples/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/t-moe%2Frpi_mmal_examples/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/t-moe","download_url":"https://codeload.github.com/t-moe/rpi_mmal_examples/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238608354,"owners_count":19500365,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","mmal","raspberry-pi","raspberry-pi-camera","raspberrypi"],"created_at":"2024-09-28T00:40:54.952Z","updated_at":"2025-10-28T07:30:36.533Z","avatar_url":"https://github.com/t-moe.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Raspberry PI MMAL Examples\n\nThis repository contains a bunch of examples for the MMAL (Multimedia Abstraction Layer) API.\nMMAL is a C library designed by Broadcom for use with the Videocore IV GPU found on the Raspberry Pi.\n\nEverything written in this document is a personal opinion from myself (t-moe). Feel free to contribute to the respository via Pull-Requests, but please don't send me general MMAL questions, as I am not an expert on the Topic.\n\n\nThe goal of this repository is to help others getting started with MMAL. MMAL can be a real pain, because it's poorly documented and the relevant GPU Source-Code is closed source.\n\n\n## Official resources\n\n\n* [MMAL Doxygen](http://www.jvcref.com/files/PI/documentation/html/index.html) (Warning: Out of date, see below)\n* [Raspberry PI Community Forum](https://www.raspberrypi.org/forums/viewforum.php?f=67)\n* [Official MMAL examples](https://github.com/raspberrypi/userland/tree/master/interface/mmal/test/examples) (Warning: Partially broken, see below)\n* [MMAL Source](https://github.com/raspberrypi/userland/tree/master/interface/mmal) (client only)\n* [OpenMAX Il Components Documentation](http://www.jvcref.com/files/PI/documentation/ilcomponents/index.html) (Openmax is used in the backend of MMAL)\n\n\n\n## Examples in this repository\n\nFile | Description | Known Working rpi-firmware versions\n------------ | ------------- | ---------------------\nexample_basic_2.c | Copied from the official userland repo. Takes a video-filename as argument and decodes that video | [a5b781c](https://github.com/Hexxeh/rpi-firmware/commit/a5b781c7a761664226ff9654416776d372f8bbf0)\ngraph_decode_render.c | Decodes test.h264_2 and renders it to the gpu output. Uses the graph api | [a5b781c](https://github.com/Hexxeh/rpi-firmware/commit/a5b781c7a761664226ff9654416776d372f8bbf0)\nconnection_decode_encode.c | Decodes test.h264_t and re-encodes it again. Uses the connection api | [a5b781c](https://github.com/Hexxeh/rpi-firmware/commit/a5b781c7a761664226ff9654416776d372f8bbf0)\nmanual_decode_overlay_encode.c | Decodes test.h264_t, draws some basic overlay on it (CPU) and re-encodes it. Manipulates the buffers manually.| [a5b781c](https://github.com/Hexxeh/rpi-firmware/commit/a5b781c7a761664226ff9654416776d372f8bbf0)\n\nJust type make to build them to individual programms.\n\n\n## Debugging Notes\n\n* `export VC_LOGLEVEL=\"mmal:trace\"` will enable log output of the MMAL client library (CPU)\n* `sudo vcdbg log msg` will dump the server-side messages (GPU)\n* `vcgencmd version` will print the GPU firmware version.\n* Ensure that you have enough GPU Memory allocated (check `/boot/config.txt`) and the required license keys, for what you're trying to achieve.\n* The people over at the [Raspberry PI Community Forum](https://www.raspberrypi.org/forums/viewforum.php?f=67) are really helpful. Provide them a [Minimal, Complete and Verifiable Example ](https://stackoverflow.com/help/mcve) along with the log outputs from the commands listed above and they may be able to help you.\n\n## Problem Notes\n* The Doxygen documentation of the MMAL library is out of date.\n  * The container reader and writer components do not work. They were initially designed for a project where the GPU had access to the filesystem. This is no longer the case. So you have to read/write media containers on the CPU and send the data via buffers to the GPU\n  * The MMAL Library provides a generic way to access \"components\". The general concept is documented in doxygen but the individual components are not documented. You have to guess the inputs, outputs \u0026 parameters for every component by looking at examples.\n* The Offical MMAL examples are partially broken.\n  * example_connections.c and example_graph.c use the reader component, which will not work\n  * example_basic_2.c has a small typo. A fixed version is in this repository.\n  * I didn't look at example_basic_1.c\n  * All examples lack Makefiles and the input data to test it with.\n* Whether your MMAL Program will work depends a lot on the GPU firmware. What may have worked once, will not nececessarily work now.\n  * Run `sudo rpi-update` to update to the latest firmware.\n  * Run `sudo rpi-update \u003cversion\u003e` to install a specific version.\n  * Always include the used firmware version in your problem description.\n* The video decoder component expects a h264 raw stream without audio as input.\n  * The file `test.h264_2` in this repository is a suitable example.\n  * You can convert to the requested format using ffmpeg. `ffmpeg -i input_720p.mp4 -bsf h264_mp4toannexb -an -f h264 output.h262`\n* The video encoder component expects a specific input format:\n  * encoding: I420\n  * the width must be a multiple of 32 and the height a multiple of 16. Use the `VCOS_ALIGN_UP` Macros to calculate the aligned lengths and provide the effective size via the \"crop\" parameter.\n* The video encoder component opens the codec when you enable the output port. At this point the input format must be commited. Changing it afterwards will result in an error.\n* If you use the Graph API, you cannot use \"Zero Copy\" on inputs and outputs.\n  * This is probably because mmal_graph is using mmal_pool_create, whilst to get zero_copy working correctly requires the use of mmal_port_pool_create.\n  * Connect your components manually or do not use \"Zero copy\"\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ft-moe%2Frpi_mmal_examples","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ft-moe%2Frpi_mmal_examples","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ft-moe%2Frpi_mmal_examples/lists"}