LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware > Slackware - ARM
User Name
Password
Slackware - ARM This forum is for the discussion of Slackware ARM.

Notices


Reply
  Search this Thread
Old 08-24-2017, 01:50 AM   #1
abga
Member
 
Registered: Jul 2017
Location: EU
Distribution: Slackware x86 & ARM
Posts: 108

Rep: Reputation: 26
Slackware ARM Raspberry Pi - armv6 and armv7 - optimized FFMPEG with HW Acceleration


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

Last edited by abga; 09-05-2017 at 04:24 PM. Reason: completion & x264 compilation fix - missed FFmpeg extraction command
 
Old 08-24-2017, 03:54 PM   #2
abga
Member
 
Registered: Jul 2017
Location: EU
Distribution: Slackware x86 & ARM
Posts: 108

Original Poster
Rep: Reputation: 26
There were some issues with the compilation of the latest X264 libs git snapshot, discussed here:
https://www.linuxquestions.org/quest...-a-4175612536/

By looking in my archives I found the older X264 git commit 72d53ab2ac7af24597a824e868f2ef363a22f5d4 that builds perfectly and amended the above how-to accordingly.
It should be all fine now!

Feel free to provide any feedback or "annoy" me with your questions in case you're getting stuck somewhere
Always happy to help!

Last edited by abga; 08-24-2017 at 06:02 PM. Reason: Issue Resolved - Reformulating
 
Old 08-25-2017, 12:34 PM   #3
PELinux64
LQ Newbie
 
Registered: Aug 2017
Distribution: Ubuntu
Posts: 9

Rep: Reputation: Disabled
Excellent write-up, saved me a lot of time. I'm trying to get this working on my 64-bit ARMv8 build of Xubuntu.

http://privacyenhanced.blogspot.com/
 
Old 08-30-2017, 06:44 PM   #4
abga
Member
 
Registered: Jul 2017
Location: EU
Distribution: Slackware x86 & ARM
Posts: 108

Original Poster
Rep: Reputation: 26
Raspberry Pi3 Addendum


If you own a Raspberry Pi3 then you might want to go through the How-To from above, follow the instructions for pi2 and only change the compiler flags (wherever you find them) from:

-march=armv7-a -mtune=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard

to:

-march=armv8-a+crc -mtune=cortex-a53 -mfpu=neon-fp-armv8 -mfloat-abi=hard

I don't own a Pi3, waiting for Pi4, but these compiler flags are supported by the actual Slack ARM - current HF and I was able to generate usable code (running on armv7) with them.
For example, the resulting binaries should look like this (readelf -A output):

Attribute Section: aeabi
File Attributes
Tag_CPU_name: "8-A"
Tag_CPU_arch: v8
Tag_THUMB_ISA_use: Thumb-2
Tag_FP_arch: FP for ARMv8
Tag_Advanced_SIMD_arch: NEON for ARMv8
Tag_ABI_VFP_args: VFP registers

Last edited by abga; 09-03-2017 at 04:07 AM. Reason: shorter format
 
Old 09-03-2017, 04:13 AM   #5
abga
Member
 
Registered: Jul 2017
Location: EU
Distribution: Slackware x86 & ARM
Posts: 108

Original Poster
Rep: Reputation: 26
Pulseaudio Audio Analog Out - FFMPEG -Addendum

Pulseaudio can also make use of the optimized FFMPEG, lower CPU usage, and the quality of the output is better.
To use the ffmpeg decoding engine for your pulseaudio do the following:
- as root stop the pulseaudio daemon
pulseaudio -k

- edit the file /etc/pulse/daemon.conf file, comment (with ; ) your original corresponding records and insert these ones:
resample-method = ffmpeg
enable-remixing = no
enable-lfe-remixing = no

flat-volumes = no
default-sample-format = s16le
default-sample-rate = 44100
default-sample-channels = 2

- as root start the pulseaudio daemon
pulseaudio -D
 
1 members found this post helpful.
Old 09-14-2017, 08:21 AM   #6
abga
Member
 
Registered: Jul 2017
Location: EU
Distribution: Slackware x86 & ARM
Posts: 108

Original Poster
Rep: Reputation: 26
There's a new version of FFmpeg just released for Kodi 17.4. I'd suggest to use this new version instead of the older one from the how-to.

