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

  2. 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 🙂

    Simon

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.