[FFmpeg-devel] [PATCH V5 1/2] avutil: add ROI (Region Of Interest) data struct and bump version

Rostislav Pehlivanov atomnuker at gmail.com
Fri Jan 4 13:13:52 EET 2019


On Thu, 3 Jan 2019 at 08:41, Guo, Yejun <yejun.guo at intel.com> wrote:

> The encoders such as libx264 support different QPs offset for different
> MBs,
> it makes possible for ROI-based encoding. It makes sense to add support
> within ffmpeg to generate/accept ROI infos and pass into encoders.
>
> Typical usage: After AVFrame is decoded, a ffmpeg filter or user's code
> generates ROI info for that frame, and the encoder finally does the
> ROI-based encoding.
>
> The ROI info is maintained as side data of AVFrame.
>
> Signed-off-by: Guo, Yejun <yejun.guo at intel.com>
> ---
>  libavutil/frame.c   |  1 +
>  libavutil/frame.h   | 29 +++++++++++++++++++++++++++++
>  libavutil/version.h |  2 +-
>  3 files changed, 31 insertions(+), 1 deletion(-)
>
> diff --git a/libavutil/frame.c b/libavutil/frame.c
> index 34a6210..dcf1fc3 100644
> --- a/libavutil/frame.c
> +++ b/libavutil/frame.c
> @@ -841,6 +841,7 @@ const char *av_frame_side_data_name(enum
> AVFrameSideDataType type)
>      case AV_FRAME_DATA_QP_TABLE_DATA:               return "QP table
> data";
>  #endif
>      case AV_FRAME_DATA_DYNAMIC_HDR_PLUS: return "HDR Dynamic Metadata
> SMPTE2094-40 (HDR10+)";
> +    case AV_FRAME_DATA_REGIONS_OF_INTEREST: return "Regions Of Interest";
>      }
>      return NULL;
>  }
> diff --git a/libavutil/frame.h b/libavutil/frame.h
> index 582ac47..7887391 100644
> --- a/libavutil/frame.h
> +++ b/libavutil/frame.h
> @@ -173,6 +173,12 @@ enum AVFrameSideDataType {
>       * volume transform - application 4 of SMPTE 2094-40:2016 standard.
>       */
>      AV_FRAME_DATA_DYNAMIC_HDR_PLUS,
> +
> +    /**
> +     * Regions Of Interest, the data is an array of AVRegionOfInterest
> type, the number of
> +     * array element is implied by AVFrameSideData.size /
> AVRegionOfInterest.self_size.
> +     */
> +    AV_FRAME_DATA_REGIONS_OF_INTEREST,
>  };
>
>  enum AVActiveFormatDescription {
> @@ -201,6 +207,29 @@ typedef struct AVFrameSideData {
>  } AVFrameSideData;
>
>  /**
> + * Structure to hold Region Of Interest.
> + *
> + * self_size specifies the size of this data structure. This value
> + * should be set to sizeof(AVRegionOfInterest).
> + *
> + * Number of pixels to discard from the top/bottom/left/right border of
> + * the frame to obtain the region of interest of the frame.
> + * They are encoder dependent and will be extended internally
> + * if the codec requires an alignment.
> + * If the regions overlap, the last value in the list will be used.
> + *
> + * qoffset is quant offset, it is encoder dependent.
> + */
> +typedef struct AVRegionOfInterest {
> +    size_t self_size;
> +    size_t top;
> +    size_t bottom;
> +    size_t left;
> +    size_t right;
>

I'd still much rather have uints with fixed sizes than these platform
dependent types.


+    float qoffset;
>

Use an AVRational with a denum set to the max quantizer, that'll make it
encoder independent and give you better precision.
We also generally don't have floats in the API.


More information about the ffmpeg-devel mailing list