#973 closed enhancement (fixed)
libyuv colourspace conversion
Reported by: | Antoine Martin | Owned by: | Smo |
---|---|---|---|
Priority: | blocker | Milestone: | 0.17 |
Component: | encodings | Version: | 0.15.x |
Keywords: | Cc: |
Description
libyuv is Optimized for SSE2/SSSE3/AVX2 on x86/x64. and it is packaged in Fedora: libyuv pkgdb entry
It could compete with ffmpeg on speed, sadly scaling requires a separate step.
Attachments (2)
Change History (15)
comment:1 Changed 5 years ago by
Status: | new → assigned |
---|
comment:2 Changed 5 years ago by
Owner: | changed from Antoine Martin to Smo |
---|---|
Status: | assigned → new |
r11647 adds support for scaling and improves the tests to measure the performance.
Scaling costs us about 10 to 20%, and swscale is a lot more competitive when scaling is involved.
I have also tested the size limits of this csc mode, and it can scale past 32kx32k which will be helpful for #969.
@smo:
- please record CSC performance data on a reference system (Xeon?), also for #926 - and maybe someone can generate some pretty graphs to visually verify the differences - as it is, libyuv should win the video pipeline scoring system because it has a lower "setup cost" than all the other csc modules (set to zero because we don't need any setup at all apart from instantiating our Cython adapter class!)
- try the osx and win32 builds: you can probably ask for help on the "unusual" chromium build system (I do plan to use libyuv client side, see patch, which will be useful for opengl-challenged systems like OSX + Intel cards)
- then re-assign to afarr for testing / some testing can be done in parallel already but the ticketing system does not have this option
For testing:
- verify that it is installed and gets loaded, using the codec loader (
xpra/codecs/loader.py
/Encoding_info.exe
) and video helper (xpra/codecs/video_helper.py
) test classes - start the server with
--csc-modules=libyuv
(we only use libyuv for RGB to yuv, so it only gets used on the server) and verify that it gets used:xpra info | grep csc
- maybe force downscaling to exercise that code:
XPRA_SCALING_HARDCODED=1:2 xpra start ...
, or just make the scaling more aggressive:xpra start --video-scaling=100 ...
- the downscaling should be visible fromxpra info | grep csc
. - try to break it, look for memory leaks, visual corruption, etc
comment:3 Changed 5 years ago by
Priority: | major → critical |
---|
I have figured out the win32 build, as as of r11874 you just do:
cd libyuv-r1446 mkdir out cd out cmake .. -G "Visual Studio 9 2008"
Then build the solution with the visual studio 9 GUI (or directly with nmake? should work too).
Note: I changed from "debug" to "Release" build before building.
If building for Python 3, we should probably use a new Visual Studio version... but the "Xpra-Build-Libs" directory structure is not version specific. Maybe it should be.
Talking about which, you have to place the files where our build system will find them, ie for me:
E:\Xpra-Build-Libs\ libyuv\ bin\ convert.exe lib\ yub.lib include\ libyuv.h libyuv\ *.h
The OSX build is more problematic, first you have to install cmake (that's easy), then it fails with:
libyuv-r1446/source/row_gcc.cc: In function 'void libyuv::ARGBToUVRow_SSSE3(const uint8*, int, uint8*, uint8*, int)': libyuv-r1446/source/row_gcc.cc:886: error: can't find a register in class 'GENERAL_REGS' while reloading 'asm' libyuv-r1446/source/row_gcc.cc:886: error: 'asm' operand has impossible constraints
Because of this gcc bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=11203.
The workaround:
LDFLAGS="-read_only_relocs suppress" \ CXXFLAGS="-march=i686 -O3 -fno-pic -fomit-frame-pointer -frename-registers -pipe" \ cmake -DCMAKE_INSTALL_PREFIX:PATH=$PREFIX ..
It's ugly and uses -fno-pic
... but at least it builds. (this is not problem with 64-bit builds)
Then you need to generate and install the pkgconfig file attached to this ticket since libyuv does not provide a template.
But it still fails because of the text relocs, and adding the flag to the compiler options does not help:
creating build/temp.macosx-10.5-i386-2.7/xpra/codecs/csc_libyuv /usr/bin/gcc-4.2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -arch i386 -I/Developer/SDKs/MacOSX10.5.sdk/usr/include \ -isysroot /Developer/SDKs/MacOSX10.5.sdk -mmacosx-version-min=10.5 -I/Users/osx/gtk/inst/include -arch i386 \ -I/Developer/SDKs/MacOSX10.5.sdk/usr/include -isysroot /Developer/SDKs/MacOSX10.5.sdk -I/Users/osx/gtk/inst/include/python2.7 \ -c xpra/codecs/csc_libyuv/colorspace_converter.cpp -o build/temp.macosx-10.5-i386-2.7/xpra/codecs/csc_libyuv/colorspace_converter.o \ -Wall -fPIC -read_only_relocs suppress cc1plus: warning: command line option "-Wstrict-prototypes" is valid for C/ObjC but not for C++ /Developer/usr/bin/g++-4.2 -bundle -undefined dynamic_lookup \ -L/Users/osx/gtk/inst/lib -L/Users/osx/gtk/inst/lib -arch i386 -L/Developer/SDKs/MacOSX10.5.sdk/usr/lib \ -isysroot /Developer/SDKs/MacOSX10.5.sdk -mmacosx-version-min=10.5 -Wl,-headerpad_max_install_names \ -L/Users/osx/gtk/inst/lib -L/Users/osx/gtk/inst/lib -arch i386 -L/Developer/SDKs/MacOSX10.5.sdk/usr/lib \ -isysroot /Developer/SDKs/MacOSX10.5.sdk -mmacosx-version-min=10.5 -Wl,-headerpad_max_install_names -arch i386 \ -I/Developer/SDKs/MacOSX10.5.sdk/usr/include -isysroot /Developer/SDKs/MacOSX10.5.sdk -mmacosx-version-min=10.5 \ -I/Users/osx/gtk/inst/include -arch i386 -I/Developer/SDKs/MacOSX10.5.sdk/usr/include -isysroot /Developer/SDKs/MacOSX10.5.sdk \ build/temp.macosx-10.5-i386-2.7/xpra/codecs/csc_libyuv/colorspace_converter.o -L/Users/osx/gtk/inst/lib \ -lyuv -o build/lib.macosx-10.5-i386-2.7/xpra/codecs/csc_libyuv/colorspace_converter.so -Wall -read_only_relocs suppress ld: absolute addressing (perhaps -mdynamic-no-pic) used in _GetARGBBlend from /Users/osx/gtk/inst/lib/libyuv.a(planar_functions.cc.o) \ not allowed in slidable image. Use '-read_only_relocs suppress' to enable text relocs
And at this point I give up. We'll enable libyuv when we get 64-bit builds.
comment:4 Changed 5 years ago by
Owner: | changed from Smo to Antoine Martin |
---|---|
Status: | new → assigned |
Not sure why I am only seeing this now, but I get reliable crashes with a different user over tcp with vp8 and d-feet as client app:
2016-03-13 11:13:46,179 libyuv.ColorspaceConverter.init_context(499, 316, 'BGRX', 499, 316, 'YUV420P', 48) 2016-03-13 11:13:46,180 buffer size=243712, scaling=0, filtermode=None 2016-03-13 11:13:46,183 libyuv.ARGBToI420 took 0.2ms 2016-03-13 11:13:46,188 YUVImageWrapper.free() cython_buffer=0x7fbc883ee220 2016-03-13 11:13:46,188 YUVImageWrapper.free() cython_buffer=0x0 2016-03-13 11:13:49,606 libyuv.ColorspaceConverter.init_context(499, 311, 'BGRX', 499, 311, 'YUV420P', 38) 2016-03-13 11:13:49,606 buffer size=239616, scaling=0, filtermode=None 2016-03-13 11:13:49,609 libyuv.ARGBToI420 took 0.3ms 2016-03-13 11:13:49,616 YUVImageWrapper.free() cython_buffer=0x7fbc887e6050 *** Error in `/bin/python': double free or corruption (!prev): 0x00007fbc887e6050 *** ======= Backtrace: ========= /lib64/libc.so.6(+0x77da5)[0x7fbcc256dda5] /lib64/libc.so.6(+0x804fa)[0x7fbcc25764fa] /lib64/libc.so.6(cfree+0x4c)[0x7fbcc2579cac] /usr/lib64/python2.7/site-packages/xpra/codecs/csc_libyuv/colorspace_converter.so(+0xdbaf)[0x7fbc92983baf]
comment:5 Changed 5 years ago by
Priority: | critical → blocker |
---|
The crash only occurs with the vpx codec (happens with both with vp8 and vp9)... h264, and mpeg4 are not affected when using the exact same csc (using XPRA_FORCE_CSC_MODE=YUV420P
for x264)
But the libyuv code looks fine, and temporarily removing all calls to free() the memory does not help!?
Raising. This may require using valgrind (oh noes).
comment:6 Changed 5 years ago by
Owner: | changed from Antoine Martin to Smo |
---|---|
Status: | assigned → new |
Summary: | libyuv support as a better fallback than the cython module → libyuv colourspace conversion |
I cannot reproduce the problem on an Intel system, maybe it was a bad build somehow, or maybe this crashes on a different setup. (was on an AMD CPU system)
valgrind didn't show anything even remotely suspicious.
@smo: back over to you, can you break it? if not, just record some performance stats.
comment:7 Changed 5 years ago by
Owner: | changed from Smo to Antoine Martin |
---|---|
Status: | new → assigned |
Hit it again, on Intel this time :(
comment:8 Changed 5 years ago by
Owner: | changed from Antoine Martin to Smo |
---|---|
Status: | assigned → new |
Turns out it's a trivial rounding error, fixed in r12303 - which I never hit because the tests used even dimensions, the bug only occurred with an odd input height.
(not sure why this fired more with vpx than x264! The memory corruption would affect any buffer allocated after this one)
comment:9 Changed 5 years ago by
Ran some of these tests on my machine to confirm libyuv is much faster here are my results
Intel(R) Xeon(R) CPU E5-2620 0 @ 2.00GHz
BGRX to YUV420P
CSC | 16x16 | 128x128 | 256x256 | 512x512 | 1920x1080 | 2560x1600 |
---|---|---|---|---|---|---|
cython | 11 | 60 | 64 | 64 | 61 | 62 |
swscale | 10 | 126 | 165 | 182 | 188 | 199 |
libyuv | 16 | 427 | 1039 | 1432 | 1743 | 1444 |
I will do more testing like mentioned in comment:2 to make sure there are no crashes and update this ticket if there is.
It is quite obvious that libyuv is much faster than the alternatives.
comment:10 Changed 5 years ago by
I haven't run across any issues on the server end in linux with this but I haven't got to compiling and bundling libyuv on win32 yet. I will get to this shortly and update the ticket if I find any issues.
comment:11 Changed 5 years ago by
Resolution: | → fixed |
---|---|
Status: | new → closed |
No issues building this on win32 following your instructions.
The command line way of building this is
msbuild Project.sln /p:Configuration=Release
comment:12 Changed 2 years ago by
comment:13 Changed 2 days ago by
this ticket has been moved to: https://github.com/Xpra-org/xpra/issues/973
Added preliminary support and packaging (Fedora only) in r11646, only for BGRX to YUV420P.
That thing is seriously fast. It beats the current record holder (ffmpeg's swscale) by a huge margin on 256x256 and up (this sort of size is pretty common for video).
On a somewhat old AMD FX 8150:
Still TODO: