NEON optimised ffmpeg build fatal error: must enable NEON

This forum is for discussion about general software issues.

NEON optimised ffmpeg build fatal error: must enable NEON

Postby smilerish » Sat Sep 18, 2021 3:36 pm

Hi all,

I hope this is the right forum.

I'm trying to build a customised ffmpeg-headless package on an rPi2, optimised for the Cortex package of the rPi2.

I have the following $CFLAGS in makepkg.conf:
$this->bbcode_second_pass_code('', 'CFLAGS="-mcpu=cortex-a7 -mfloat-abi=hard -mfpu=neon-vfpv4 -O4 -pipe -fstack-protector-strong -fno-plt -fexceptions -Wp,-D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -fstack-clash-protection"')
As I understand it, this is the correct combination of flags for optimised builds for the rPi2.

At first, I was getting lots of compiler warning about conflicting optimisation flags:
$this->bbcode_second_pass_code('', 'cc1: warning: switch ‘-mcpu=cortex-a7’ conflicts with ‘-march=armv7-a’ switch')
It seems that the ffmpeg configure script sets its own -march flag, regardless of what's in the environment $CFLAGS. So I added the following line to the PKGBUILD, as part of the configure line in build():
$this->bbcode_second_pass_code('', '$([[ $CFLAGS =~ -mcpu=([^ ]+) ]] && echo "--cpu=${BASH_REMATCH[1]}") \')
This explicitly tells the ffmpeg configure script which -mcpu to use, so it no longer adds -march to the compiler call. So no more errors about conflicting switches - great!

Except now I'm getting this error during the build:
$this->bbcode_second_pass_code('', '/usr/lib/gcc/armv7l-unknown-linux-gnueabihf/10.2.0/include/arm_neon.h:6635:10: fatal error: You must enable NEON instructions (e.g. ‘-mfloat-abi=softfp’ ‘-mfpu=neon’) to use these intrinsics.')

And I'm stumped! My $CFLAGS includes both -mfloat-abi=hard (which should be compatible with NEON) and -mfpu=neon-vfpv4. The only thing I can think is that these flags are somehow not being passed to the compiler (specifically, lto1 which is what is running when this error occurs), but I can't work out how to check that. Googling the error (in relation to ffmpeg) has been a dead-end.

Does anyone familiar with ffmpeg's configure/build system have some ideas? Or any suggestions on how else to diagnose the problem?

NB: I'm compiling locally/natively. Other than for troubleshooting this problem, the length of time compiling doesn't bother me and I've not taken the time to get my head around distcc cross-compiling yet (though I'm sure I will at some point!).

TIA
smilerish
 
Posts: 8
Joined: Wed Jan 06, 2021 12:25 pm

Re: NEON optimised ffmpeg build fatal error: must enable NEO

Postby graysky » Sat Sep 18, 2021 5:34 pm

Not sure about your error but as an aside: you just want to specify -mpcu=

Ref: https://community.arm.com/developer/too ... e-and-mcpu
graysky
Developer
 
Posts: 1727
Joined: Sun Jun 26, 2011 6:56 am
Location: /run/user/1000

Re: NEON optimised ffmpeg build fatal error: must enable NEO

Postby smilerish » Sat Sep 18, 2021 5:58 pm

$this->bbcode_second_pass_quote('graysky', 'y')ou just want to specify -mpcu=

Yes, that's what I've done. The problem I encountered is that ffmpeg's configure script adds its own -march switch. As I explained in the OP, I found a way to override that by passing an explicit -cpu switch to the configure script.
smilerish
 
Posts: 8
Joined: Wed Jan 06, 2021 12:25 pm

Re: NEON optimised ffmpeg build fatal error: must enable NEO

Postby smilerish » Sat Sep 18, 2021 6:01 pm

Just to add...

