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

7 comments for “Convert #RaspberryPi camera module output to MP4 or FLV

  1. 16 May 2013 at 8:14 pm

    Just a note – ffmpeg wasn’t installed on my Raspbian image so I presume its not a default package
    I did sudo apt-get install ffmpeg to get it

  2. 16 May 2013 at 8:32 pm

    And then it said ffmpeg was depreciated πŸ™‚
    And then the .mp4 only appears to have one frame πŸ™

    And then using avconv made no difference πŸ™

    Not winning with this one so far πŸ™‚


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.