[FFmpeg-devel] [PATCH v2] avcodec/v4l2_m2m_enc: Support changing qmin/qmax
Andriy Gelman
andriy.gelman at gmail.com
Sun Feb 16 21:28:20 EET 2020
On Sat, 01. Feb 22:38, Mark Thompson wrote:
> On 19/01/2020 19:54, Andriy Gelman wrote:
> > From: Andriy Gelman <andriy.gelman at gmail.com>
> >
> > Hard coded parameters for qmin and qmax are currently used to initialize
> > v4l2_m2m device. This commit uses values from avctx->{qmin,qmax} if they
> > are set.
> >
> > Signed-off-by: Andriy Gelman <andriy.gelman at gmail.com>
> > ---
> > libavcodec/v4l2_m2m_enc.c | 33 +++++++++++++++++++++++++++++++--
> > 1 file changed, 31 insertions(+), 2 deletions(-)
> >
> > diff --git a/libavcodec/v4l2_m2m_enc.c b/libavcodec/v4l2_m2m_enc.c
> > index 8059e3bb48f..318be0d3379 100644
> > --- a/libavcodec/v4l2_m2m_enc.c
> > +++ b/libavcodec/v4l2_m2m_enc.c
> > @@ -31,10 +31,25 @@
> > #include "v4l2_context.h"
> > #include "v4l2_m2m.h"
> > #include "v4l2_fmt.h"
> > +#include "internal.h"
> >
> > #define MPEG_CID(x) V4L2_CID_MPEG_VIDEO_##x
> > #define MPEG_VIDEO(x) V4L2_MPEG_VIDEO_##x
> >
> > +#define CLIP_MIN_MAX(in, min_val, max_val, name, logctx) \
> > + do { \
> > + if ((in) < (min_val)) { \
> > + av_log((logctx), AV_LOG_WARNING, \
> > + "Adjusted: " name " (%d)\n", (min_val)); \
> > + in = min_val; \
> > + } \
> > + if ((in) > (max_val)) { \
> > + av_log((logctx), AV_LOG_WARNING, \
> > + "Adjusted: " name " (%d)\n", (max_val)); \
> > + (in) = (max_val); \
> > + } \
> > + } while (0)
> > +
> > static inline void v4l2_set_timeperframe(V4L2m2mContext *s, unsigned int num, unsigned int den)
> > {
> > struct v4l2_streamparm parm = { 0 };
> > @@ -232,8 +247,15 @@ static int v4l2_prepare_encoder(V4L2m2mContext *s)
> > return 0;
> > }
> >
> > - if (qmin != avctx->qmin || qmax != avctx->qmax)
> > - av_log(avctx, AV_LOG_WARNING, "Encoder adjusted: qmin (%d), qmax (%d)\n", qmin, qmax);
> > + if (avctx->qmin >= 0) {
> > + CLIP_MIN_MAX(avctx->qmin, qmin, qmax, "qmin", avctx);
> > + qmin = avctx->qmin;
> > + }
> > +
> > + if (avctx->qmax >= 0) {
> > + CLIP_MIN_MAX(avctx->qmax, qmin, qmax, "qmax", avctx);
> > + qmax = avctx->qmax;
> > + }
> >
> > v4l2_set_ext_ctrl(s, qmin_cid, qmin, "minimum video quantizer scale");
> > v4l2_set_ext_ctrl(s, qmax_cid, qmax, "maximum video quantizer scale");
> > @@ -349,6 +371,12 @@ static const AVOption options[] = {
> > { NULL },
> > };
> >
> > +static const AVCodecDefault v4l2_m2m_defaults[] = {
> > + { "qmin", "-1" },
> > + { "qmax", "-1" },
> > + { NULL },
> > +};
> > +
> > #define M2MENC_CLASS(NAME) \
> > static const AVClass v4l2_m2m_ ## NAME ## _enc_class = { \
> > .class_name = #NAME "_v4l2m2m_encoder", \
> > @@ -370,6 +398,7 @@ static const AVOption options[] = {
> > .send_frame = v4l2_send_frame, \
> > .receive_packet = v4l2_receive_packet, \
> > .close = v4l2_encode_close, \
> > + .defaults = v4l2_m2m_defaults, \
> > .capabilities = AV_CODEC_CAP_HARDWARE | AV_CODEC_CAP_DELAY, \
> > .wrapper_name = "v4l2m2m", \
> > };
> >
>
> Can we avoid some of the clumsiness around clipping twice in different ways by querying the quantiser values from the encode device here?
>
In the s5p-mfc code, a function ends up being assigned to each parameter that
clips the values to be in the correct range.
As I understand, it's std_validate:
https://github.com/torvalds/linux/blob/master/drivers/media/v4l2-core/v4l2-ctrls.c#L1873
Then, I do not think we need to explicitly clip the parameter.
Also, when testing the qmax/qmin, I found it had no affect unless the
frame_level_rate_control_enable option was set (it's off by default).
If the option is set, qmax/qmin range seems to be respected except for the first
frame, where it's always 1 (not sure why).
--
Andriy
More information about the ffmpeg-devel
mailing list