Page 1 of 1

Right way to compile libx264

Posted: Sun Jun 24, 2012 9:08 am
by Andrey V
Hello!
I'm trying to encode video from webcam on Debian Wheezy with ffmpeg. And it works fine with any video codec but libx264. When i use libx264 all i get is:

Code: Select all

ffmpeg -y -f video4linux2 -s 320x240 -r 1 -i /dev/video0 -r 1 -vcodec libx264 -s 320x240 -b:v 50K -f mp4 /tmp/test.mp4
ffmpeg version git-2012-06-21-9e63c30 Copyright (c) 2000-2012 the FFmpeg developers
  built on Jun 24 2012 02:22:41 with gcc 4.6.3
  configuration: --enable-gpl --enable-libfaac --enable-libmp3lame --enable-libx264 --enable-nonfree --enable-version3 --enable-librtmp
  libavutil      51. 59.100 / 51. 59.100
  libavcodec     54. 29.100 / 54. 29.100
  libavformat    54. 10.100 / 54. 10.100
  libavdevice    54.  0.100 / 54.  0.100
  libavfilter     2. 82.100 /  2. 82.100
  libswscale      2.  1.100 /  2.  1.100
  libswresample   0. 15.100 /  0. 15.100
  libpostproc    52.  0.100 / 52.  0.100
[video4linux2,v4l2 @ 0x12a4510] The driver changed the time per frame from 1/1 to 1/5
[video4linux2,v4l2 @ 0x12a4510] Estimating duration from bitrate, this may be inaccurate
Input #0, video4linux2,v4l2, from '/dev/video0':
  Duration: N/A, start: 227240.304332, bitrate: 6144 kb/s
    Stream #0:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 320x240, 6144 kb/s, 5 tbr, 1000k tbn, 5 tbc
[buffer @ 0x12aaf70] w:320 h:240 pixfmt:yuyv422 tb:1/1 fr:1/1 sar:0/1 sws_param:flags=2
[ffmpeg_buffersink @ 0x12a02c0] No opaque field provided
[buffer @ 0x12aaf70] TB:1.000000
[scale @ 0x12a08d0] w:320 h:240 fmt:yuyv422 sar:0/1 -> w:320 h:240 fmt:yuv422p sar:0/1 flags:0x4
Illegal instruction
(code above works perfectly on x86)


As i understand it happens beacuse of absense of NEON, so i tried to recompile
libx264 with --disable-asm then ffmpeg, but result is the same.

So appearently there missing something else. But what?

Re: Right way to compile libx264

Posted: Mon Jun 25, 2012 7:04 am
by saintdev
I haven't tried compiling x264, but it should be fairly trivial without asm and with some extra cflags/ldflags.

For ffmpeg/libav I would suggest starting with what I have below and appending whatever extra switches you need after. The cflags/ldflags are optional, but should help performance in floating point code (most of what you want in libav is integer, so it probably won't help much).

Code: Select all

./configure --arch=armv6zk --cpu=arm1176jzf-s --extra-cflags="-mfloat-abi=softfp -mfpu=vfp" --extra-ldflags="-mfloat-abi=softfp -mfpu=vfp"
For x264 I would try starting with something like the following (I have not tested this, so ymmv). The float-abi and fpu options are mostly useless here, there is even less floating point math than libav, but it shouldn't hurt.

Code: Select all

./configure --disable-asm --extra-cflags="-mcpu=armv6zk -march=arm1176jzf-s -marm -mfloat-abi=softfp -mfpu=vfp" --extra-ldflags="-mcpu=armv6zk -march=arm1176jzf-s -marm -mfloat-abi=softfp -mfpu=vfp"
NOTE: I have run FATE (libav's automated testing suite) and there are quite a few failures (largest being most of the VP8 tests fail).

Re: Right way to compile libx264

Posted: Mon Jun 25, 2012 1:00 pm
by AndrewS
saintdev wrote:The cflags/ldflags are optional, but should help performance in floating point code (most of what you want in libav is integer, so it probably won't help much).

Code: Select all

./configure --arch=armv6zk --cpu=arm1176jzf-s --extra-cflags="-mfloat-abi=softfp -mfpu=vfp" --extra-ldflags="-mfloat-abi=softfp -mfpu=vfp"
Or you could use Rasbian which allows you to make use of hardfloat :)

Re: Right way to compile libx264

Posted: Tue Jun 26, 2012 12:36 pm
by Andrey V
Thank you for advices!

I'll post back with right config when i get positive results.

Re: Right way to compile libx264

Posted: Wed Jun 27, 2012 3:43 pm
by Andrey V
After numerous fails and hours of waiting (2-4 hours per build) i decided to follow the advice of AndrewS and switched to raspbian, installed there libx264-dev and build ffmpeg without any optimisation. And it works!

Too bad i didn't found good way to build it on pure debian but it doesn't matter since there is better Raspbian with other optimisations.

Re: Right way to compile libx264

Posted: Thu Jun 28, 2012 1:39 am
by AndrewS
IMHO Raspbian is no less "pure Debian" than any of the other Pi-Debian-distros. Only difference is that the repository isn't stored on debian.org

Re: Right way to compile libx264

Posted: Tue Jul 17, 2012 9:58 pm
by tekmanro
Hi,

I was wondering if you got this working, what are the perf characteristics of the software x264 encode? How far can you go in terms of resolution / fps? I suspect full 1080p/30fps is out of the question on 700Mhz, but what about 720p?

Thanks!

Re: Right way to compile libx264

Posted: Wed Jul 18, 2012 12:18 am
by AndrewS
I haven't tried it myself, but I can't see any reason why you couldn't software encode 1080p/30? It'll just be very slow...

Apparently when the camera add-on gets released, that'll somehow "unlock" the hardware x264 encoder, which is fast enough to do real-time FullHD.

Re: Right way to compile libx264

Posted: Wed Jul 18, 2012 2:05 am
by tekmanro
Hmm, I guess I should have rephrased that. What is the maximum resolution I can use to real-time encode a video stream from a web camera?

I assume software only, since the hardware encoder is not currently enabled due to licensing issues.

Re: Right way to compile libx264

Posted: Wed Jul 18, 2012 11:28 am
by AndrewS
Well, that's a very different question ;)
Given the limited CPU on the RPi, I suspect for any real-time software video encoding you'll have to choose a less compressed format than x264. I've seen several posts mentioning MJPEG?

Re: Right way to compile libx264

Posted: Mon Dec 02, 2013 2:48 am
by khisraw
Can I ask guys if ffmpeg or libav development packages are pre installed on the RPi or you need to install them?