I'm not able to edit my first post anymore (weird) and cannot update the new instructions:
Code:
wget https://github.com/xbmc/FFmpeg/archive/3.1.9-Krypton-17.4.tar.gz
tar -xzpf 3.1.9-Krypton-17.4.tar.gz
cd FFmpeg-3.1.9-Krypton-17.4/

Last edited by abga; 09-16-2017 at 02:25 PM.
 
Old 11-04-2017, 05:19 PM   #7
abga
Member
 
Registered: Jul 2017
Location: EU
Distribution: Slackware x86 & ARM
Posts: 108

Original Poster
Rep: Reputation: 26
New FFmpeg release available with plenty of bugfixes:
Code:
wget https://github.com/xbmc/FFmpeg/archive/3.1.11-Krypton-17.5.tar.gz
 
Old 11-16-2017, 02:25 PM   #8
abga
Member
 
Registered: Jul 2017
Location: EU
Distribution: Slackware x86 & ARM
Posts: 108

Original Poster
Rep: Reputation: 26
A general rule to get the latest FFmpeg Version - download the latest Kodi release source code archive and check the file FFMPEG-VERSION from the tools/depends/target/ffmpeg/ subdirectory.
- follow the Kodi guide from here:
https://www.linuxquestions.org/quest...2/#post5759079

For example on Kodi 17.6:
/xbmc-17.6-Krypton/tools/depends/target/ffmpeg/FFMPEG-VERSION
Code:
LIBNAME=ffmpeg
BASE_URL=https://github.com/xbmc/FFmpeg/archive
VERSION=3.1.11-Krypton-17.5
ARCHIVE=$(LIBNAME)-$(VERSION).tar.gz
GNUTLS_VER=3.4.14
Then use the version number you learned to build the link and get FFmpeg:
Code:
wget https://github.com/xbmc/FFmpeg/archive/3.1.11-Krypton-17.5.tar.gz

Last edited by abga; 11-16-2017 at 02:26 PM. Reason: typo
 
Old 11-16-2017, 02:43 PM   #9
stormtracknole
Member
 
Registered: Aug 2005
Location: The Big Easy
Distribution: Slackware, RHEL
Posts: 968

Rep: Reputation: 124Reputation: 124
So if I understand correctly, I would just need to add:
Code:
export LDFLAGS="-L /opt/vc/lib/"
to the ffmpeg.SlackBuild in order to produce a hardware accelerated ffmpeg package? I'm assuming that the same could be done for vlc? Thank you for the work that you have done.
 
Old 11-16-2017, 05:19 PM   #10
abga
Member
 
Registered: Jul 2017
Location: EU
Distribution: Slackware x86 & ARM
Posts: 108

Original Poster
Rep: Reputation: 26
@stormtracknole

I'm afraid that by just pointing the compilation of FFmpeg to link to the precompiled and optimized for RaspberryPi MESA libs (specifically libEGL.so & libGLESv2.so) with:
Code:
export LDFLAGS="-L /opt/vc/lib/"
won't be enough. There are some other dependencies you need to provide FFmpeg with and there are some ARM platform specific compiler flags to optimize and make use of these dependencies and CPU acceleration (NEON instructions) too. For Pi2 these are:
Code:
--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'--enable-mmal --enable-hwaccel=h264_mmal --enable-neon --enable-libx264
I wasn't using any Slack.Build for inspiration and only referred to AlienBob's FFmpeg.SlackBuild for the ones who might search for more functions / devices support than what I've documented and need some inspiration on the capabilities of FFmpeg (configuration directives). I've been focusing only on performance, that's HW accelerated playback and recording of MPEG2 & MPEG4 and ARM (Raspberry Pi) platform optimization.

