kvazaar icon indicating copy to clipboard operation
kvazaar copied to clipboard

ffmpeg codes use kvazaar

Open lyk941031 opened this issue 1 year ago • 5 comments

hi , im change command line to codes use ffmpeg libkvazaar ,i cant find codec_ID for libkvazaar, should i use AV_CODEC_ID_HEVC? or other codec_id
my codes like :

lyk941031 avatar Aug 30 '23 06:08 lyk941031

const AVCodec *avCodec = avcodec_find_encoder(AV_CODEC_ID_HEVC); AVCodecContext *avCodecContext = avcodec_alloc_context3(avCodec); avCodecContext->time_base = {1,25};

avCodecContext->width = 3480;
avCodecContext->height = 1920;
avCodecContext->bit_rate = 10485760;
//avCodecContext->profile = FF_PROFILE_H264_MAIN;
avCodecContext->gop_size = 10;
avCodecContext->time_base = {1,25};
avCodecContext->framerate = {25,1};

avCodecContext->max_b_frames = 1;
avCodecContext->pix_fmt = AV_PIX_FMT_YUV420P;

av_opt_set(avCodecContext->priv_data,"preset","ultrafast",0);
av_opt_set(avCodecContext->priv_data,"tiles","1x3",0);
av_opt_set(avCodecContext->priv_data,"slices","tiles",0);
av_opt_set(avCodecContext->priv_data,"mv-constraint","tiles",0);

int ret = avcodec_open2(avCodecContext,avCodec, nullptr);
if(ret < 0){
    std::cout << "open encoder fail:" << strerror(ret) << std::endl;
    return;
}

lyk941031 avatar Aug 30 '23 06:08 lyk941031

how can i change kvazaar-paramers into code (--cpuid --input-fps 30 --bitrate 10485760 --period 30 --preset ultrafast --erp-aqp --input-res 3840x1920 --no-open-gop --gop lp-g30d1t1 --tiles 1x3 --slices tiles --mv-constraint frametilemargin --no-bipred) just use like this {av_opt_set(avCodecContext->priv_data,"tiles","1x3",0);}?

lyk941031 avatar Aug 30 '23 06:08 lyk941031

i cant find avcodec_find_encoder_by_name("libkvazaar") , used wrong?

lyk941031 avatar Aug 30 '23 07:08 lyk941031

You have to pack this parameters to string "input-fps=30,bitrate=104..." and then do

av_dict_set(&options, "kvazaar-params", options_string, 0)

Where options is an AVDictionary which you will later pass to

avcodec_open2(context, codec, &options)

The answer might depend on version of ffmpeg. You can set some of the parameters via context->, but they are overriden by parameters in the options later.

See source code: https://github.com/FFmpeg/FFmpeg/blob/master/libavcodec/libkvazaar.c

Read the friendly manual: ffmpeg -h encoder=libkvazaar

pinbraerts avatar Aug 23 '24 11:08 pinbraerts

i cant find avcodec_find_encoder_by_name("libkvazaar") , used wrong?

This is right. If ffmpeg can't find the encoder, that could mean that you built the ffmpeg library without kvazaar.

pinbraerts avatar Aug 23 '24 11:08 pinbraerts