I've tried adding the following to the PKGBUILD, as an additional argument to the configure script:
$this->bbcode_second_pass_code('', '--extra-cflags="$CFLAGS" \')

And it made no difference - the compilation failed in the same way as before.
smilerish
 
Posts: 8
Joined: Wed Jan 06, 2021 12:25 pm

Re: NEON optimised ffmpeg build fatal error: must enable NEO

Postby graysky » Sat Sep 18, 2021 6:20 pm

$this->bbcode_second_pass_quote('smilerish', '')$this->bbcode_second_pass_quote('graysky', 'y')ou just want to specify -mpcu=

Yes, that's what I've done. The problem I encountered is that ffmpeg's configure script adds its own -march switch. As I explained in the OP, I found a way to override that by passing an explicit -cpu switch to the configure script.


Here is how I work around that in the kodi package which uses a patch ffmpeg for hardware decoding:
https://github.com/archlinuxarm/PKGBUIL ... tune.patch

That is applied to the ffmpeg internal code prior to building (kodi's CMAKE).
graysky
Developer
 
Posts: 1727
Joined: Sun Jun 26, 2011 6:56 am
Location: /run/user/1000
Top

Re: NEON optimised ffmpeg build fatal error: must enable NEO

Postby smilerish » Mon Sep 20, 2021 8:54 am

I've made some progress with this.

I managed to find this report of the same problem (different package) and realised that the fault definitely lies with the linker when 'link time optimisation' is enabled (--enable-lto for ffmpeg configure). So for the time being, I've got ffmpeg to build by not enabling LTO.

I suspect the real fix is to somehow pass the correct arguments to the linker, but I've not explored that yet.
smilerish
 
Posts: 8
Joined: Wed Jan 06, 2021 12:25 pm

Re: NEON optimised ffmpeg build fatal error: must enable NEO

Postby armuseru » Fri Sep 24, 2021 5:42 am

Inspecting ./configure at ffmpeg source dir, shows that it has --cpu= --extra-cflags= --extra-cxxflags= --optflags= parameters, so you can directly set it like
$this->bbcode_second_pass_code('', ' flags=" -mcpu=cortex-a7 -mfpu=neon --param l1-cache-size=64 --param l2-cache-size=1024 -O3 -fPIC "
./configure \
--cpu=cortex-a7 \
--extra-cflags="$flags" \
--extra-cxxflags="$flags" \
--optflags="$flags" ')
an so on (cache sizes as example i do not know it for rpi2)

While building ffmpeg ./configure says:

$this->bbcode_second_pass_code('', 'ARCH arm (armv7-a)
big-endian no
runtime cpu detection yes
ARMv5TE enabled yes
ARMv6 enabled yes
ARMv6T2 enabled yes
VFP enabled yes
NEON enabled yes
THUMB enabled no
debug symbols no
strip symbols no
optimize for size no
optimizations yes
static no')
but afrer installing a new recompiled ffmpeg i still got
$this->bbcode_second_pass_code('', '
ffmpeg -to 1s -i test.mkv -f mp4 -y /dev/null 2>&1 | grep cpu
[libx264 @ 0x81e640] using cpu capabilities: none!

cat /proc/cpuinfo | grep neon -m 1
Features : half thumb fastmult vfp edsp thumbee neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm')
Probably some cpu features detection bug.

As for paper https://community.arm.com/developer/too ... e-and-mcpu I am not sure that it totally right. I tried to force everywhere -mcpu=cortex-a15 and remove -march parameters from PKGBUILD and /etc/makepkg.conf. Then tryed to compile linux kernel and I got assembler errors and compilation fail.
armuseru
 
Posts: 34
Joined: Sat Jan 09, 2021 9:36 am

Re: NEON optimised ffmpeg build fatal error: must enable NEO

Postby smilerish » Fri Sep 24, 2021 8:22 am

$this->bbcode_second_pass_quote('armuseru', 'I')nspecting ./configure at ffmpeg source dir, shows that it has --cpu= --extra-cflags= --extra-cxxflags= --optflags= parameters

Yes, I said in the OP that I've used ffmpeg's --cpu= flag to override its internal architecture detection. The --extra-c(xx)flags= aren't needed in my case: the $C(XX)FLAGS environment variables are still used by ffmpeg make (mine are already customised in makepkg.conf).

$this->bbcode_second_pass_quote('armuseru', '
')but afrer installing a new recompiled ffmpeg i still got
$this->bbcode_second_pass_code('', '
ffmpeg -to 1s -i test.mkv -f mp4 -y /dev/null 2>&1 | grep cpu
[libx264 @ 0x81e640] using cpu capabilities: none!')

I noticed this, too. On my system at least, libx264 is installed as a dependency to ffmpeg - it's not compiled as part of the ffmpeg compilation. I just tried running x264 and got the same message.

Looking at the configure script for x264, it has the following lines where it detects CPU features:
$this->bbcode_second_pass_code('', 'echo "You specified a pre-ARMv6 or Thumb-1 CPU in your CFLAGS."
echo "If you really want to run on such a CPU, configure with --disable-asm."')
And yet, when I look at the alarm PKBUILD for x264, it uses the --disable-asm for all non-aarch64 processors. So that would explain why x264 isn't being built with arm6, vfp3 and neon support.

I've just recompiled x264 after removing the aarch64 detection line from the PKGBUILD, and now I get the following message when I run x264:
$this->bbcode_second_pass_code('', 'x264 [info]: using cpu capabilities: ARMv6 NEON')
So that's progress!

I've also just found this article, that suggests that $C(XX)FLAGS should be added to $LDFLAGS when using LTO. I suspected this was the case, but I haven't seen it documented elsewhere. I might try that to see if it will build with LTO.
smilerish
 
Posts: 8
Joined: Wed Jan 06, 2021 12:25 pm
Top

Re: NEON optimised ffmpeg build fatal error: must enable NEO

Postby armuseru » Sun Oct 03, 2021 4:04 pm

So I can confirm that recompilation ( with commented [[ $CARCH != "aarch64" ]] )and subsequent installation of x264 further similarly with ffmpeg gave me next
$this->bbcode_second_pass_code('', 'ffmpeg -to 1s -i test.mkv -f mp4 -y /dev/null 2>&1 | grep cpu
[libx264 @ 0x1c0be10] using cpu capabilities: ARMv6 NEON
')
armuseru
 
Posts: 34
Joined: Sat Jan 09, 2021 9:36 am


Return to General

Who is online

Users browsing this forum: No registered users and 4 guests