* [FFmpeg-devel] [crop support for matroska demuxer, V4 1/3] libavcodec: Add crop related fields to structure AVCodecContext and AVCodecParameters.
@ 2022-11-04 14:13 OvchinnikovDmitrii
2022-11-04 14:13 ` [FFmpeg-devel] [crop support for matroska demuxer, V4 2/3] libavcodec: Public code to support container crop OvchinnikovDmitrii
2022-11-04 14:13 ` [FFmpeg-devel] [crop support for matroska demuxer, V4 3/3] libavformat\matroskadec.c: crop support for matroska demuxer OvchinnikovDmitrii
0 siblings, 2 replies; 7+ messages in thread
From: OvchinnikovDmitrii @ 2022-11-04 14:13 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: OvchinnikovDmitrii
---
libavcodec/avcodec.h | 35 +++++++++++++++++++++++++++++++++++
libavcodec/codec_par.h | 8 ++++++++
libavcodec/options_table.h | 4 ++++
3 files changed, 47 insertions(+)
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 3edd8e2636..57b340c24d 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -380,6 +380,19 @@ typedef struct RcOverride{
*/
#define AV_GET_ENCODE_BUFFER_FLAG_REF (1 << 0)
+/**
+* Video decoding only. Certain container support cropping, meaning that
+* only a sub-rectangle of the decoded frame is intended for display.
+* Certain codec supports cropping as well.This option controls how
+* cropping is handled by libavcodec when container cropping and
+* codec cropping exist.
+*/
+enum CONTAINER_CROPPING_POLICY_TYPE {
+ FF_CONTAINER_CROPPING_IGNORE = 0,
+ FF_CONTAINER_CROPPING_ADDITION,
+ FF_CONTAINER_CROPPING_OVERWRITE
+};
+
struct AVCodecInternal;
/**
@@ -2057,6 +2070,28 @@ typedef struct AVCodecContext {
* The decoder can then override during decoding as needed.
*/
AVChannelLayout ch_layout;
+
+ /* When set to 1 (the default), libavcodec will apply container cropping
+ * to codec cropping additionally.
+ *
+ * When set to 2, libavcodec will use container cropping to overwrite
+ * codec cropping (the final cropping uses container cropping parameters)
+ *
+ * When set to 0, libavcodec will ignore container cropping parameters
+ * (the final cropping uses codec cropping parameters)
+ *
+ * This field works with "apply_cropping". Only if apply_cropping is 1, this
+ * field works
+ */
+ enum CONTAINER_CROPPING_POLICY_TYPE container_apply_cropping;
+
+ /**
+ * The cropping parameters from container.
+ */
+ int container_crop_top;
+ int container_crop_left;
+ int container_crop_bottom;
+ int container_crop_right;
} AVCodecContext;
/**
diff --git a/libavcodec/codec_par.h b/libavcodec/codec_par.h
index f51d27c590..cc0695689c 100644
--- a/libavcodec/codec_par.h
+++ b/libavcodec/codec_par.h
@@ -211,6 +211,14 @@ typedef struct AVCodecParameters {
* Audio only. The channel layout and number of channels.
*/
AVChannelLayout ch_layout;
+
+ /**
+ * The cropping parameters from container.
+ */
+ int container_crop_top;
+ int container_crop_left;
+ int container_crop_bottom;
+ int container_crop_right;
} AVCodecParameters;
/**
diff --git a/libavcodec/options_table.h b/libavcodec/options_table.h
index cd02f5096f..fd1ef21f90 100644
--- a/libavcodec/options_table.h
+++ b/libavcodec/options_table.h
@@ -401,6 +401,10 @@ static const AVOption avcodec_options[] = {
{"allow_profile_mismatch", "attempt to decode anyway if HW accelerated decoder's supported profiles do not exactly match the stream", 0, AV_OPT_TYPE_CONST, {.i64 = AV_HWACCEL_FLAG_ALLOW_PROFILE_MISMATCH }, INT_MIN, INT_MAX, V | D, "hwaccel_flags"},
{"extra_hw_frames", "Number of extra hardware frames to allocate for the user", OFFSET(extra_hw_frames), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, V|D },
{"discard_damaged_percentage", "Percentage of damaged samples to discard a frame", OFFSET(discard_damaged_percentage), AV_OPT_TYPE_INT, {.i64 = 95 }, 0, 100, V|D },
+{ "container_apply_cropping", "ploicy using container cropping parameters", OFFSET(container_apply_cropping), AV_OPT_TYPE_INT64, {.i64 = FF_CONTAINER_CROPPING_ADDITION }, 0, 2, V | D, "container_apply_cropping" },
+{ "ignore", "ignore container cropping", 0, AV_OPT_TYPE_CONST, {.i64 = FF_CONTAINER_CROPPING_IGNORE }, 0, 0, V | D, "container_apply_cropping" },
+{ "addition", "apply container cropping additionally to elementary stream cropping", 0, AV_OPT_TYPE_CONST, {.i64 = FF_CONTAINER_CROPPING_ADDITION }, 0, 0, V | D, "container_apply_cropping" },
+{ "overwrite", "use container cropping to overwrite elementary stream cropping", 0, AV_OPT_TYPE_CONST, {.i64 = FF_CONTAINER_CROPPING_OVERWRITE }, 0, 0, V | D, "container_apply_cropping" },
{NULL},
};
--
2.30.0.windows.2
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 7+ messages in thread
* [FFmpeg-devel] [crop support for matroska demuxer, V4 2/3] libavcodec: Public code to support container crop
2022-11-04 14:13 [FFmpeg-devel] [crop support for matroska demuxer, V4 1/3] libavcodec: Add crop related fields to structure AVCodecContext and AVCodecParameters OvchinnikovDmitrii
@ 2022-11-04 14:13 ` OvchinnikovDmitrii
2022-11-04 15:34 ` Michael Niedermayer
2022-11-04 14:13 ` [FFmpeg-devel] [crop support for matroska demuxer, V4 3/3] libavformat\matroskadec.c: crop support for matroska demuxer OvchinnikovDmitrii
1 sibling, 1 reply; 7+ messages in thread
From: OvchinnikovDmitrii @ 2022-11-04 14:13 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: OvchinnikovDmitrii
Support both simple and receive_frame api
The container crop information is applied additional to frame crop information
---
libavcodec/codec_par.c | 30 ++++++++++++++---------
libavcodec/decode.c | 54 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 73 insertions(+), 11 deletions(-)
diff --git a/libavcodec/codec_par.c b/libavcodec/codec_par.c
index abda649aa8..9738402434 100644
--- a/libavcodec/codec_par.c
+++ b/libavcodec/codec_par.c
@@ -115,17 +115,21 @@ int avcodec_parameters_from_context(AVCodecParameters *par,
switch (par->codec_type) {
case AVMEDIA_TYPE_VIDEO:
- par->format = codec->pix_fmt;
- par->width = codec->width;
- par->height = codec->height;
- par->field_order = codec->field_order;
- par->color_range = codec->color_range;
- par->color_primaries = codec->color_primaries;
- par->color_trc = codec->color_trc;
- par->color_space = codec->colorspace;
- par->chroma_location = codec->chroma_sample_location;
- par->sample_aspect_ratio = codec->sample_aspect_ratio;
- par->video_delay = codec->has_b_frames;
+ par->format = codec->pix_fmt;
+ par->width = codec->width;
+ par->height = codec->height;
+ par->container_crop_top = codec->container_crop_top;
+ par->container_crop_left = codec->container_crop_left;
+ par->container_crop_bottom = codec->container_crop_bottom;
+ par->container_crop_right = codec->container_crop_right;
+ par->field_order = codec->field_order;
+ par->color_range = codec->color_range;
+ par->color_primaries = codec->color_primaries;
+ par->color_trc = codec->color_trc;
+ par->color_space = codec->colorspace;
+ par->chroma_location = codec->chroma_sample_location;
+ par->sample_aspect_ratio = codec->sample_aspect_ratio;
+ par->video_delay = codec->has_b_frames;
break;
case AVMEDIA_TYPE_AUDIO:
par->format = codec->sample_fmt;
@@ -199,6 +203,10 @@ int avcodec_parameters_to_context(AVCodecContext *codec,
codec->pix_fmt = par->format;
codec->width = par->width;
codec->height = par->height;
+ codec->container_crop_top = par->container_crop_top;
+ codec->container_crop_left = par->container_crop_left;
+ codec->container_crop_bottom = par->container_crop_bottom;
+ codec->container_crop_right = par->container_crop_right;
codec->field_order = par->field_order;
codec->color_range = par->color_range;
codec->color_primaries = par->color_primaries;
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 6be2d3d6ed..9e44fcb293 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -693,6 +693,60 @@ static int apply_cropping(AVCodecContext *avctx, AVFrame *frame)
if (!avctx->apply_cropping)
return 0;
+ if (avctx->container_apply_cropping == FF_CONTAINER_CROPPING_ADDITION)
+ {
+ /*check if container parameter and elementary streaming cropping parameters are safe for applying */
+ if (avctx->container_crop_left + frame->crop_left>= INT_MAX - (avctx->container_crop_right + frame->crop_right) ||
+ avctx->container_crop_top + frame->crop_top >= INT_MAX - (avctx->container_crop_bottom + frame->crop_bottom) ||
+ (avctx->container_crop_left + frame->crop_left + avctx->container_crop_right + frame->crop_right) >= frame->width ||
+ (avctx->container_crop_top + frame->crop_top + avctx->container_crop_bottom + frame->crop_bottom) >= frame->height) {
+ av_log(avctx, AV_LOG_WARNING,
+ "Apply container and elementary stream corpping parametes error: "
+ "container cropping parameters"
+ "%"SIZE_SPECIFIER"/%"SIZE_SPECIFIER"/%"SIZE_SPECIFIER"/%"SIZE_SPECIFIER" "
+ "elementary stream croping paramters"
+ "%"SIZE_SPECIFIER"/%"SIZE_SPECIFIER"/%"SIZE_SPECIFIER"/%"SIZE_SPECIFIER" "
+ "(frame size %dx%d). This is a bug, please report it\n",
+ avctx->container_crop_left, avctx->container_crop_right, avctx->container_crop_top, avctx->container_crop_bottom,
+ frame->crop_left, frame->crop_right, frame->crop_top, frame->crop_bottom,
+ frame->width, frame->height);
+ frame->crop_left = 0;
+ frame->crop_right = 0;
+ frame->crop_top = 0;
+ frame->crop_bottom = 0;
+ return 0;
+ }
+
+ frame->crop_top += avctx->container_crop_top;
+ frame->crop_left += avctx->container_crop_left;
+ frame->crop_bottom += avctx->container_crop_bottom;
+ frame->crop_right += avctx->container_crop_right;
+ }else if (avctx->container_apply_cropping == FF_CONTAINER_CROPPING_OVERWRITE) {
+
+ /*check the croppping parameters from container are reasonable and correct*/
+ if (avctx->container_crop_left >= INT_MAX - avctx->container_crop_right ||
+ avctx->container_crop_top >= INT_MAX - avctx->container_crop_bottom ||
+ (avctx->container_crop_left + avctx->container_crop_right) >= frame->width ||
+ (avctx->container_crop_top + avctx->container_crop_bottom) >= frame->height) {
+ av_log(avctx, AV_LOG_WARNING,
+ "Invalid container cropping information set by a demuxer: "
+ "%"SIZE_SPECIFIER"/%"SIZE_SPECIFIER"/%"SIZE_SPECIFIER"/%"SIZE_SPECIFIER" "
+ "(frame size %dx%d). This is a bug, please report it\n",
+ avctx->container_crop_left, avctx->container_crop_right, avctx->container_crop_top, avctx->container_crop_bottom,
+ frame->width, frame->height);
+ frame->crop_left = 0;
+ frame->crop_right = 0;
+ frame->crop_top = 0;
+ frame->crop_bottom = 0;
+ return 0;
+ }
+
+ frame->crop_top = avctx->container_crop_top;
+ frame->crop_left = avctx->container_crop_left;
+ frame->crop_bottom = avctx->container_crop_bottom;
+ frame->crop_right = avctx->container_crop_right;
+ }
+
return av_frame_apply_cropping(frame, avctx->flags & AV_CODEC_FLAG_UNALIGNED ?
AV_FRAME_CROP_UNALIGNED : 0);
}
--
2.30.0.windows.2
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [FFmpeg-devel] [crop support for matroska demuxer, V4 2/3] libavcodec: Public code to support container crop
2022-11-04 14:13 ` [FFmpeg-devel] [crop support for matroska demuxer, V4 2/3] libavcodec: Public code to support container crop OvchinnikovDmitrii
@ 2022-11-04 15:34 ` Michael Niedermayer
2022-11-23 14:44 ` Dmitrii Ovchinnikov
0 siblings, 1 reply; 7+ messages in thread
From: Michael Niedermayer @ 2022-11-04 15:34 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1.1: Type: text/plain, Size: 2710 bytes --]
On Fri, Nov 04, 2022 at 03:13:35PM +0100, OvchinnikovDmitrii wrote:
> Support both simple and receive_frame api
> The container crop information is applied additional to frame crop information
[...]
> + av_log(avctx, AV_LOG_WARNING,
> + "Apply container and elementary stream corpping parametes error: "
> + "container cropping parameters"
> + "%"SIZE_SPECIFIER"/%"SIZE_SPECIFIER"/%"SIZE_SPECIFIER"/%"SIZE_SPECIFIER" "
> + "elementary stream croping paramters"
> + "%"SIZE_SPECIFIER"/%"SIZE_SPECIFIER"/%"SIZE_SPECIFIER"/%"SIZE_SPECIFIER" "
> + "(frame size %dx%d). This is a bug, please report it\n",
> + avctx->container_crop_left, avctx->container_crop_right, avctx->container_crop_top, avctx->container_crop_bottom,
> + frame->crop_left, frame->crop_right, frame->crop_top, frame->crop_bottom,
> + frame->width, frame->height);
> + frame->crop_left = 0;
> + frame->crop_right = 0;
> + frame->crop_top = 0;
> + frame->crop_bottom = 0;
> + return 0;
> + }
> +
> + frame->crop_top += avctx->container_crop_top;
> + frame->crop_left += avctx->container_crop_left;
> + frame->crop_bottom += avctx->container_crop_bottom;
> + frame->crop_right += avctx->container_crop_right;
> + }else if (avctx->container_apply_cropping == FF_CONTAINER_CROPPING_OVERWRITE) {
> +
> + /*check the croppping parameters from container are reasonable and correct*/
> + if (avctx->container_crop_left >= INT_MAX - avctx->container_crop_right ||
> + avctx->container_crop_top >= INT_MAX - avctx->container_crop_bottom ||
> + (avctx->container_crop_left + avctx->container_crop_right) >= frame->width ||
> + (avctx->container_crop_top + avctx->container_crop_bottom) >= frame->height) {
> + av_log(avctx, AV_LOG_WARNING,
> + "Invalid container cropping information set by a demuxer: "
> + "%"SIZE_SPECIFIER"/%"SIZE_SPECIFIER"/%"SIZE_SPECIFIER"/%"SIZE_SPECIFIER" "
> + "(frame size %dx%d). This is a bug, please report it\n",
> + avctx->container_crop_left, avctx->container_crop_right, avctx->container_crop_top, avctx->container_crop_bottom,
> + frame->width, frame->height);
The types seems mismatching
thx
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
I do not agree with what you have to say, but I'll defend to the death your
right to say it. -- Voltaire
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
[-- Attachment #2: Type: text/plain, Size: 251 bytes --]
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [FFmpeg-devel] [crop support for matroska demuxer, V4 2/3] libavcodec: Public code to support container crop
2022-11-04 15:34 ` Michael Niedermayer
@ 2022-11-23 14:44 ` Dmitrii Ovchinnikov
2022-11-24 23:07 ` Michael Niedermayer
0 siblings, 1 reply; 7+ messages in thread
From: Dmitrii Ovchinnikov @ 2022-11-23 14:44 UTC (permalink / raw)
To: FFmpeg development discussions and patches
>>The types seems mismatching
The reason for the mismatch of types is that I left the
int type according to the comments :
"
James Almer
IMO the AVFrame ones should have not been size_t to begin with, not just
because the actual dimensions you'll apply them to are int, but because
these fields are not arch dependent or meant for the size of some object
in memory.
"
It seems that performing casts would not be a good idea.
Should I make crop fields size_t type as in AVFrame?
Or is there a more correct way?
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [FFmpeg-devel] [crop support for matroska demuxer, V4 2/3] libavcodec: Public code to support container crop
2022-11-23 14:44 ` Dmitrii Ovchinnikov
@ 2022-11-24 23:07 ` Michael Niedermayer
0 siblings, 0 replies; 7+ messages in thread
From: Michael Niedermayer @ 2022-11-24 23:07 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1.1: Type: text/plain, Size: 1001 bytes --]
On Wed, Nov 23, 2022 at 03:44:25PM +0100, Dmitrii Ovchinnikov wrote:
> >>The types seems mismatching
>
> The reason for the mismatch of types is that I left the
> int type according to the comments :
> "
> James Almer
> IMO the AVFrame ones should have not been size_t to begin with, not just
> because the actual dimensions you'll apply them to are int, but because
> these fields are not arch dependent or meant for the size of some object
> in memory.
> "
>
> It seems that performing casts would not be a good idea.
> Should I make crop fields size_t type as in AVFrame?
> Or is there a more correct way?
the type specified in the format string has to match the types passed
in the argument to av_log
"%"SIZE_SPECIFIER" + size_t
or
%d + int
otherwise you have undefined behavior
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
The greatest way to live with honor in this world is to be what we pretend
to be. -- Socrates
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
[-- Attachment #2: Type: text/plain, Size: 251 bytes --]
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 7+ messages in thread
* [FFmpeg-devel] [crop support for matroska demuxer, V4 3/3] libavformat\matroskadec.c: crop support for matroska demuxer.
2022-11-04 14:13 [FFmpeg-devel] [crop support for matroska demuxer, V4 1/3] libavcodec: Add crop related fields to structure AVCodecContext and AVCodecParameters OvchinnikovDmitrii
2022-11-04 14:13 ` [FFmpeg-devel] [crop support for matroska demuxer, V4 2/3] libavcodec: Public code to support container crop OvchinnikovDmitrii
@ 2022-11-04 14:13 ` OvchinnikovDmitrii
1 sibling, 0 replies; 7+ messages in thread
From: OvchinnikovDmitrii @ 2022-11-04 14:13 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: OvchinnikovDmitrii
In webm specification, it supports cropping information. (https://www.webmproject.org/docs/container/)
In ffmpeg, the implementation of webm is a subset of matroska. In matroskadec.c, those cropping related four fields are forced to 0.
for the sample file with crop (crop_bottom =8, crop_top=crop_left=crop_right=0.)
ffmpeg.exe -i test_with_container_crop.webm -pix_fmt yuv420p -y output.yuv
original ffmpeg code - the output.yuv resolution is 1920x1088
changed code - the output.yuv resolution is 1920x1080
Previous discussion :https://patchwork.ffmpeg.org/project/ffmpeg/list/?series=7668
---
libavformat/matroskadec.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index d582f566a2..2023fd4977 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -210,6 +210,10 @@ typedef struct MatroskaTrackVideo {
uint64_t pixel_width;
uint64_t pixel_height;
EbmlBin color_space;
+ uint64_t pixel_cropt;
+ uint64_t pixel_cropl;
+ uint64_t pixel_cropb;
+ uint64_t pixel_cropr;
uint64_t display_unit;
uint64_t interlaced;
uint64_t field_order;
@@ -517,10 +521,10 @@ static EbmlSyntax matroska_track_video[] = {
{ MATROSKA_ID_VIDEOALPHAMODE, EBML_UINT, 0, 0, offsetof(MatroskaTrackVideo, alpha_mode), { .u = 0 } },
{ MATROSKA_ID_VIDEOCOLOR, EBML_NEST, 0, sizeof(MatroskaTrackVideoColor), offsetof(MatroskaTrackVideo, color), { .n = matroska_track_video_color } },
{ MATROSKA_ID_VIDEOPROJECTION, EBML_NEST, 0, 0, offsetof(MatroskaTrackVideo, projection), { .n = matroska_track_video_projection } },
- { MATROSKA_ID_VIDEOPIXELCROPB, EBML_NONE },
- { MATROSKA_ID_VIDEOPIXELCROPT, EBML_NONE },
- { MATROSKA_ID_VIDEOPIXELCROPL, EBML_NONE },
- { MATROSKA_ID_VIDEOPIXELCROPR, EBML_NONE },
+ { MATROSKA_ID_VIDEOPIXELCROPT, EBML_UINT, 0, 0, offsetof(MatroskaTrackVideo, pixel_cropt), {.u = 0 } },
+ { MATROSKA_ID_VIDEOPIXELCROPL, EBML_UINT, 0, 0, offsetof(MatroskaTrackVideo, pixel_cropl), {.u = 0 } },
+ { MATROSKA_ID_VIDEOPIXELCROPB, EBML_UINT, 0, 0, offsetof(MatroskaTrackVideo, pixel_cropb), {.u = 0 } },
+ { MATROSKA_ID_VIDEOPIXELCROPR, EBML_UINT, 0, 0, offsetof(MatroskaTrackVideo, pixel_cropr), {.u = 0 } },
{ MATROSKA_ID_VIDEODISPLAYUNIT, EBML_UINT, 0, 0, offsetof(MatroskaTrackVideo, display_unit), { .u= MATROSKA_VIDEO_DISPLAYUNIT_PIXELS } },
{ MATROSKA_ID_VIDEOFLAGINTERLACED, EBML_UINT, 0, 0, offsetof(MatroskaTrackVideo, interlaced), { .u = MATROSKA_VIDEO_INTERLACE_FLAG_UNDETERMINED } },
{ MATROSKA_ID_VIDEOFIELDORDER, EBML_UINT, 0, 0, offsetof(MatroskaTrackVideo, field_order), { .u = MATROSKA_VIDEO_FIELDORDER_UNDETERMINED } },
@@ -2879,6 +2883,11 @@ static int matroska_parse_tracks(AVFormatContext *s)
st->codecpar->width = track->video.pixel_width;
st->codecpar->height = track->video.pixel_height;
+ st->codecpar->container_crop_top = track->video.pixel_cropt;
+ st->codecpar->container_crop_left = track->video.pixel_cropl;
+ st->codecpar->container_crop_bottom = track->video.pixel_cropb;
+ st->codecpar->container_crop_right = track->video.pixel_cropr;
+
if (track->video.interlaced == MATROSKA_VIDEO_INTERLACE_FLAG_INTERLACED)
st->codecpar->field_order = mkv_field_order(matroska, track->video.field_order);
else if (track->video.interlaced == MATROSKA_VIDEO_INTERLACE_FLAG_PROGRESSIVE)
--
2.30.0.windows.2
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 7+ messages in thread
* [FFmpeg-devel] [crop support for matroska demuxer, V4 1/3] libavcodec: Add crop related fields to structure AVCodecContext and AVCodecParameters.
@ 2022-12-20 15:37 Dmitrii Ovchinnikov
2022-12-20 15:37 ` [FFmpeg-devel] [crop support for matroska demuxer, V4 3/3] libavformat\matroskadec.c: crop support for matroska demuxer Dmitrii Ovchinnikov
0 siblings, 1 reply; 7+ messages in thread
From: Dmitrii Ovchinnikov @ 2022-12-20 15:37 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Dmitrii Ovchinnikov
From: Dmitrii Ovchinnikov <ovchinnikov.dmitrii@gmail.com>
---
libavcodec/avcodec.h | 35 +++++++++++++++++++++++++++++++++++
libavcodec/codec_par.h | 8 ++++++++
libavcodec/options_table.h | 4 ++++
3 files changed, 47 insertions(+)
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 3edd8e2636..57b340c24d 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -380,6 +380,19 @@ typedef struct RcOverride{
*/
#define AV_GET_ENCODE_BUFFER_FLAG_REF (1 << 0)
+/**
+* Video decoding only. Certain container support cropping, meaning that
+* only a sub-rectangle of the decoded frame is intended for display.
+* Certain codec supports cropping as well.This option controls how
+* cropping is handled by libavcodec when container cropping and
+* codec cropping exist.
+*/
+enum CONTAINER_CROPPING_POLICY_TYPE {
+ FF_CONTAINER_CROPPING_IGNORE = 0,
+ FF_CONTAINER_CROPPING_ADDITION,
+ FF_CONTAINER_CROPPING_OVERWRITE
+};
+
struct AVCodecInternal;
/**
@@ -2057,6 +2070,28 @@ typedef struct AVCodecContext {
* The decoder can then override during decoding as needed.
*/
AVChannelLayout ch_layout;
+
+ /* When set to 1 (the default), libavcodec will apply container cropping
+ * to codec cropping additionally.
+ *
+ * When set to 2, libavcodec will use container cropping to overwrite
+ * codec cropping (the final cropping uses container cropping parameters)
+ *
+ * When set to 0, libavcodec will ignore container cropping parameters
+ * (the final cropping uses codec cropping parameters)
+ *
+ * This field works with "apply_cropping". Only if apply_cropping is 1, this
+ * field works
+ */
+ enum CONTAINER_CROPPING_POLICY_TYPE container_apply_cropping;
+
+ /**
+ * The cropping parameters from container.
+ */
+ int container_crop_top;
+ int container_crop_left;
+ int container_crop_bottom;
+ int container_crop_right;
} AVCodecContext;
/**
diff --git a/libavcodec/codec_par.h b/libavcodec/codec_par.h
index f51d27c590..cc0695689c 100644
--- a/libavcodec/codec_par.h
+++ b/libavcodec/codec_par.h
@@ -211,6 +211,14 @@ typedef struct AVCodecParameters {
* Audio only. The channel layout and number of channels.
*/
AVChannelLayout ch_layout;
+
+ /**
+ * The cropping parameters from container.
+ */
+ int container_crop_top;
+ int container_crop_left;
+ int container_crop_bottom;
+ int container_crop_right;
} AVCodecParameters;
/**
diff --git a/libavcodec/options_table.h b/libavcodec/options_table.h
index cd02f5096f..fd1ef21f90 100644
--- a/libavcodec/options_table.h
+++ b/libavcodec/options_table.h
@@ -401,6 +401,10 @@ static const AVOption avcodec_options[] = {
{"allow_profile_mismatch", "attempt to decode anyway if HW accelerated decoder's supported profiles do not exactly match the stream", 0, AV_OPT_TYPE_CONST, {.i64 = AV_HWACCEL_FLAG_ALLOW_PROFILE_MISMATCH }, INT_MIN, INT_MAX, V | D, "hwaccel_flags"},
{"extra_hw_frames", "Number of extra hardware frames to allocate for the user", OFFSET(extra_hw_frames), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, V|D },
{"discard_damaged_percentage", "Percentage of damaged samples to discard a frame", OFFSET(discard_damaged_percentage), AV_OPT_TYPE_INT, {.i64 = 95 }, 0, 100, V|D },
+{ "container_apply_cropping", "ploicy using container cropping parameters", OFFSET(container_apply_cropping), AV_OPT_TYPE_INT64, {.i64 = FF_CONTAINER_CROPPING_ADDITION }, 0, 2, V | D, "container_apply_cropping" },
+{ "ignore", "ignore container cropping", 0, AV_OPT_TYPE_CONST, {.i64 = FF_CONTAINER_CROPPING_IGNORE }, 0, 0, V | D, "container_apply_cropping" },
+{ "addition", "apply container cropping additionally to elementary stream cropping", 0, AV_OPT_TYPE_CONST, {.i64 = FF_CONTAINER_CROPPING_ADDITION }, 0, 0, V | D, "container_apply_cropping" },
+{ "overwrite", "use container cropping to overwrite elementary stream cropping", 0, AV_OPT_TYPE_CONST, {.i64 = FF_CONTAINER_CROPPING_OVERWRITE }, 0, 0, V | D, "container_apply_cropping" },
{NULL},
};
--
2.30.0.windows.2
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 7+ messages in thread
* [FFmpeg-devel] [crop support for matroska demuxer, V4 3/3] libavformat\matroskadec.c: crop support for matroska demuxer.
2022-12-20 15:37 [FFmpeg-devel] [crop support for matroska demuxer, V4 1/3] libavcodec: Add crop related fields to structure AVCodecContext and AVCodecParameters Dmitrii Ovchinnikov
@ 2022-12-20 15:37 ` Dmitrii Ovchinnikov
0 siblings, 0 replies; 7+ messages in thread
From: Dmitrii Ovchinnikov @ 2022-12-20 15:37 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Dmitrii Ovchinnikov
From: Dmitrii Ovchinnikov <ovchinnikov.dmitrii@gmail.com>
In webm specification, it supports cropping information. (https://www.webmproject.org/docs/container/)
In ffmpeg, the implementation of webm is a subset of matroska. In matroskadec.c, those cropping related four fields are forced to 0.
for the sample file with crop (crop_bottom =8, crop_top=crop_left=crop_right=0.)
ffmpeg.exe -i test_with_container_crop.webm -pix_fmt yuv420p -y output.yuv
original ffmpeg code - the output.yuv resolution is 1920x1088
changed code - the output.yuv resolution is 1920x1080
---
libavformat/matroskadec.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index d582f566a2..2023fd4977 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -210,6 +210,10 @@ typedef struct MatroskaTrackVideo {
uint64_t pixel_width;
uint64_t pixel_height;
EbmlBin color_space;
+ uint64_t pixel_cropt;
+ uint64_t pixel_cropl;
+ uint64_t pixel_cropb;
+ uint64_t pixel_cropr;
uint64_t display_unit;
uint64_t interlaced;
uint64_t field_order;
@@ -517,10 +521,10 @@ static EbmlSyntax matroska_track_video[] = {
{ MATROSKA_ID_VIDEOALPHAMODE, EBML_UINT, 0, 0, offsetof(MatroskaTrackVideo, alpha_mode), { .u = 0 } },
{ MATROSKA_ID_VIDEOCOLOR, EBML_NEST, 0, sizeof(MatroskaTrackVideoColor), offsetof(MatroskaTrackVideo, color), { .n = matroska_track_video_color } },
{ MATROSKA_ID_VIDEOPROJECTION, EBML_NEST, 0, 0, offsetof(MatroskaTrackVideo, projection), { .n = matroska_track_video_projection } },
- { MATROSKA_ID_VIDEOPIXELCROPB, EBML_NONE },
- { MATROSKA_ID_VIDEOPIXELCROPT, EBML_NONE },
- { MATROSKA_ID_VIDEOPIXELCROPL, EBML_NONE },
- { MATROSKA_ID_VIDEOPIXELCROPR, EBML_NONE },
+ { MATROSKA_ID_VIDEOPIXELCROPT, EBML_UINT, 0, 0, offsetof(MatroskaTrackVideo, pixel_cropt), {.u = 0 } },
+ { MATROSKA_ID_VIDEOPIXELCROPL, EBML_UINT, 0, 0, offsetof(MatroskaTrackVideo, pixel_cropl), {.u = 0 } },
+ { MATROSKA_ID_VIDEOPIXELCROPB, EBML_UINT, 0, 0, offsetof(MatroskaTrackVideo, pixel_cropb), {.u = 0 } },
+ { MATROSKA_ID_VIDEOPIXELCROPR, EBML_UINT, 0, 0, offsetof(MatroskaTrackVideo, pixel_cropr), {.u = 0 } },
{ MATROSKA_ID_VIDEODISPLAYUNIT, EBML_UINT, 0, 0, offsetof(MatroskaTrackVideo, display_unit), { .u= MATROSKA_VIDEO_DISPLAYUNIT_PIXELS } },
{ MATROSKA_ID_VIDEOFLAGINTERLACED, EBML_UINT, 0, 0, offsetof(MatroskaTrackVideo, interlaced), { .u = MATROSKA_VIDEO_INTERLACE_FLAG_UNDETERMINED } },
{ MATROSKA_ID_VIDEOFIELDORDER, EBML_UINT, 0, 0, offsetof(MatroskaTrackVideo, field_order), { .u = MATROSKA_VIDEO_FIELDORDER_UNDETERMINED } },
@@ -2879,6 +2883,11 @@ static int matroska_parse_tracks(AVFormatContext *s)
st->codecpar->width = track->video.pixel_width;
st->codecpar->height = track->video.pixel_height;
+ st->codecpar->container_crop_top = track->video.pixel_cropt;
+ st->codecpar->container_crop_left = track->video.pixel_cropl;
+ st->codecpar->container_crop_bottom = track->video.pixel_cropb;
+ st->codecpar->container_crop_right = track->video.pixel_cropr;
+
if (track->video.interlaced == MATROSKA_VIDEO_INTERLACE_FLAG_INTERLACED)
st->codecpar->field_order = mkv_field_order(matroska, track->video.field_order);
else if (track->video.interlaced == MATROSKA_VIDEO_INTERLACE_FLAG_PROGRESSIVE)
--
2.30.0.windows.2
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2022-12-20 15:37 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-04 14:13 [FFmpeg-devel] [crop support for matroska demuxer, V4 1/3] libavcodec: Add crop related fields to structure AVCodecContext and AVCodecParameters OvchinnikovDmitrii
2022-11-04 14:13 ` [FFmpeg-devel] [crop support for matroska demuxer, V4 2/3] libavcodec: Public code to support container crop OvchinnikovDmitrii
2022-11-04 15:34 ` Michael Niedermayer
2022-11-23 14:44 ` Dmitrii Ovchinnikov
2022-11-24 23:07 ` Michael Niedermayer
2022-11-04 14:13 ` [FFmpeg-devel] [crop support for matroska demuxer, V4 3/3] libavformat\matroskadec.c: crop support for matroska demuxer OvchinnikovDmitrii
2022-12-20 15:37 [FFmpeg-devel] [crop support for matroska demuxer, V4 1/3] libavcodec: Add crop related fields to structure AVCodecContext and AVCodecParameters Dmitrii Ovchinnikov
2022-12-20 15:37 ` [FFmpeg-devel] [crop support for matroska demuxer, V4 3/3] libavformat\matroskadec.c: crop support for matroska demuxer Dmitrii Ovchinnikov
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git