There is already a topic about how to get HW accelerated ffmpeg on Raspberry Pi with OpenMax here on the LQ Slack ARM forum and by respecting the work that it's been done there I considered to start a new topic. I haven't tried that and I'm still confused about why would you need an external OpenMax library and not use the patched and optimized libs from the Raspberry Foundation. These libs come with all Raspbian Images and if the instructions for installing Slackware ARM on the Raspberry Pi are followed, these libs will be copied and residing in /opt/vc. This collection of libs is also called "userland" and confusingly "firmware". More info about it:
https://github.com/raspberrypi/userland
The GPU in the Raspberry Pi has routines for HW Accelerated decoding/encoding of MPEG4 H264 (enabled by default) and MPEG2 & VC1 (disabled - needs a license).
For Multimedia best performance, I'd advise you to put the following settings in your /boot/config.txt
gpu_mem=256
framebuffer_depth=16
#If you're using Analog Audio Out
audio_pwm_mode=2
Compilation time on a Raspberry Pi2B is around 1 hour and on Raspberry Pi1/0 a little bit more, worst case scenario 4 times more than on the Pi2B.
Before starting - a short preamble:
- there is already a generic ffmpeg package that comes with Slackware ARM and I'd suggest to uninstall it before compiling your own ffmpeg. To uninstall it you need to run:
removepkg /var/log/packages/ffmpeg-x.x.x-arm
and if you need it back, remember its name and use:
slackpkg install ffmpeg-x.x.x-arm
- this how-to applies only for Raspberry Pi devices running either Slackware ARM 14.2 SoftFloat or Slackware ARM - current HardFloat
- it is building FFMPEG with support for HW Accelerated decoding/encoding of MPEG4 H264 and MPEG2 (if you buy a license)
- it is covering the optimization for Raspberry Pi 1/0 (armv6) and Raspberry Pi2B (armv7)
- there is a naming convention needed for helping with the short formatting:
Using "pi1" will imply Slack ARM 14.2 - SoftFloat on armv6 (RaspberryPi 1/0)
Using "pi2" will imply Slack ARM current - HardFloat on armv7 (RaspberryPi 2B)
- for best performance and system optimization on ARM Systems/SoCs, mainly due to their simplicity, it is imperative to create ARM-CPU specific code and if possible use the help of the FPU (co-processor) and GPU. Additionally, HardFloat code is the best option but unsupported on pi1.
- some configure scripts do not have an extra compiler flags option and are not tolerating compiler environmental variables, thus, all of the resulted Makefiles need to be edited MidnightCommander should be your friend - use F7 and search for CFLAGS = or write a script
Dependencies:
___VC-USERLAND___START
- it is advised to always use (upgrade) the latest release together with the corresponding firmware & kernel. If you need an older compiled VC snapshot, you can always find them on:
Raspbian Images Repository
https://downloads.raspberrypi.org/raspbian/images/
or Raspbian Lite Images Repository
https://downloads.raspberrypi.org/raspbian_lite/images/
- if you use a pi2 and followed the Slack ARM installation steps then you have everything you need in /opt/vc (optimized already for armv7 and compiled as HardFloat)
- if you are using a pi1, then you might need to download the VC source, compile& install it. To do so follow the steps:
- backup your old and useless (compiled for armv7 HardFloat) /opt/vc
Code:
mv /opt/vc /opt/vc-old
mkdir /kit&&cd /kit
git clone https://github.com/raspberrypi/userland
cd userland/
- edit and change CMakeLists:
from:
# Global compiler flags
if(CMAKE_COMPILER_IS_GNUCC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-multichar -Wall -Wno-unused-but-set-variable -fPIC")
endif()
to:
# Global compiler flags
if(CMAKE_COMPILER_IS_GNUCC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-multichar -Wall -Wno-unused-but-set-variable -march=armv6zk -mtune=arm1176jzf-s -mfloat-abi=soft -fPIC")
endif()
- run and wait around 40 minutes on pi1
./buildme
- then add to /etc/ld.so.conf
/opt/vc/lib
/opt/vc/bin
- run ldconfig
___VC-USERLAND___END
___x264___START
- x264 lib is needed for HW Accelerated encoding of MPEG4 H264 content
- on p1 run:
Code:
cd /kit
git clone git://git.videolan.org/x264
cd x264/
git checkout 72d53ab2ac7af24597a824e868f2ef363a22f5d4
./configure --disable-asm --enable-shared --disable-win32thread --enable-strip --extra-cflags='-march=armv6zk -mtune=arm1176jzf-s -mfloat-abi=soft'
make V=1
make install
ldconfig
- on pi2 run the same as above until ./configure
Code:
./configure --disable-asm --enable-shared --disable-win32thread --enable-strip --extra-cflags='-march=armv7-a -mtune=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard'
make -j 4 V=1
make install
ldconfig
___x264___END
___libmpeg2___START
- the old libmpeg2 might be needed as an alternative for FFMPEG's libavcodec
- on pi1 run:
Code:
cd /kit
wget http://libmpeg2.sourceforge.net/files/libmpeg2-0.5.1.tar.gz
tar -xvzpf libmpeg2-0.5.1.tar.gz
cd libmpeg2-0.5.1
./configure --disable-largefile
- edit ALL Makefiles (including subdirs) look for CFLAGS = and add -march=armv6zk -mtune=arm1176jzf-s -mfloat-abi=soft
Code:
make V=1
make install
ldconfig
- on pi2 run the same as above until after ./configure
- edit ALL Makefiles (including subdirs) look for CFLAGS = and add -march=armv7-a -mtune=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard
Code:
make -j 4 V=1
make install
ldconfig
___libmpeg2___END
___libass___START
- libass is needed for subtitles display
- more info on
https://github.com/libass/libass/releases
- on pi 1 run:
Code:
cd /kit
wget https://github.com/libass/libass/releases/download/0.13.7/libass-0.13.7.tar.gz
tar -xvzpf libass-0.13.7.tar.gz
cd libass-0.13.7/
./configure
make V=1
make install
ldconfig
- on pi2 run the same as above until after ./configure
Code:
make -j 4 V=1
make install
ldconfig
___libass___END
Building FFMPEG
- For Raspberry Pi I'd recommend using the FFmpeg Version 3.1.6-Krypton.tar.gz patched and optimized by the Kodi Community. This version incorporates many special patches for the Raspberry Pi GPU and VC libs and it will be the fastest you'd be able to get ATM.
- on pi1
Code:
cd /kit
wget https://github.com/xbmc/FFmpeg/archive/3.1.6-Krypton.tar.gz
tar -xzpf 3.1.6-Krypton.tar.gz
cd FFmpeg-3.1.6-Krypton/
export LDFLAGS="-L /opt/vc/lib/"
./configure --extra-cflags='-march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=soft' --extra-cxxflags='-march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=soft' --disable-devices --disable-sdl --disable-ffprobe --disable-ffserver --disable-doc --disable-w32threads --enable-ffplay --extra-libs=-ldl --enable-shared --enable-libass --disable-devices --enable-mmal --enable-hwaccel=h264_mmal --enable-opengl --disable-neon --enable-gnutls --enable-libvorbis --enable-muxer=ogg --enable-encoder=libvorbis --enable-nonfree --enable-libx264 --enable-gpl --enable-runtime-cpudetect --enable-postproc --enable-bzlib --enable-gnutls --enable-muxer=spdif --enable-muxer=adts --enable-muxer=asf --enable-encoder=ac3 --enable-encoder=aac --enable-encoder=wmav2 --enable-protocol=http --enable-encoder=png --enable-encoder=mjpeg --enable-nonfree --enable-pthreads --enable-pic --enable-zlib --disable-mipsdsp --disable-mipsdspr2
make V=1
- install it or create a package
https://docs.slackware.com/howtos:sl...ding_a_package
- run ldconfig
- on pi2 run the same as above until ./configure
Code:
./configure --extra-cflags='-march=armv7-a -mtune=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard' --extra-cxxflags='-march=armv7-a -mtune=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard' --disable-devices --disable-sdl --disable-ffprobe --disable-ffserver --disable-doc --disable-w32threads --enable-ffplay --extra-libs=-ldl --enable-shared --enable-libass --disable-devices --enable-mmal --enable-hwaccel=h264_mmal --enable-opengl --enable-neon --enable-gnutls --enable-libvorbis --enable-muxer=ogg --enable-encoder=libvorbis --enable-nonfree --enable-libx264 --enable-gpl --enable-runtime-cpudetect --enable-postproc --enable-bzlib --enable-gnutls --enable-muxer=spdif --enable-muxer=adts --enable-muxer=asf --enable-encoder=ac3 --enable-encoder=aac --enable-encoder=wmav2 --enable-protocol=http --enable-encoder=png --enable-encoder=mjpeg --enable-nonfree --enable-pthreads --enable-pic --enable-zlib --disable-mipsdsp --disable-mipsdspr2
make -j 4 V=1
- install it or create a package
https://docs.slackware.com/howtos:sl...ding_a_package
- run ldconfig
And you're done!
Enjoy low CPU usage while watching *** on your Pi. Careful to point your favorite Media Player to use ffmpeg, Kodi could also be used with this ffmpeg build.
Feel free to add whatever codec / exotic add-on you wish to the above instructions by first adding the dependency and then modifying the ffmpeg ./config directives with your add-on. For inspiration take a look at AlienBob's ffmpeg SlackBuild:
http://www.slackware.com/~alien/slac...peg.SlackBuild