Posts: 2
Joined: Sun Oct 22, 2017 7:41 pm
Location: Colorado
Contact: Website

Compiling RaspiStill.c Instructions

Tue Oct 24, 2017 6:01 pm

Hi - Working with the pi Camera module V2 and its raspistill utility to do some image processing. I'm delving into the source code now which is complex. In particular RaspiStill.c which controls the camera. I'm hoping to get a raw memory mapped raster feed from the camera that provides simple RGB information to do edge detection. This avoids reading/writing picture files and converting them. The goal is to speed up the analysis which currently takes about 800 - 1000 mS. The source is available from github and the included buildme worked fine for the initial build. I wrote some simple shell scripts to compile/link just RaspiStill.c which also work for other c source programs in the set. Also wrote a PDF on what I did with the hope it may help a few others paddling in similar waters. Link is Happy computing and enjoy your projects.
Best - Muniac (aka Scott)

User avatar
Posts: 34152
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: Compiling RaspiStill.c Instructions

Thu Oct 26, 2017 10:14 pm

cd /tmp
git clone
cd userland

Job done.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

2012-18: 1B*5, 2B*2, B+, A+, Z, ZW, 3Bs*3, 3B+

Any DMs sent on Twitter will be answered next month.

Posts: 5
Joined: Sat Sep 17, 2016 6:26 pm

Re: Compiling RaspiStill.c Instructions

Mon Sep 17, 2018 1:33 am

Thanks for these steps! At time of this writing, I needed one more step with a Pi Zero W and a clean flash of the June 2018 version of Raspbian Stretch - ... 018-06-29/:

sudo apt-get install cmake

Posts: 540
Joined: Wed Oct 02, 2013 12:28 pm

Re: Compiling RaspiStill.c Instructions

Mon Sep 17, 2018 11:16 am

You can also compile raspistill and the other programs on its own without compiling the whole userland.

I will show you for raspividyuv, which I think is easier for your purpose.

Create a directory for your program, lets call it "~/raspividyuv". Copy the files RaspiCamControl.c, RaspiCamControl.h, RaspiCLI.c, RaspiCLI.h, RaspiPreview.c, RaspiPreview.h, RaspiVidYUV.c from the folder host_applications/linux/apps/raspicam/ of the userland source code into this directory.

Create a new "CMakeLists.txt" based on the original one:

Code: Select all

cmake_minimum_required(VERSION 2.8)
# raspividyuv



find_package (Threads)
FIND_LIBRARY(MMAL_CORE_LIBRARY mmal_core /opt/vc/lib)
FIND_LIBRARY(MMAL_UTIL_LIBRARY mmal_util /opt/vc/lib)
FIND_LIBRARY(MMAL_VC_CLIENT_LIBRARY mmal_vc_client /opt/vc/lib)
FIND_LIBRARY(BCM_HOST_LIBRARY bcm_host /opt/vc/lib)


add_executable(raspividyuv   ${COMMON_SOURCES} RaspiVidYUV.c)


install(TARGETS raspividyuv DESTINATION /usr/local/bin)
To build your copy of raspividyuv:

Code: Select all

mkdir -p build
cd build
cmake ..
Which will create a local raspividyuv copy you can run with ./raspividyuv in this directory for testing, or install it by finally using

Code: Select all

sudo make install
cd ..
You can put these commands into a script, too.

As a starting point RaspiVidYuv.c can directly deliver RGB buffer inside the camera_buffer_callback function("./raspividyuv -rgb -o /dev/null"). You can use the buffer there for image processing by replacing the fwrite call by your image processing code.

For RaspiStill.c it can be done similar, but needs some additional tweaks and more source files, as things like the gl_scenes are included, too...

Posts: 5
Joined: Sat Sep 17, 2016 6:26 pm

Re: Compiling RaspiStill.c Instructions

Mon Oct 15, 2018 2:05 pm

@ethanol100, thanks for the tips on compiling a single program within userland. I'm going to try this out and do something similar to build only raspistillyuv.c

I'm still a little new to the build chain for this project and C in general, but I've tried many things and I'm having trouble linking in additional libraries. If anyone has a suggestion, it would be greatly appreciated. I thought I found the right file, but when I ran the ./buildme script in userland, it seems to have dynamically rebuilt the file I edited.

I'd like to include the wiring pi library so I can read/write GPIO pins within the raspistillyuv module. I followed the instructions here:, which basically just let you just do a git pull and run the build script. This compiles and installs the c library. It looks like it puts it in the /usr/lib/ directory.

The examples on the WiringPi site show adding a linker argument to the compile command line, but I'm having trouble finding the appropriate spot to put this argument when building userland. I tried the wiringPi example program and it worked fine which is to reference the wiringPi.h header file in code then add -lwiringPi to the compile command line. I haven't tried using @ethanol100's method yet, but a solution around that approach would be adequate for me as well.

Thank you!

Posts: 540
Joined: Wed Oct 02, 2013 12:28 pm

Re: Compiling RaspiStill.c Instructions

Fri Oct 19, 2018 10:33 pm

If you are using cmake, than it is basically just adding two lines to the CMakeLists.txt.
"FIND_LIBRARY(WIRINGPI_LIBRARY wiringPi)" and adding ${WIRINGPI_LIBRARY} into target_link_libraries().

As an example I added the sources for a modified raspistillyuv example, where you can use --gpio as a command line option and use a pull-down button connected to WiringPi Pin 8 to trigger a capture.
(36.83 KiB) Downloaded 7 times
I installed wiringpi via "sudo apt-get install wiringpi".

Posts: 5
Joined: Sat Sep 17, 2016 6:26 pm

Re: Compiling RaspiStill.c Instructions

Sat Oct 20, 2018 4:40 pm

Thank you, thank you, thank you!
Your example worked for me and I can use your cmake setup instead of the userland version to move forward now.

Return to “Camera board”