【问题标题】:Is there an easy way to use x264 presets with ffmpeg in code?有没有一种简单的方法可以在代码中使用带有 ffmpeg 的 x264 预设?
【发布时间】:2014-08-29 12:39:05
【问题描述】:

我正在尝试使用 ffmpeg 和 x264 对视频进行编码。我知道 ffmpeg 从命令行使用程序 ffm​​peg 时可以使用 x264 预设。但是在代码中使用 ffmpeg 编码时是否可以轻松使用这些预设?

如果不是,从 ffmpeg 代码设置 x264 参数的最佳方法是什么?它只是使用 AVCodecContext 的属性吗?是否所有 x264 选项都可以通过它获得?

谢谢!

【问题讨论】:

    标签: ffmpeg video-encoding x264


    【解决方案1】:

    很抱歉,答案很晚,但我有同样的问题,我想分享我找到的解决方案。 是的,可以通过命令行和 API 传递许多 x264 选项,至少在使用 libav 时(我现在无法用 ffmpeg 确认)。通过发出 avconv --help 你可以找到:

    libx264 AVOptions:
    -preset            <string> E.V.. Set the encoding preset (cf. x264 --fullhelp)
    -tune              <string> E.V.. Tune the encoding params (cf. x264 --fullhelp)
    -profile           <string> E.V.. Set profile restrictions (cf. x264 --fullhelp)
    -fastfirstpass     <int>   E.V.. Use fast settings when encoding first pass
    -crf               <float> E.V.. Select the quality for constant quality mode
    -crf_max           <float> E.V.. In CRF mode, prevents VBV from lowering quality beyond this point.
    -qp                <int>   E.V.. Constant quantization parameter rate control method
    -aq-mode           <int>   E.V.. AQ method
       none                    E.V..
       variance                E.V.. Variance AQ (complexity mask)
       autovariance            E.V.. Auto-variance AQ (experimental)
    -aq-strength       <float> E.V.. AQ strength. Reduces blocking and blurring in flat and textured areas.
    -psy               <int>   E.V.. Use psychovisual optimizations.
    -psy-rd            <string> E.V.. Strength of psychovisual optimization, in <psy-rd>:<psy-trellis> format.
    -rc-lookahead      <int>   E.V.. Number of frames to look ahead for frametype and ratecontrol
    -weightb           <int>   E.V.. Weighted prediction for B-frames.
    -weightp           <int>   E.V.. Weighted prediction analysis method.
       none                    E.V..
       simple                  E.V..
       smart                   E.V..
    -ssim              <int>   E.V.. Calculate and print SSIM stats.
    -intra-refresh     <int>   E.V.. Use Periodic Intra Refresh instead of IDR frames.
    -b-bias            <int>   E.V.. Influences how often B-frames are used
    -b-pyramid         <int>   E.V.. Keep some B-frames as references.
       none                    E.V..
       strict                  E.V.. Strictly hierarchical pyramid
       normal                  E.V.. Non-strict (not Blu-ray compatible)
    -mixed-refs        <int>   E.V.. One reference per partition, as opposed to one reference per macroblock
    -8x8dct            <int>   E.V.. High profile 8x8 transform.
    -fast-pskip        <int>   E.V..
    -aud               <int>   E.V.. Use access unit delimiters.
    -mbtree            <int>   E.V.. Use macroblock tree ratecontrol.
    -deblock           <string> E.V.. Loop filter parameters, in <alpha:beta> form.
    -cplxblur          <float> E.V.. Reduce fluctuations in QP (before curve compression)
    -partitions        <string> E.V.. A comma-separated list of partitions to consider. Possible values: p8x8, p4x4, b8x8, i8x8, i4x4, none, all
    -direct-pred       <int>   E.V.. Direct MV prediction mode
       none                    E.V..
       spatial                 E.V..
       temporal                E.V..
       auto                    E.V..
    -slice-max-size    <int>   E.V.. Limit the size of each slice in bytes
    -stats             <string> E.V.. Filename for 2 pass stats
    

    使用 AVCodecContext 结构时,您还可以设置那些选项,例如 -rc-lookahead 可以在 AVCodecContext::rc_lookahead 中设置,但我现在不确定 -preset。

    希望对你有帮助

    【讨论】:

      【解决方案2】:

      首先,你必须知道 ffmpeg 支持 x264opts 和 x264-params,以添加更精确的 x264 编码控制。并将一个由“:”分隔的 key=value 列表传递给 x264。 例如:

      ffmpeg .... -x264opts bframes=0:... ...
      

      对于 x264 将 bframes 设置为 0 的意思。此格式与 x264 不完全相同。

      更多细节检查:

      1,ffmpge document

      2,x264

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-04-08
        • 2010-09-12
        • 2011-03-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-01-15
        • 2010-10-25
        相关资源
        最近更新 更多