gen2brain/x264-go

extlib on Ubuntu 20.04

kivutar opened this issue · 12 comments

I'm trying to use extlib on ubuntu 20.04, which uses x264 v155.

For this, I've updated the x264.h, encoder and common from the exact same version, v155 commit 0a84d98

I'm able to compile and link fine, but at runtime, when I initialize the encoder, I'm getting these two errors:

x264 [error]:  8-bit AVC-Intra is not widely compatible
x264 [error]: 10-bit x264 is required to encode AVC-Intra

So I took a look at the source, and tried adding this in x264c_cgo_extlib.go:

#cgo linux CFLAGS: -DX264_REV=2917 -DX264_REV_DIFF=0 -DX264_VERSION=" r2917 0a84d98" -DX264_POINTVER="0.155.2917 0a84d98" -DHAVE_BITDEPTH10=1 -DHIGH_BIT_DEPTH=1 -DBIT_DEPTH=10

But it doesn't seem to be enough. Any idea of what I could try next?

It is broken for some time (extlib tag), there are some incompatible changes with newer versions. Actually, not sure what is v155, I think they don't have releases, just master snapshots so it is hard to get it to work everywhere. What you can try is to compile the code in external/x264 and install instead of the system lib, build a static library, and link with that, that should work.

I tried recently to update C sources, but that needs more work, currently, I have issues with colors and I was hoping to remove the need for .syso files. Not sure when will I find time though.

I feel like we might need to expose a IBitDepth because there is i_bitdepth in the x264_param_t just between i_csp and i_level_idc.

I wonder how things like IHeight is liked to i_height, I didn't see any place where i_height is set from IHeight. Is it just the order of the members in the structs?

Yes, the order of members, including any padding that might be needed. Not sure if that is the only change, the newer versions I tested with this https://gist.github.com/gen2brain/d7b5ce38e1a85ff9a33aa3c6a165f87e

Thanks, adding IBitDepth helped me to go past this.
I'll try to check every member..

No problem, you can check like this, e.g:

package main

/*
#include "x264.h"
*/
import "C"

type Param C.x264_param_t

func main() {
}

Name the file types.go, put x264.h in same dir and then go tool cgo -godefs types.go.

OK, the params look fine, I'm not missing any, after adding IBitDepth. They all have the right type.

Now my new error is

x264 [error]: baseline profile doesn't support lossless

I took care of setting

opts.Param.Rc.IQpConstant = 40

But apparently it's not enough.

I think it might be due to the fact that I don't yet understand where to put the [4]byte paddings. I have them exactly like in https://gist.github.com/gen2brain/d7b5ce38e1a85ff9a33aa3c6a165f87e so there is one between Analyse and Rc.

I checked Analyze and Rc and there is nothing new there compared to the header.

Try to change baseline to high profile. That I think is not related to struct/padding, but new changes.

Changing to high changed nothing. So it must be one of these vars:

    if( p < PROFILE_HIGH444_PREDICTIVE && ((param->rc.i_rc_method == X264_RC_CQP && param->rc.i_qp_constant <= 0) ||
        (param->rc.i_rc_method == X264_RC_CRF && (int)(param->rc.f_rf_constant + qp_bd_offset) <= 0)) )
    {
        x264_log_internal( X264_LOG_ERROR, "%s profile doesn't support lossless\n", profile );
        return -1;
    }

rc.i_rc_method
rc.i_qp_constant
rc.f_rf_constant

This is a patch from when I tested new versions, maybe it will be of help https://gist.github.com/gen2brain/f5ead089cbf29110bb7c59bddad8bee7

Thanks, fyi I was able to get extlib working quite well with just adding IBitdepth and updating the sources files. I did this using the libx264 of Ubuntu 18.04, which is version 0.152.2854 e9a5903.

I also added a #cgo linux CFLAGS: -Iexternal/x264 to point to the x264.h in the package.

And removed the .syso because they were causing issues.

I also added the x264_config.h generated by configure, and included it.

Support for the external library should be fixed now, but it will not work in Ubuntu 16, not sure from when is the IBitdepth change.

There is now also compat build tag so Ubuntu 16 works with -tags 'extlib compat'.