I struggled to get Kodi compiled for Raspberry Pi and while Kodi itself builds (should) FFmpeg internally it always failed under Slackware. Finally I studied the FFmpeg build script from Kodi (together with some google search) and got successful in compiling it on its own and documented the process here. I'm sorry for not creating a Slack.Build for it, I don't have time, I never used myself Slack.Builds apart from Kodi (inspiration) and lately LibreOffice (no offense - appreciate the work that's been put in them but I configure/compile for my specific needs) and finally I don't need a Slack.Build for issuing 4 commands to build FFmpeg (excluding the dependencies).

On VLC, I've used it a long time ago on Windows, then on Android for listening to music and while I liked it mainly because of its features richness, on the optimization side it was really bad and as far as I remember it had some proprietary encoding/decoding engines. I'm not sure if you want to compile it to use the RaspberryPi MESA libs from /opt/vc/lib or just point it (configure) to use an optimized (this one) FFmpeg as a decoding/encoding engine.

Last edited by abga; 11-16-2017 at 05:24 PM. Reason: bad bad English
 
2 members found this post helpful.
Old 11-17-2017, 09:38 AM   #11
stormtracknole
Member
 
Registered: Aug 2005
Location: The Big Easy
Distribution: Slackware, RHEL
Posts: 968

Rep: Reputation: 124Reputation: 124
Quote:
Originally Posted by abga View Post
@stormtracknole

I'm afraid that by just pointing the compilation of FFmpeg to link to the precompiled and optimized for RaspberryPi MESA libs (specifically libEGL.so & libGLESv2.so) with:
Code:
export LDFLAGS="-L /opt/vc/lib/"
won't be enough. There are some other dependencies you need to provide FFmpeg with and there are some ARM platform specific compiler flags to optimize and make use of these dependencies and CPU acceleration (NEON instructions) too. For Pi2 these are:
Code:
--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'--enable-mmal --enable-hwaccel=h264_mmal --enable-neon --enable-libx264
I wasn't using any Slack.Build for inspiration and only referred to AlienBob's FFmpeg.SlackBuild for the ones who might search for more functions / devices support than what I've documented and need some inspiration on the capabilities of FFmpeg (configuration directives). I've been focusing only on performance, that's HW accelerated playback and recording of MPEG2 & MPEG4 and ARM (Raspberry Pi) platform optimization.

I struggled to get Kodi compiled for Raspberry Pi and while Kodi itself builds (should) FFmpeg internally it always failed under Slackware. Finally I studied the FFmpeg build script from Kodi (together with some google search) and got successful in compiling it on its own and documented the process here. I'm sorry for not creating a Slack.Build for it, I don't have time, I never used myself Slack.Builds apart from Kodi (inspiration) and lately LibreOffice (no offense - appreciate the work that's been put in them but I configure/compile for my specific needs) and finally I don't need a Slack.Build for issuing 4 commands to build FFmpeg (excluding the dependencies).

On VLC, I've used it a long time ago on Windows, then on Android for listening to music and while I liked it mainly because of its features richness, on the optimization side it was really bad and as far as I remember it had some proprietary encoding/decoding engines. I'm not sure if you want to compile it to use the RaspberryPi MESA libs from /opt/vc/lib or just point it (configure) to use an optimized (this one) FFmpeg as a decoding/encoding engine.
Thank you so much for the explanation. I may have to give this a try on a slow day.
 
Old 11-18-2017, 10:08 AM   #12
abga
Member
 
Registered: Jul 2017
Location: EU
Distribution: Slackware x86 & ARM
Posts: 108

Original Poster
Rep: Reputation: 26
@stormtracknole
It shouldn't take you more than 1 hour (including deps) if you follow the instructions and compile on a Pi2/Pi3.
I wrote some extra details/explanations just to give a technical background and share some of the stuff I learned myself.

It looks like VLC can work with FFmpeg but it needs to get built to support&use it (configure directive --enable-ffmpeg ):
https://wiki.videolan.org/Configure/
https://wiki.videolan.org/FFmpeg/
https://stackoverflow.com/questions/...works-together

Here, while not Slackware specific and with a ton of dependencies, they compile VLC to use the OpenMAX HW acceleration and not an optimized FFmpeg:
https://thepi.io/how-to-compile-vlc-...-raspberry-pi/
I just noticed that they are not enabling de-interlacing in the video configuration section and I fear that VLC is not that well performing (taking too many resources) after all.

I was myself looking for a Media Player on Raspberry and considered Kodi to be the best in both quality & performance. Unfortunately you cannot have it running under X but only standalone (and that's because of the MESA libs).
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Slackware ARM on a Raspberry Pi 2 Exaga Slackware - ARM 28 05-06-2015 07:42 AM
LXer: Raspberry Pi 2: Raspbian (ARMv6) v Linaro (ARMv7) LXer Syndicated Linux News 0 03-15-2015 05:20 PM
Slackware ARM 14.1 on a Raspberry Pi Exaga Slackware - Installation 2 11-17-2013 09:11 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware > Slackware - ARM

All times are GMT -5. The time now is 01:49 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration