[FFmpeg-devel] [PATCH] add support for ROI-based encoding

Guo, Yejun yejun.guo at intel.com
Thu Dec 6 05:03:36 EET 2018



> -----Original Message-----
> From: ffmpeg-devel [mailto:ffmpeg-devel-bounces at ffmpeg.org] On Behalf
> Of Michael Niedermayer
> Sent: Thursday, December 06, 2018 4:41 AM
> To: FFmpeg development discussions and patches <ffmpeg-
> devel at ffmpeg.org>
> Subject: Re: [FFmpeg-devel] [PATCH] add support for ROI-based encoding
> 
> On Wed, Dec 05, 2018 at 05:58:58PM +0800, Guo, Yejun wrote:
> > this patch is not ask for merge, it is more to get a feature feedback.
> >
> > 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. And so I choose to maintain the ROI info
> > within AVFrame struct.
> >
> > TODO:
> > - remove code in vf_scale.c, it is just an example to generate ROI
> > info
> > - use AVBufferRef instead of current implementation within AVFrame
> struct.
> > - add other encoders support
> >
> > Signed-off-by: Guo, Yejun <yejun.guo at intel.com>
> > ---
> >  libavcodec/libx264.c   | 35 +++++++++++++++++++++++++++++++++++
> >  libavfilter/vf_scale.c |  8 ++++++++
> >  libavutil/frame.c      |  9 +++++++++
> >  libavutil/frame.h      | 14 ++++++++++++++
> >  4 files changed, 66 insertions(+)
> 
> this causes asserion failures
> ./ffmpeg -i matrixbench_mpeg2.mpg  this.mkv
> 
> ...
> 
> ooooops, frame 0x0x3c03cc0 with rois 0
> Assertion !"should not reach here" failed at libavcodec/libx264.c:381 Aborted
> (core dumped)
> 

The reason is that no one generates the ROI info with this command line.

In this patch, I just borrowed vf_scale to mock the behavior to generate ROI info, the qp offset
of the left half video is forced to be 15, and so the left part will be more rough with a given bitrate.

And only libx264 encoder is supported now, so the command line looks like:
./ffmpeg  -i  .../path_to_1920x1080_video_file  -vf scale=1920:1080 -c:v libx264  -b:v 2000k -y tmp.264

btw, the impact between the left and the right of the video will be more obvious if the video is about
a sky with proper bitrates.

> 
> [...]
> --
> Michael     GnuPG fingerprint:
> 9FF2128B147EF6730BADF133611EC787040B0FAB
> 
> While the State exists there can be no freedom; when there is freedom
> there will be no State. -- Vladimir Lenin


More information about the ffmpeg-devel mailing list