Fixin Raspistill and Raspivid for Headless Streaming on the Raspberry Pi
Recently I got 2 Raspberry Pi Camera modules for my Raspberry Pi boards for some projects I have in mind. I was sad to find out I could not stream unless I had a monitor connected to the Pi and after some additional digging I found out that the initial version of the tools Raspistill and Raspivid the no preview option was broken causing it to not work. After some digging in the forums and trial and error I found how to fix it while the tools are updated and added to the package repo. Plus it was a good exercise in compiling files for ARM.
Update your system applications and download the required software to compile userland:
sudo apt-get update sudo apt-get upgrade sudo apt-get install git gcc build-essential cmake vlc
Download and configure sources
Create a folder to hold development files and clone the latest userland for raspian.
cd ~ mkdir Development git clone git://github.com/raspberrypi/userland.git cd userland
Create the proper make files:
sed -i 's/if (DEFINED CMAKE_TOOLCHAIN_FILE)/if (NOT DEFINED CMAKE_TOOLCHAIN_FILE)/g' makefiles/cmake/arm-linux.cmake
Fix Raspistill
Open Raspistill command source file at line 1034:
nano +1034 host_applications/linux/apps/raspicam/RaspiStill.c
Modify the line from:
MMAL_STATUS_T status = -1;
to:
MMAL_STATUS_T status = MMAL_SUCCESS;
Fix Raspivid
Open the raspivid source file at line 852:
nano +852 host_applications/linux/apps/raspicam/RaspiVid.c
Modify the line from:
MMAL_STATUS_T status = -1;
to:
MMAL_STATUS_T status = MMAL_SUCCESS;
Build and Install the Latest Userland
Configure a build folder and build and install the userland binaries. This should take around 30 to 45 minutes:
mkdir build cd build sudo cmake -DCMAKE_BUILD_TYPE=Release .. sudo make sudo make install
You should now be able to create a steam with VLC and connect to it on a headless system using the -n parameter for no preview:
raspivid -o - -t -1 -w 920 -h 540 -n | cvlc -vvv --network-caching=0 stream:///dev/stdin --sout '#rtp{sdp=rtsp://:8554/}' :demux=h264
Reader Comments (7)
So I just tried building it anyway, and the new raspivid ("v1.2") gives me the same problem. The output mp4 file is of completely plausible size for the time and bitrate, and has some indications of being properly formatted, but VNC (on windows) and Windows media player won't play it. VNC at least recognizes the frame size, puts up a black frame of the right size and then immediately stops. I can't be sure, but the debug log from VNC seems to indicate that there is 'stream format' info (such as the frame size) but no actual content was found. There's nothing that looks like an error, but nothing that looks like anything got decoded either.
Is this what happens with the 'old' raspivid when you don't have a monitor hooked up?
Note, I have not yet tried raspivid with a monitor hooked up, I don't have one handy right now, I'm running raspivid over ssh, redirect to a file, and then copying the output files via sFTP and trying to play them.
The raspistill has worked fine - except when I did a time lapse of 600 frames every 2 second for 1200 seconds, I actually got 600 frames taken every 2.5 seconds, spread out over 1500 seconds. So it's either running 25% slow on its timing, or maybe it's taking .5 seconds to store each frame and not accounting for that in the -t or -ti options. Both of which seem strange.
Two questions:
Do you really need to run cmake and make as root?
Why do you change "if (DEFINED CMAKE_TOOLCHAIN_FILE)" to "if (NOT DEFINED CMAKE_TOOLCHAIN_FILE)"? Or does that just eliminate the warning error when building on the Pi?
Do you think it is possible to choose the level profile of the H264 by changing
from:
param.profile[0].level = MMAL_VIDEO_LEVEL_H264_4;
to:
param.profile[0].level = MMAL_VIDEO_LEVEL_H264_3;
and then build and install the userland binaries?
At least here "userland / interface / mmal / mmal_parameters_video.h" it seems that there are several levels to choose.