【问题标题】:h264 lossless settings in cc中的h264无损设置
【发布时间】:2014-03-28 10:47:28
【问题描述】:

我目前正在尝试在 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;

对于确保无损编码应该采取什么措施有什么想法吗? 提前致谢。

【问题讨论】:

    标签: ffmpeg h.264 video-encoding lossless


    【解决方案1】:

    试试这个:

    ...
    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);
    ...
    

    无损不要使用配置文件

    【讨论】:

    • 嗨,卢卡,我尝试了这种方法,但是,现在当我使用此代码生成的 DLL 运行我的 C# 代码访问时,我可能会出现“AccessViolationUnhandled”错误,指出“尝试读取或写入受保护内存。这通常表明其他内存已损坏。”。我不太确定是什么原因造成的,有什么想法吗?
    • 抱歉,您是否尝试过设置 param=0?因为 av_dict_set 如果 param=0 分配内存,但如果不是,它认为内存已分配
    • 嗨卢卡,非常感谢您的帮助!我现在可以构建和运行代码,但不幸的是,它似乎仍然没有完全无损编码,因为当我解码文件时,它比预期的要小(通常大约 25MB)。
    • 抱歉,看起来压缩确实有效,问题出在其他地方,与将帧写入文件有关。非常感谢您的帮助!
    猜你喜欢
    • 2011-10-05
    • 1970-01-01
    • 2016-11-10
    • 1970-01-01
    • 2012-01-19
    • 1970-01-01
    • 2012-05-11
    • 2011-01-17
    • 2020-12-30
    相关资源
    最近更新 更多