asticode/go-astiav

av_opt_set question

Cacsjep opened this issue · 6 comments

First awesome project,

I want o set the quality on a mjpeg context, in C this is done with av_opt_set(c->priv_data, "quality", "12", 0);
Is there a way I can set this with go-astiv ? It looks like that av_opt_set and priv_data is not exposed to golang right ?

Thank u

It looks like that av_opt_set and priv_data is not exposed to golang right ?

You're right.

I want o set the quality on a mjpeg context, in C this is done with av_opt_set(c->priv_data, "quality", "12", 0);

Could you share more code (especially the code above the line you mentioned)? I can look to add this to this lib 👍

Hi

Thank u for your answer =)
Here an example, biolerplate its not tested but should give you an idea,
Would be great if you can add this =)

int main() {
    AVCodec* codec = avcodec_find_encoder(AV_CODEC_ID_MJPEG);
    if (!codec) {
        fprintf(stderr, "Codec not found\n");
        return 1;
    }

    AVCodecContext* c = avcodec_alloc_context3(codec);
    if (!c) {
        fprintf(stderr, "Could not allocate codec context\n");
        return 1;
    }

    // Set codec parameters
    c->width = 1920;
    c->height = 1080;
    c->bit_rate = 4000000;
    c->time_base = (AVRational){1, 25};
    c->pix_fmt = AV_PIX_FMT_YUVJ420P;

    // Set MJPEG-specific options
    av_opt_set(c->priv_data, "quality", "12", 0);

    // Open codec
    int ret = avcodec_open2(c, codec, NULL);
    if (ret < 0) {
        fprintf(stderr, "Could not open codec: %s\n", av_err2str(ret));
        return 1;
    }

    // Encoding loop goes here

    // Close codec and free context
    avcodec_close(c);
    avcodec_free_context(&c);

    return 0;
}

I'm getting Option not found when implementing the code you pasted. Can you tell me what value av_opt_set(c->priv_data, "quality", "12", 0); returns? Is it equal to 0 ?

ok please forget it I just found this on google for setting the mjpeg quality but looks that are an old one or so,
I found now a other way to set the quality for mjpeg encoding. Sorry to bother u with this.

Just for testing a add this to codec_context.go, because qmin was not exposed.

func (cc *CodecContext) SetQmin(qual int) {
	cc.c.qmin = C.int(qual)
}

And using like this:

s.mjpegEncCodecContext.SetFlags(s.encCodecContext.Flags().Add(astiav.CodecContextFlagQscale))
s.mjpegEncCodecContext.SetQmin(30)

I am tried to using global_quality on ctx but this does not work for mjpeg refering to last post here
Now I am able to control the quality of mjpeg encoding =), once more great work you did !!

fyi I've added qmin handling in master 👍

great thank u