PDA

View Full Version : Question about the x264 library


Sagekilla
3rd August 2008, 19:08
Is the x264 library compatible with MSVC? I was talking to manao about adding some new parameters to AVCMatrices so it has more functionality, and I wanted to take it upon myself to try adding them. The only issue that arose was whether or not I could compile the latest x264 library properly under MSVC.

LoRd_MuldeR
3rd August 2008, 19:13
No, you cannot compile libx264 wth MSVC or ICL, because the Assembly functions in x264 require an aligned stack.
Those compilers can't guarantee that, so you will encounter crash, unless you disable all Assembly code.

A fix has been committed a while ago:
http://git.videolan.org/gitweb.cgi?p=x264.git;a=commit;h=ad1d7a4a585bc7f995ced5152557a4f5306275bf

Now you should get a working DLL with MSVC/ICL, but it will run slooooooooow with all Assembly optimizations disabled.

Also note that you will need GCC 4.x.x to compile x264 as a DLL, because GCC 3.x.x doesn't respect "__attribute__((force_align_arg_pointer))".
But this attribute has to be added to the "x264_encoder_encode" function, if you want to use x264 as a DLL.
Otherwise you'll get crashes because of wrong alignment. AFAIK that's because the code outside the DLL doesn't keep the stack aligned...

akupenguin
3rd August 2008, 19:17
Note the commit message: "some asm functions require aligned stack". Not all. So it's only slow, not slooooooooow.
Otoh, note that x264 spends far more time in the state of having a broken msvc project file than a working one, since I don't care about msvc enough to even review other people's patches.

Dark Shikari
3rd August 2008, 19:19
No, you cannot compile libx264 wth MSVC or ICL, because the Assembly functions in x264 require an aligned stack.
Those compilers can't guarantee that, so you will encounter crash, unless you disable all Assembly code.Wrong, it'll automatically disable just the few functions that require an aligned stack. So you'll lose a bit of performance, but not a huge amount.

Also note that you will need GCC 4.x.x to compile x264 as a DLL, because GCC 3.x.x doesn't respect "__attribute__((force_align_arg_pointer))".
But this attribute has to be added to the "x264_encoder_encode" function, if you want to use x264 as a DLL.Since when? I'm pretty sure x264_stack_align does this for you regardless of how crappy your compiler is.

Sagekilla
3rd August 2008, 19:32
Ugh.. so I'll end up having a very slow, but featured version of x264 running then? Honestly, I'd rather have the new features at the cost of some speed because MSVC has to disable asm. What I want to do is add more of the x264 options so you can actually see how a frame is encoded with those particular settings in say, AvsP w/ AVCMatrices, before you actually go ahead with the encode..

It's not like I'll be attempting to do a video encode where the performance is needed, so if I lose some performance then that's fine, as long as the output is (more or less) like that of x264 when I output it from the CLI.

LoRd_MuldeR
3rd August 2008, 19:33
Wrong, it'll automatically disable just the few functions that require an aligned stack. So you'll lose a bit of performance, but not a huge amount.
Since when? I'm pretty sure x264_stack_align does this for you regardless of how crappy your compiler is.

You can try it easily. Compile libx264.dll with GCC 3.x.x and it will crash. Even when you put "__attribute__((force_align_arg_pointer))" before "x264_encoder_encode".
If you compile it with GCC 4.x.x it will work, but "__attribute__((force_align_arg_pointer))" is mandatory.

This was discussed a while ago and it's the solution Gruntster+MasterNobody came up with. So far it's the only working solution I'm aware of...

See: http://forum.doom9.org/showthread.php?p=1148167#post1148167

Dark Shikari
3rd August 2008, 19:43
Ugh.. so I'll end up having a very slow, but featured version of x264 running then? Honestly, I'd rather have the new features at the cost of some speed because MSVC has to disable asm.As I said, it only disables the few functions that require an aligned stack.

LoRd_MuldeR
3rd August 2008, 20:17
Sagekilla, is there a specific reason why you don't want to use MinGW GCC ???

Sagekilla
3rd August 2008, 20:25
The filter I'm editing, AVCMatrices, happened to be developed in MSVC++ so I figured I should use the same for updating the filter. However, I'll try compiling in GCC if it will work properly.

akupenguin
3rd August 2008, 20:27
I'm pretty sure x264_stack_align does this for you regardless of how crappy your compiler is.
The current use of x264_stack_align is sufficient for x264cli, when it is compiled entirely by gcc but invokes a pthread implementation that doesn't preserve alignment. It is not sufficient if you want to invoke libx264 from an exe compiled with non-gcc.
I am more likely to use __attribute__((force_align_arg_pointer)) and require gcc4.3, than to write a vararg version of x264_stack_align.

Sagekilla
3rd August 2008, 20:44
As long as the output from x264 will be (mostly) the same without the optimizations enabled, I'd be fine. Speed is hardly a concern for this filter seeing as it's meant for comparisons which don't require a lot of speed to be running.