简体   繁体   English

有没有一种简单的方法可以在代码中将x264预设与ffmpeg一起使用?

[英]Is there an easy way to use x264 presets with ffmpeg in code?

I'm trying to encode video with ffmpeg and x264. 我正在尝试使用ffmpeg和x264对视频进行编码。 I know ffmpeg can use x264 presets when using the program ffmpeg from command line. 我知道从命令行使用ffmpeg程序时,ffmpeg可以使用x264预设。 But is it possible to easily use these presets when encoding with ffmpeg in code? 但是,在代码中使用ffmpeg进行编码时,是否可以轻松使用这些预设?

If not, what is the best way to set the x264 parameters from ffmpeg code? 如果不是,从ffmpeg代码设置x264参数的最佳方法是什么? Is it just using the properties of the AVCodecContext? 是否仅使用AVCodecContext的属性? Are all the x264 options available through this? 所有的x264选项都可以通过此方法使用吗?

Thank you! 谢谢!

Sorry for the very late answer but I had the same question and I want to share the solution that I found. 抱歉,回答太晚了,但我有相同的问题,我想分享找到的解决方案。 Yes, it is possible to pass many of the x264 options through the command-line and API, at least when using libav (I can´t confirm with ffmpeg now). 是的,至少在使用libav时,可以通过命令行和API传递许多x264选项(我现在无法用ffmpeg进行确认)。 By issuing avconv --help you can find this: 通过发布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

When using the AVCodecContext struct, you can also set those options like -rc-lookahead can be set at AVCodecContext::rc_lookahead, but I´m not sure about -preset now. 使用AVCodecContext结构时,还可以设置-rc-lookahead之类的选项,可以在AVCodecContext :: rc_lookahead中设置,但是我现在不确定-preset。

Hope this can help 希望这可以帮助

first, you must know ffmpeg support x264opts and x264-params, to add more precise control of x264 encodec. 首先,您必须知道ffmpeg支持x264opts和x264-params,以添加对x264编码器的更精确控制。 and it pass a key=value list separated by ":" to x264. 并将通过“:”分隔的键=值列表传递给x264。 for example: 例如:

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

which mean of setting bframes to 0 for x264. 这意味着将x264的bframe设置为0。 this format not fully same with x264. 此格式与x264不完全相同。

more detail check this: 更详细的检查:

1, ffmpge document 1, ffmpge文件

2, x264 2, x264

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM