Convert #RaspberryPi camera module output to MP4 or FLV

Once the camera module has captured video, you are left with an raw H264 file. Now, some players can already play this but what you really want to do is convert it to a common format like MP4. (This is actually ‘wrapping’ the H264 output inside an MP4 ‘container’, but we’ll call it conversion…)

First of all, take a video:

raspivid -fps 30 -o raw.h264 -t 20000
This will create a 20 seconds-long video.
Now run the conversion (see the caveat below, though!):
ffmpeg -r 30 -i raw.h264 -vcodec copy converted.mp4

And there you have it – an MP4 file. Now, I’m not convinced that this will produce a standards-compliant MP4. There seems to be some debate about whether you’ll be able to use it, for example, in a video editing package such as Pinnacle, however, the MP4 should play in most video player software and you should be able to upload to YouTube.

You can produce a FLV (or Flash) file by changing ‘converted.mp4’ to ‘converted.flv’.

RasPi.tv announces RasP.iO add-on board for #RaspberryPi

RasP.iO Introducing RasPiO® » RasP.iO

Alex Eames, over at RasPi.tv has been celebrating a year of having a Raspberry Pi and blogging about it. Amongst his look back over the year, he has announced what sounds like a really exciting project. He is developing a new expansion board for the Pi called RasPIO which will feature:

  • 8 protected digital IO ports
  • 8 analog inputs
  • 2 analog outputs
  • i2c & uart breakout pins

His plan is to turn it into a tool for education and bundle it with software to make a kind of physical computing toolkit for kids to learn how to interact with their environment using the Pi. You can read a little bit more about the board here.

Read Alex’s look back over the last 12 months

Streaming live with the #RaspberryPi camera module to Bambuser

With the release of the camera module to a wider audience, I thought I’d share some of things I’ve learnt. To start off, here’s some information about using the camera with Bambuser.com.

This is in part taken from Marcus Olsson’s blog post about streaming with a webcam.

First of all, register on bambuser.com. Then, go to https://bambuser.com/api/keys and get your RTMP url and stream ID.

On the Pi, do:

apt-get update
apt-get install avconv

If this doesn’t work (it didn’t for me, like it’s disappeared from the repository), do:

apt-get install ffmpeg

On the Pi, create the following in a script called camera_mkfifo.sh:

rm fifo.264
mkfifo fifo.264

(When you run this script first of all you’ll get an error message because the file doesn’t exist, but just ignore it).

Now create another script called camera_output.sh:

/opt/vc/bin/raspivid -o fifo.264 -w 400 -h 300 -t 10000000 -b 500000 &

Now create another script called camera_bambuser.sh

avconv -f h264 -r 25 -i fifo.264 -metadata title="Raspberry Pi Camera Module (LIVE)" -f flv rtmp://<RTMP URL>/<RTMP KEY>

If you’re using ffmpeg, change the “avconv” to “ffmpeg”.

Now, do:

chmod +x camera*.sh

This will make the scripts executable.

Now, just run the three scripts in order:

./camera_mkfifo.sh
./camera_output.sh
./camera_bambuser.sh

You should now be broadcasting LIVE. My stream, should anyone want to see it (and if it’s actually streaming) is at http://bambuser.com/channel/recantha

Please bear in mind that the resolution isn’t all that good. This is to get the frames-per-second up. If you increase the width and height of the video being created using raspivid, it will reduce the fps with an increase in quality.