Ffmpeg h264 c中的无损设置

Ffmpeg h264 c中的无损设置,ffmpeg,h.264,video-encoding,lossless,Ffmpeg,H.264,Video Encoding,Lossless,我目前正在尝试在c中为FFMPEG应用无损H264设置。然而,我不确定需要什么样的设置来确保无损编码,我在这方面几乎找不到文档 我当前的设置是: codecContex->coder_type = 1; codecContex->flags|=CODEC_FLAG_LOOP_FILTER; codecContex->flags2|=CODEC_FLAG2_BPYRAMID-CODEC_FLAG2_WPRED-CODEC_FLAG2_8X8DCT;

我目前正在尝试在c中为FFMPEG应用无损H264设置。然而,我不确定需要什么样的设置来确保无损编码,我在这方面几乎找不到文档

我当前的设置是:

    codecContex->coder_type = 1; 
    codecContex->flags|=CODEC_FLAG_LOOP_FILTER;
    codecContex->flags2|=CODEC_FLAG2_BPYRAMID-CODEC_FLAG2_WPRED-CODEC_FLAG2_8X8DCT;

    codecContex->profile=FF_PROFILE_H264_BASELINE;
    codecContex->scenechange_threshold = 40; 
    codecContex->gop_size=40;
    codecContex->max_b_frames=0;
    codecContex->max_qdiff=4;
    codecContex->me_method=10;
    codecContex->me_range=16;
    codecContex->me_cmp|= 1;
    codecContex->me_subpel_quality = 5; 
    codecContex->qmin=0; 
    codecContex->qmax=0;
    codecContex->qcompress=0.6f;
    codecContex->keyint_min=25;
    codecContex->trellis=0;
    codecContex->level=13;
    codecContex->refs = 16;
    codecContex->weighted_p_pred = 2;
    codecContex->b_frame_strategy= 1;
    codecContex->color_range = libffmpeg::AVCOL_RANGE_JPEG;
    codecContex->coder_type = FF_CODER_TYPE_AC;
    codecContex->crf = 0;
关于如何确保无损编码,有什么想法吗? 提前感谢。

试试这个:

...
AVDictionary *param;
av_dict_set(&param, "qp", "0", 0);
/*
Change options to trade off compression efficiency against encoding speed. If you specify a preset, the changes it makes will be applied before all other parameters are applied.
You should generally set this option to the slowest you can bear.
Values available: ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow, placebo.
*/
av_dict_set(&param, "preset", "medium", 0);
/*
Tune options to further optimize them for your input content. If you specify a tuning, the changes will be applied after --preset but before all other parameters.
If your source content matches one of the available tunings you can use this, otherwise leave unset.
Values available: film, animation, grain, stillimage, psnr, ssim, fastdecode, zerolatency.
*/
av_dict_set(&param, "tune", "film", 0);
int rt = avcodec_open2(codecContext, codec, &param);
...

对于无损请勿使用配置文件

Hi luca,我尝试了这种方法,但是,现在每当我使用此代码生成的DLL运行我的C代码访问时,我都会发现一个“AccessViolationUnhandled”错误,声明“试图读取或写入受保护的内存。这通常表示其他内存已损坏。”。我不太确定是什么原因造成的,有什么想法吗?对不起,您是否尝试将param=0?因为av_dict_set在param=0时分配内存,但如果不是,它认为内存已分配Hi Luca,非常感谢您的帮助!我现在可以构建并运行代码了,但不幸的是,它似乎仍然不是完全无损编码的,因为当我解码文件时,它比预期的小(通常约25MB)。对不起,实际上看起来压缩正在工作,问题在别处,与向文件写入帧有关。非常感谢你的帮助!