[FFmpeg-devel] [PATCH v4 1/3] avcodec/v4l2_m2m_enc: Reduce log verbosity for some params

Andriy Gelman andriy.gelman at gmail.com
Sat Mar 14 16:32:10 EET 2020


On Sun, 23. Feb 13:47, Andriy Gelman wrote:
> From: Andriy Gelman <andriy.gelman at gmail.com>
> 
> Currently the user gets unhelpful warnings when some default parameters
> are not supported by the device. The verbosity of these log messages has
> been changed to AV_LOG_DEBUG.
> 
> Signed-off-by: Andriy Gelman <andriy.gelman at gmail.com>
> ---
>  libavcodec/v4l2_m2m_enc.c | 36 +++++++++++++++++++++---------------
>  1 file changed, 21 insertions(+), 15 deletions(-)
> 
> diff --git a/libavcodec/v4l2_m2m_enc.c b/libavcodec/v4l2_m2m_enc.c
> index c9f1741bfd0..859feb7bde7 100644
> --- a/libavcodec/v4l2_m2m_enc.c
> +++ b/libavcodec/v4l2_m2m_enc.c
> @@ -47,7 +47,7 @@ static inline void v4l2_set_timeperframe(V4L2m2mContext *s, unsigned int num, un
>          av_log(s->avctx, AV_LOG_WARNING, "Failed to set timeperframe");
>  }
>  
> -static inline void v4l2_set_ext_ctrl(V4L2m2mContext *s, unsigned int id, signed int value, const char *name)
> +static inline void v4l2_set_ext_ctrl(V4L2m2mContext *s, unsigned int id, signed int value, const char *name, int log_warning)
>  {
>      struct v4l2_ext_controls ctrls = { { 0 } };
>      struct v4l2_ext_control ctrl = { 0 };
> @@ -62,12 +62,13 @@ static inline void v4l2_set_ext_ctrl(V4L2m2mContext *s, unsigned int id, signed
>      ctrl.id = id;
>  
>      if (ioctl(s->fd, VIDIOC_S_EXT_CTRLS, &ctrls) < 0)
> -        av_log(s->avctx, AV_LOG_WARNING, "Failed to set %s: %s\n", name, strerror(errno));
> +        av_log(s->avctx, log_warning || errno != EINVAL ? AV_LOG_WARNING : AV_LOG_DEBUG,
> +               "Failed to set %s: %s\n", name, strerror(errno));
>      else
>          av_log(s->avctx, AV_LOG_DEBUG, "Encoder: %s = %d\n", name, value);
>  }
>  
> -static inline int v4l2_get_ext_ctrl(V4L2m2mContext *s, unsigned int id, signed int *value, const char *name)
> +static inline int v4l2_get_ext_ctrl(V4L2m2mContext *s, unsigned int id, signed int *value, const char *name, int log_warning)
>  {
>      struct v4l2_ext_controls ctrls = { { 0 } };
>      struct v4l2_ext_control ctrl = { 0 };
> @@ -83,7 +84,8 @@ static inline int v4l2_get_ext_ctrl(V4L2m2mContext *s, unsigned int id, signed i
>  
>      ret = ioctl(s->fd, VIDIOC_G_EXT_CTRLS, &ctrls);
>      if (ret < 0) {
> -        av_log(s->avctx, AV_LOG_WARNING, "Failed to get %s\n", name);
> +        av_log(s->avctx, log_warning || errno != EINVAL ? AV_LOG_WARNING : AV_LOG_DEBUG,
> +               "Failed to get %s\n", name);
>          return ret;
>      }
>  
> @@ -145,8 +147,8 @@ static int v4l2_check_b_frame_support(V4L2m2mContext *s)
>      if (s->avctx->max_b_frames)
>          av_log(s->avctx, AV_LOG_WARNING, "Encoder does not support b-frames yet\n");
>  
> -    v4l2_set_ext_ctrl(s, MPEG_CID(B_FRAMES), 0, "number of B-frames");
> -    v4l2_get_ext_ctrl(s, MPEG_CID(B_FRAMES), &s->avctx->max_b_frames, "number of B-frames");
> +    v4l2_set_ext_ctrl(s, MPEG_CID(B_FRAMES), 0, "number of B-frames", 0);
> +    v4l2_get_ext_ctrl(s, MPEG_CID(B_FRAMES), &s->avctx->max_b_frames, "number of B-frames", 0);
>      if (s->avctx->max_b_frames == 0)
>          return 0;
>  
> @@ -175,9 +177,9 @@ static int v4l2_prepare_encoder(V4L2m2mContext *s)
>          v4l2_set_timeperframe(s, avctx->framerate.num, avctx->framerate.den);
>  
>      /* set ext ctrls */
> -    v4l2_set_ext_ctrl(s, MPEG_CID(HEADER_MODE), MPEG_VIDEO(HEADER_MODE_SEPARATE), "header mode");
> -    v4l2_set_ext_ctrl(s, MPEG_CID(BITRATE) , avctx->bit_rate, "bit rate");
> -    v4l2_set_ext_ctrl(s, MPEG_CID(GOP_SIZE), avctx->gop_size,"gop size");
> +    v4l2_set_ext_ctrl(s, MPEG_CID(HEADER_MODE), MPEG_VIDEO(HEADER_MODE_SEPARATE), "header mode", 0);
> +    v4l2_set_ext_ctrl(s, MPEG_CID(BITRATE) , avctx->bit_rate, "bit rate", 1);
> +    v4l2_set_ext_ctrl(s, MPEG_CID(GOP_SIZE), avctx->gop_size,"gop size", 1);
>  
>      av_log(avctx, AV_LOG_DEBUG,
>          "Encoder Context: id (%d), profile (%d), frame rate(%d/%d), number b-frames (%d), "
> @@ -187,26 +189,30 @@ static int v4l2_prepare_encoder(V4L2m2mContext *s)
>  
>      switch (avctx->codec_id) {
>      case AV_CODEC_ID_H264:
> +        if (avctx->profile != FF_PROFILE_UNKNOWN) {
>          val = v4l2_h264_profile_from_ff(avctx->profile);
>          if (val < 0)
>              av_log(avctx, AV_LOG_WARNING, "h264 profile not found\n");
>          else
> -            v4l2_set_ext_ctrl(s, MPEG_CID(H264_PROFILE), val, "h264 profile");
> +            v4l2_set_ext_ctrl(s, MPEG_CID(H264_PROFILE), val, "h264 profile", 1);
> +        }
>          qmin_cid = MPEG_CID(H264_MIN_QP);
>          qmax_cid = MPEG_CID(H264_MAX_QP);
>          qmin = 0;
>          qmax = 51;
>          break;
>      case AV_CODEC_ID_MPEG4:
> +        if (avctx->profile != FF_PROFILE_UNKNOWN) {
>          val = v4l2_mpeg4_profile_from_ff(avctx->profile);
>          if (val < 0)
>              av_log(avctx, AV_LOG_WARNING, "mpeg4 profile not found\n");
>          else
> -            v4l2_set_ext_ctrl(s, MPEG_CID(MPEG4_PROFILE), val, "mpeg4 profile");
> +            v4l2_set_ext_ctrl(s, MPEG_CID(MPEG4_PROFILE), val, "mpeg4 profile", 1);
> +        }
>          qmin_cid = MPEG_CID(MPEG4_MIN_QP);
>          qmax_cid = MPEG_CID(MPEG4_MAX_QP);
>          if (avctx->flags & AV_CODEC_FLAG_QPEL)
> -            v4l2_set_ext_ctrl(s, MPEG_CID(MPEG4_QPEL), 1, "qpel");
> +            v4l2_set_ext_ctrl(s, MPEG_CID(MPEG4_QPEL), 1, "qpel", 1);
>          qmin = 1;
>          qmax = 31;
>          break;
> @@ -235,8 +241,8 @@ static int v4l2_prepare_encoder(V4L2m2mContext *s)
>      if (qmin != avctx->qmin || qmax != avctx->qmax)
>          av_log(avctx, AV_LOG_WARNING, "Encoder adjusted: qmin (%d), qmax (%d)\n", qmin, 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");
> +    v4l2_set_ext_ctrl(s, qmin_cid, qmin, "minimum video quantizer scale", 0);
> +    v4l2_set_ext_ctrl(s, qmax_cid, qmax, "maximum video quantizer scale", 0);
>  
>      return 0;
>  }
> @@ -248,7 +254,7 @@ static int v4l2_send_frame(AVCodecContext *avctx, const AVFrame *frame)
>  
>  #ifdef V4L2_CID_MPEG_VIDEO_FORCE_KEY_FRAME
>      if (frame && frame->pict_type == AV_PICTURE_TYPE_I)
> -        v4l2_set_ext_ctrl(s, MPEG_CID(FORCE_KEY_FRAME), 0, "force key frame");
> +        v4l2_set_ext_ctrl(s, MPEG_CID(FORCE_KEY_FRAME), 0, "force key frame", 1);
>  #endif
>  
>      return ff_v4l2_context_enqueue_frame(output, frame);
> -- 
> 2.25.0
> 

ping for set

-- 
Andriy


More information about the ffmpeg-devel mailing list