May 232013
 

This is going to be short and sweet. I picked it up from a video by the Marvellous Matthew Manning (reminds me of the “marvellous mechanical mouse organ” from Bagpuss – Google it if you need to ask) otherwise known as RaspberryPi4Beginners.

Matt’s made a video which complements several of my recent blogs about the Raspberry Pi Camera. His channel is Raspberry Pi For Beginners, but that doesn’t mean that only beginners can learn something from it. I learnt this alternative way of wrapping an .h264 stream to .mp4. It’s much simpler than using FFMPEG and it worked first time for me. (Apparently Stuart Green @sg_84 figured it out).

Installation

sudo apt-get update
sudo apt-get install gpac
y

Usage

MP4Box -add filename.h264 filename.mp4

And you can do it all right there on your Raspberry Pi. Nice one Matt. Check out the full video here…

I met Matt at the Cambridge Jam last week. We had a bit of a chat, but not enough. I find Jams a bit hectic (particularly when I have three demos) and although good for initial meet-ups, perhaps not the best places for lengthy discussion. We must meet again soon and have a proper chat!

  21 Responses to “Another way to convert Raspberry Pi Camera .h264 output to .mp4”

  1. Nice one! Been hinting ages for this!

    The Raspberry Pi Guy

  2. The MP4Box is running perfectly on raspberry, but I have one doubt whe I read AVC-H264 import – frame size 1920 x 1080 at 25.000 FPS. Is the vid 25 FPS? or perhaps 30 FPS

    • The output is 25 fps – at least, that’s what it says on the MP4 file when I look in Windows. I don’t know if there’s a way to get it in 30 fps or not. I expect there is, but I don’t know how to do that. I’m happy with 25 fps as it avoids issues for me when mixing video from different sources. My main video camera is 25 fps.

  3. How can I do this command in a Python script?

    • You can pretty much do anything in Python if you

      from subprocess import call

      near the top of your program, then…
      your_command = "do this" # set your command here

      call ([your_command], shell=True)

  4. […] And this is possible on the raspberry pi itself. […]

  5. I was wondering if there’s a way to stream h.264 video from a USB camera / Raspberry pi to a windows computer. It has to be a way other than gstreamer as I’ve heard it’s quite tricky to stream with this software on a windows machine.

  6. Hi!
    Do you think it’s possible to write something like this:

    from subprocess import call

    converter = MP4Box -add filename.h264 filename.mp4
    Call = ([converter], Shell = True)

    ?

    • Yes it is but you’d need quotes around at least the string parts of the command…

      converter = “MP4Box -add filename.h264 filename.mp4”

      • After sudo apt-get install gpac. Not all files can be authenticated but I download anyways. A lot of errors about things I cannot get. Raspberry pi says MP4Box is not a valid command. How do I convert the .h264 now? I’ve sudo apt-get upgrade and updated already. I don’t know what to do.

    • After MUCH trial and error here’s what I got to work. I used Popen in order to call the .wait() function later to get a return code for debugging.

      import subprocess

      convCommand = ‘MP4Box -add {0}.h264 {1}.mp4’.format(filename, filename)
      conv = subprocess.Popen(convCommand, shell = True)

      • Could you show me whole code?
        import subprocess

        convCommand = ‘MP4Box -add {0}.h264 {1}.mp4’.format(filename, filename)
        conv = subprocess.Popen(convCommand, shell = True)

        I’ve got NameError: name ‘filename’ is not defined
        I’ve got video.h264 at this name.

  7. Thanks, works like a charm

  8. trying sudo apt-get install gpac (or -y gpac) wouldnt work for me, saying it is unable to locate the package. Is there anything in particular I need to do?

Leave a Reply