There is quite detailed guide available for building it for raspberry pi here.
-
In short, first build the dependencies - fdk-aac, mp3lame, libass, x264.
-
Download the latest ffmpeg source from here: https://ffmpeg.org/releases/
wget https://ffmpeg.org/releases/ffmpeg-4.4.tar.bz2 -O ffmpeg.tar.bz2
tar xvf ffmpeg.tar.bz2
cd ffmpeg-*
- Configure it
./configure \
--prefix=/usr \
--enable-gpl \
--enable-nonfree \
--enable-shared \
--enable-libtheora \
--enable-libvorbis \
--enable-omx \
--enable-omx-rpi \
--enable-mmal \
--enable-libxcb \
--enable-libfreetype \
--enable-libass \
--enable-gnutls \
--disable-opencl \
--enable-libcdio \
--enable-libbluray \
--extra-cflags="-march=armv8-a+crc+simd -mcpu=cortex-a72 -mfpu=neon-fp-armv8 -mtune=cortex-a72 -mfloat-abi=hard -O3" \
--enable-libx264 \
--enable-libfdk-aac \
--enable-libmp3lame \
--enable-avresample
./configure \
--prefix=/usr \
--enable-gpl \
--enable-nonfree \
--enable-shared \
--enable-libtheora \
--enable-libvorbis \
--enable-omx \
--enable-omx-rpi \
--enable-mmal \
--enable-libxcb \
--enable-libfreetype \
--enable-libass \
--enable-gnutls \
--disable-opencl \
--enable-libcdio \
--enable-libbluray \
--extra-cflags="-march=armv8-a+crc -mfpu=neon-vfpv4 -mtune=cortex-a53 -ftree-vectorize -mfloat-abi=hard -O3" \
--enable-libx264 \
--enable-libfdk-aac \
--enable-libmp3lame \
--enable-avresample
- Build & Install it
make -j4
sudo checkinstall -y --pkgname ffmpeg --pkgversion 4.4.0 make install
sudo dpkg -i ffmpeg_4.4.0-1_armhf.deb
Follow the detailed guides from here & here.
-
In short, First install the dependency packages and libraries.
-
Download sources :
wget https://github.com/opencv/opencv/archive/refs/tags/4.5.2.tar.gz -O opencv-4.5.2.tar.gz
wget https://github.com/opencv/opencv_contrib/archive/refs/tags/4.5.2.tar.gz -O opencv_contrib-4.5.2.tar.gz
tar xvf opencv*
cd opencv-4.5.2
mkdir build ; cd build
- Note full path of
modules
directory inopencv_contrib
and replace/home/pi/cv/opencv_contrib-4.5.2/modules
with your modules path.
- Configure it
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr \
-D OPENCV_EXTRA_MODULES_PATH=/home/pi/cv/opencv_contrib-4.5.2/modules \
-D CMAKE_CXX_FLAGS='-march=armv8-a+crc+simd -mcpu=cortex-a72 -mfpu=neon-fp-armv8 -mtune=cortex-a72 -mfloat-abi=hard -O3'
-D ENABLE_NEON=ON \
-D ENABLE_VFPV4=ON \
-D WITH_TENGINE=ON \
-D BUILD_TESTS=OFF \
-D INSTALL_PYTHON_EXAMPLES=OFF \
-D OPENCV_ENABLE_NONFREE=ON \
-D CMAKE_SHARED_LINKER_FLAGS=-latomic \
-D WITH_CAROTENE=OFF \
-D BUILD_EXAMPLES=OFF ..
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr \
-D OPENCV_EXTRA_MODULES_PATH=/home/pi/cv/opencv_contrib-4.5.2/modules \
-D CMAKE_CXX_FLAGS='-march=armv8-a+crc -mfpu=neon-vfpv4 -mtune=cortex-a53 -ftree-vectorize -mfloat-abi=hard -O3'
-D ENABLE_NEON=ON \
-D ENABLE_VFPV4=ON \
-D WITH_TENGINE=ON \
-D BUILD_TESTS=OFF \
-D INSTALL_PYTHON_EXAMPLES=OFF \
-D OPENCV_ENABLE_NONFREE=ON \
-D CMAKE_SHARED_LINKER_FLAGS=-latomic \
-D WITH_CAROTENE=OFF \
-D BUILD_EXAMPLES=OFF ..
- Build & Install it
make -j4
sudo checkinstall -y --pkgname opencv --pkgversion 4.5.2 make install
sudo dpkg -i opencv_4.5.2-1_armhf.deb
I recommend you to build the packages yourself. In case, you want to skip it. You can download pre-built packages.
- Install dependency packages
sudo apt install libxcb-shm0 libcdio-paranoia-dev libsdl2-2.0-0 libxv1 libtheora0 libva-drm2 libva-x11-2 libvdpau1 libharfbuzz0b libbluray2 libatlas-base-dev libhdf5-103 libgtk-3-0
- Install the packages present in common directory
sudo dpkg -i fdk-aac_2.0.2-1_armhf.deb libass_0.15.1-1_armhf.deb mp3lame_3.100-1_armhf.deb x264_0.163-1_armhf.deb
sudo dpkg -i ffmpeg_4.4.0-1_armhf.deb opencv_4.5.2-1_armhf.deb
sudo apt remove fdk-aac mp3lame libass x264 ffmpeg
sudo apt remove opencv