[FFmpeg-devel] [crop support for matroska demuxer, V3 1/3] libavcodec: Add crop related fields to structure AVCodecContext and AVCodecParameters.

Dmitrii Ovchinnikov ovchinnikov.dmitrii at gmail.com
Wed Oct 12 18:21:31 EEST 2022


>>Why does an encoder or decoder need to care about this, given it's
>>container level information?
>>Do you plan on implementing cropping support into all the encoders?



This implementation takes a reference of the h.264 supporting cropping. In
h264, if width (stored in ACCodecContext) parsed from container is
different from width parsed from elementary, it will trigger cropping. This
is essentially a kind of cropping that related with container. It will
infer parameters cb(crop bottom), cr(crop right), and then finally assigned
them to AVFrame.

This gives the inspiration when we get direct cropping parameters from
container. We can us the same methodology.

Parser cropping parameters from container in demuxer -> stored container
cropping parameters in AVCodec -> pass container cropping parameters to
AVFrame-> Apply Crop in frame.c of libavutil.



Container cropping can both be implemented in libavutil, or libavfilter.
The as-is implementation of H.264 gave a detailed implement reference that
we can put cropping in libavcode and libavutil. My implementation just
follows that methodology.



>From the another point of view, there are some benefit as well: cropping is
a light weight process (only copy yuv data), comparing with some module
such as edge_common,  colorspacedsp etc. in libavfilter. Put container
cropping in libavcodec and libavutil is very concise.



Currently we are supporting the matroska codec. Matroska will be the first
one that use submitted code in decoder.c and AVCodecContext to support
container cropping. Because container cropping parameters I added are 0 by
default, it will not affect any existing container or future container
which don’t support crop. If other developers plan to add container crop
supporting for certain container, those codes in public section (such as
codes in in decoder.c and AVCodecContext ) are possible shared by them.


More information about the ffmpeg-devel mailing list