The Raspberry Pi is a fantastic little computer for recording video. For about €50,- you can record in HD with full customizability and for as long as you want or have storage for. However, one issue is that the .h264
container it records in is hard to work with. It is therefore often important to convert videos to widely applicable formats like .mp4
to be able to view them properly and get the right meta information. For this I recommend the program FFmpeg
.
Installing ffmpeg on a Raspberry Pi is not as simple as downloading an executable from the command line, but it is also not too difficult. Here are the steps:
Install h264 library
- Open a terminal window on the raspberrypi (or via SSH connection) and type in the following commands:
- Download h264 library:
git clone --depth 1 https://code.videolan.org/videolan/x264
- Change directory to the x264 folder:
cd x264
- Configure installation:
./configure --host=arm-unknown-linux-gnueabi --enable-static --disable-opencl
- Create the installation:
make -j4
- Install h264 library on your system:
sudo make install
Install ffmpeg with h264
- Change to home directory:
cd ~
- Download ffmpeg:
git clone git://source.ffmpeg.org/ffmpeg --depth=1
- Change to ffmpeg directory:
cd ffmpeg
- Configure installation:
./configure --arch=armel --target-os=linux --enable-gpl --enable-libx264 --enable-nonfree
- Make the installation:
make -j4
. Note this step will take a long time! - Now finally run the installation:
sudo make install
Note: If you are working with an older model of the raspberrypi (< 3 B+) then you may not have 4 cores available. You will then have to change make -j4
to make -j
.
Convert h264 video
Now you are ready to convert a h264 video on your Raspberry Pi! Simply run the following command:
ffmpeg -i USER_VIDEO.h264 -vcodec copy USER_VIDEO.mp4
There are many options available and many other ways to convert h264 videos with ffmpeg, but this command is the quickest of all methods that I tested as it basically just changes the container without re-encoding.
Updates:
26/03/20: updated post to reflect the changed VLC repository (Thanks @carlos)