Git Product home page Git Product logo

rpi_mmal_examples's Introduction

Raspberry PI MMAL Examples

This repository contains a bunch of examples for the MMAL (Multimedia Abstraction Layer) API. MMAL is a C library designed by Broadcom for use with the Videocore IV GPU found on the Raspberry Pi.

Everything 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.

The 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.

Official resources

Examples in this repository

File Description Known Working rpi-firmware versions
example_basic_2.c Copied from the official userland repo. Takes a video-filename as argument and decodes that video a5b781c
graph_decode_render.c Decodes test.h264_2 and renders it to the gpu output. Uses the graph api a5b781c
connection_decode_encode.c Decodes test.h264_t and re-encodes it again. Uses the connection api a5b781c
manual_decode_overlay_encode.c Decodes test.h264_t, draws some basic overlay on it (CPU) and re-encodes it. Manipulates the buffers manually. a5b781c

Just type make to build them to individual programms.

Debugging Notes

  • export VC_LOGLEVEL="mmal:trace" will enable log output of the MMAL client library (CPU)
  • sudo vcdbg log msg will dump the server-side messages (GPU)
  • vcgencmd version will print the GPU firmware version.
  • Ensure that you have enough GPU Memory allocated (check /boot/config.txt) and the required license keys, for what you're trying to achieve.
  • The people over at the Raspberry PI Community Forum are really helpful. Provide them a Minimal, Complete and Verifiable Example along with the log outputs from the commands listed above and they may be able to help you.

Problem Notes

  • The Doxygen documentation of the MMAL library is out of date.
    • 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
    • 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 & parameters for every component by looking at examples.
  • The Offical MMAL examples are partially broken.
    • example_connections.c and example_graph.c use the reader component, which will not work
    • example_basic_2.c has a small typo. A fixed version is in this repository.
    • I didn't look at example_basic_1.c
    • All examples lack Makefiles and the input data to test it with.
  • Whether your MMAL Program will work depends a lot on the GPU firmware. What may have worked once, will not nececessarily work now.
    • Run sudo rpi-update to update to the latest firmware.
    • Run sudo rpi-update <version> to install a specific version.
    • Always include the used firmware version in your problem description.
  • The video decoder component expects a h264 raw stream without audio as input.
    • The file test.h264_2 in this repository is a suitable example.
    • You can convert to the requested format using ffmpeg. ffmpeg -i input_720p.mp4 -bsf h264_mp4toannexb -an -f h264 output.h262
  • The video encoder component expects a specific input format:
    • encoding: I420
    • 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.
  • 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.
  • If you use the Graph API, you cannot use "Zero Copy" on inputs and outputs.
    • 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.
    • Connect your components manually or do not use "Zero copy"

rpi_mmal_examples's People

Contributors

6by9 avatar t-moe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

rpi_mmal_examples's Issues

Error message from graph_decode_render

The following also applies to the fork from 6by9.

$ uname -a
Linux sa1 4.19.19-v7+ #1198 SMP Tue Feb 5 14:53:32 GMT 2019 armv7l GNU/Linux

Using above kernel & f/w always produces this:

$ ./graph_decode_render
startmmal: mmal_port_enable: vc.ril.video_decode:ctr:0(0x1664070) already enabled
mmal: mmal_graph_enable: could not enable port vc.ril.video_decode:ctr:0
stop decoding

The supplied test file plays ok, but subsequent attempts often fail, & many valid .h264 files (I just substituted

SOURCE_OPEN(argv[1])

for the hard coded test file)

silently quit the application immediately.

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.