* [FFmpeg-devel] [PATCH 1/6] avcodec/packet: add a decoded frame cropping side data type
@ 2024-05-29 21:46 James Almer
2024-05-29 21:46 ` [FFmpeg-devel] [PATCH 2/6] avformat/dump: print Frame Cropping side data info James Almer
` (6 more replies)
0 siblings, 7 replies; 27+ messages in thread
From: James Almer @ 2024-05-29 21:46 UTC (permalink / raw)
To: ffmpeg-devel
Signed-off-by: James Almer <jamrial@gmail.com>
---
libavcodec/packet.h | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/libavcodec/packet.h b/libavcodec/packet.h
index a9a41576da..9dee035690 100644
--- a/libavcodec/packet.h
+++ b/libavcodec/packet.h
@@ -330,6 +330,20 @@ enum AVPacketSideDataType {
*/
AV_PKT_DATA_AMBIENT_VIEWING_ENVIRONMENT,
+ /**
+ * The number of pixels to discard from the
+ * top/bottom/left/right border of the decoded frame to obtain the sub-rectangle
+ * intended for presentation.
+ *
+ * @code
+ * u32le crop_top
+ * u32le crop_bottom
+ * u32le crop_left
+ * u32le crop_right
+ * @endcode
+ */
+ AV_PKT_DATA_FRAME_CROPPING,
+
/**
* The number of side data types.
* This is not part of the public API/ABI in the sense that it may
--
2.45.1
_______________________________________________
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] 27+ messages in thread
* [FFmpeg-devel] [PATCH 2/6] avformat/dump: print Frame Cropping side data info
2024-05-29 21:46 [FFmpeg-devel] [PATCH 1/6] avcodec/packet: add a decoded frame cropping side data type James Almer
@ 2024-05-29 21:46 ` James Almer
2024-05-29 21:46 ` [FFmpeg-devel] [PATCH 3/6] avformat/matroskadec: export cropping values James Almer
` (5 subsequent siblings)
6 siblings, 0 replies; 27+ messages in thread
From: James Almer @ 2024-05-29 21:46 UTC (permalink / raw)
To: ffmpeg-devel
Signed-off-by: James Almer <jamrial@gmail.com>
---
libavformat/dump.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/libavformat/dump.c b/libavformat/dump.c
index 059fb84522..610965cf81 100644
--- a/libavformat/dump.c
+++ b/libavformat/dump.c
@@ -431,6 +431,23 @@ static void dump_s12m_timecode(void *ctx, const AVStream *st, const AVPacketSide
}
}
+static void dump_cropping(void *ctx, const AVPacketSideData *sd)
+{
+ uint32_t top, bottom, left, right;
+
+ if (sd->size != sizeof(uint32_t) * 4) {
+ av_log(ctx, AV_LOG_ERROR, "invalid data\n");
+ return;
+ }
+
+ top = AV_RL32(sd->data + 0);
+ bottom = AV_RL32(sd->data + 4);
+ left = AV_RL32(sd->data + 8);
+ right = AV_RL32(sd->data + 12);
+
+ av_log(ctx, AV_LOG_INFO, "%d/%d/%d/%d", left, right, top, bottom);
+}
+
static void dump_sidedata(void *ctx, const AVStream *st, const char *indent,
int log_level)
{
@@ -505,6 +522,10 @@ static void dump_sidedata(void *ctx, const AVStream *st, const char *indent,
case AV_PKT_DATA_AMBIENT_VIEWING_ENVIRONMENT:
dump_ambient_viewing_environment_metadata(ctx, sd);
break;
+ case AV_PKT_DATA_FRAME_CROPPING:
+ av_log(ctx, AV_LOG_INFO, "Frame cropping: ");
+ dump_cropping(ctx, sd);
+ break;
default:
av_log(ctx, log_level, "unknown side data type %d "
"(%"SIZE_SPECIFIER" bytes)", sd->type, sd->size);
--
2.45.1
_______________________________________________
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] 27+ messages in thread
* [FFmpeg-devel] [PATCH 3/6] avformat/matroskadec: export cropping values
2024-05-29 21:46 [FFmpeg-devel] [PATCH 1/6] avcodec/packet: add a decoded frame cropping side data type James Almer
2024-05-29 21:46 ` [FFmpeg-devel] [PATCH 2/6] avformat/dump: print Frame Cropping side data info James Almer
@ 2024-05-29 21:46 ` James Almer
2024-06-01 11:24 ` Kacper Michajlow
2024-05-29 21:46 ` [FFmpeg-devel] [PATCH 4/6] avformat/matroskaenc: support writing " James Almer
` (4 subsequent siblings)
6 siblings, 1 reply; 27+ messages in thread
From: James Almer @ 2024-05-29 21:46 UTC (permalink / raw)
To: ffmpeg-devel
Signed-off-by: James Almer <jamrial@gmail.com>
---
libavformat/matroskadec.c | 53 +++++++++++++++++++++++++++++++--------
1 file changed, 43 insertions(+), 10 deletions(-)
diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index 2f07e11d87..a30bac786b 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -213,7 +213,13 @@ typedef struct MatroskaTrackVideo {
uint64_t display_height;
uint64_t pixel_width;
uint64_t pixel_height;
+ uint64_t cropped_width;
+ uint64_t cropped_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;
@@ -527,10 +533,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_VIDEOPIXELCROPB, EBML_UINT, 0, 0, offsetof(MatroskaTrackVideo, pixel_cropb), {.u = 0 } },
+ { 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_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 } },
@@ -2963,14 +2969,30 @@ static int mkv_parse_video(MatroskaTrack *track, AVStream *st,
if (track->video.display_unit < MATROSKA_VIDEO_DISPLAYUNIT_UNKNOWN) {
if (track->video.display_width && track->video.display_height &&
- par->height < INT64_MAX / track->video.display_width / display_width_mul &&
- par->width < INT64_MAX / track->video.display_height / display_height_mul)
+ track->video.cropped_height < INT64_MAX / track->video.display_width / display_width_mul &&
+ track->video.cropped_width < INT64_MAX / track->video.display_height / display_height_mul)
av_reduce(&st->sample_aspect_ratio.num,
&st->sample_aspect_ratio.den,
- par->height * track->video.display_width * display_width_mul,
- par->width * track->video.display_height * display_height_mul,
+ track->video.cropped_height * track->video.display_width * display_width_mul,
+ track->video.cropped_width * track->video.display_height * display_height_mul,
INT_MAX);
}
+ if (track->video.cropped_width != track->video.pixel_width ||
+ track->video.cropped_height != track->video.pixel_height) {
+ uint8_t *cropping;
+ AVPacketSideData *sd = av_packet_side_data_new(&st->codecpar->coded_side_data,
+ &st->codecpar->nb_coded_side_data,
+ AV_PKT_DATA_FRAME_CROPPING,
+ sizeof(uint32_t) * 4, 0);
+ if (!sd)
+ return AVERROR(ENOMEM);
+
+ cropping = sd->data;
+ bytestream_put_le32(&cropping, track->video.pixel_cropt);
+ bytestream_put_le32(&cropping, track->video.pixel_cropb);
+ bytestream_put_le32(&cropping, track->video.pixel_cropl);
+ bytestream_put_le32(&cropping, track->video.pixel_cropr);
+ }
if (par->codec_id != AV_CODEC_ID_HEVC)
sti->need_parsing = AVSTREAM_PARSE_HEADERS;
@@ -3136,10 +3158,21 @@ static int matroska_parse_tracks(AVFormatContext *s)
track->default_duration = default_duration;
}
}
+ track->video.cropped_width = track->video.pixel_width;
+ track->video.cropped_height = track->video.pixel_height;
+ if (track->video.display_unit == 0) {
+ if (track->video.pixel_cropl >= INT_MAX - track->video.pixel_cropr ||
+ track->video.pixel_cropt >= INT_MAX - track->video.pixel_cropb ||
+ (track->video.pixel_cropl + track->video.pixel_cropr) >= track->video.pixel_width ||
+ (track->video.pixel_cropt + track->video.pixel_cropb) >= track->video.pixel_height)
+ return AVERROR_INVALIDDATA;
+ track->video.cropped_width -= track->video.pixel_cropl + track->video.pixel_cropr;
+ track->video.cropped_height -= track->video.pixel_cropt + track->video.pixel_cropb;
+ }
if (track->video.display_width == -1)
- track->video.display_width = track->video.pixel_width;
+ track->video.display_width = track->video.cropped_width;
if (track->video.display_height == -1)
- track->video.display_height = track->video.pixel_height;
+ track->video.display_height = track->video.cropped_height;
} else if (track->type == MATROSKA_TRACK_TYPE_AUDIO) {
if (!track->audio.out_samplerate)
track->audio.out_samplerate = track->audio.samplerate;
--
2.45.1
_______________________________________________
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] 27+ messages in thread
* [FFmpeg-devel] [PATCH 4/6] avformat/matroskaenc: support writing cropping values
2024-05-29 21:46 [FFmpeg-devel] [PATCH 1/6] avcodec/packet: add a decoded frame cropping side data type James Almer
2024-05-29 21:46 ` [FFmpeg-devel] [PATCH 2/6] avformat/dump: print Frame Cropping side data info James Almer
2024-05-29 21:46 ` [FFmpeg-devel] [PATCH 3/6] avformat/matroskadec: export cropping values James Almer
@ 2024-05-29 21:46 ` James Almer
2024-05-29 21:46 ` [FFmpeg-devel] [PATCH 5/6] fftools/ffmpeg: support applying container level cropping James Almer
` (3 subsequent siblings)
6 siblings, 0 replies; 27+ messages in thread
From: James Almer @ 2024-05-29 21:46 UTC (permalink / raw)
To: ffmpeg-devel
Signed-off-by: James Almer <jamrial@gmail.com>
---
libavformat/matroskaenc.c | 44 ++++++++++++++++++++++++++++++++-------
1 file changed, 37 insertions(+), 7 deletions(-)
diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 76c542d50b..37a6a5b4f8 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -1755,8 +1755,10 @@ static int mkv_write_track_video(AVFormatContext *s, MatroskaMuxContext *mkv,
const AVDictionaryEntry *tag;
int display_width_div = 1, display_height_div = 1;
uint8_t color_space[4], projection_private[20];
+ const AVPacketSideData *sd;
EBML_WRITER(MAX_FIELD_ORDER_ELEMS + MAX_STEREO_MODE_ELEMS +
MAX_VIDEO_COLOR_ELEMS + MAX_VIDEO_PROJECTION_ELEMS + 8);
+ int cropped_width = par->width, cropped_height = par->height;
int ret;
ebml_writer_open_master(&writer, MATROSKA_ID_TRACKVIDEO);
@@ -1779,25 +1781,53 @@ static int mkv_write_track_video(AVFormatContext *s, MatroskaMuxContext *mkv,
(tag = av_dict_get( s->metadata, "alpha_mode", NULL, 0))) && strtol(tag->value, NULL, 0))
ebml_writer_add_uint(&writer, MATROSKA_ID_VIDEOALPHAMODE, 1);
+ sd = av_packet_side_data_get(st->codecpar->coded_side_data,
+ st->codecpar->nb_coded_side_data,
+ AV_PKT_DATA_FRAME_CROPPING);
+ if (sd && sd->size == sizeof(uint32_t) * 4) {
+ uint32_t top, bottom, left, right;
+
+ top = AV_RL32(sd->data + 0);
+ bottom = AV_RL32(sd->data + 4);
+ left = AV_RL32(sd->data + 8);
+ right = AV_RL32(sd->data + 12);
+
+ if (left >= INT_MAX - right ||
+ top >= INT_MAX - bottom ||
+ (left + right) >= par->width ||
+ (top + bottom) >= par->height) {
+ av_log(s, AV_LOG_ERROR, "Invalid cropping dimensions in stream side data\n");
+ return AVERROR(EINVAL);
+ }
+
+ ebml_writer_add_uint(&writer, MATROSKA_ID_VIDEOPIXELCROPB, bottom);
+ ebml_writer_add_uint(&writer, MATROSKA_ID_VIDEOPIXELCROPT, top);
+ ebml_writer_add_uint(&writer, MATROSKA_ID_VIDEOPIXELCROPL, left);
+ ebml_writer_add_uint(&writer, MATROSKA_ID_VIDEOPIXELCROPR, right);
+
+ cropped_width -= left + right;
+ cropped_height -= top + bottom;
+ }
+
// write DisplayWidth and DisplayHeight, they contain the size of
// a single source view and/or the display aspect ratio
if (st->sample_aspect_ratio.num) {
- int64_t d_width = av_rescale(par->width, st->sample_aspect_ratio.num, st->sample_aspect_ratio.den);
+ int64_t d_width = av_rescale(cropped_width, st->sample_aspect_ratio.num, st->sample_aspect_ratio.den);
if (d_width > INT_MAX) {
av_log(s, AV_LOG_ERROR, "Overflow in display width\n");
return AVERROR(EINVAL);
}
- if (d_width != par->width || display_width_div != 1 || display_height_div != 1) {
+ if (d_width != cropped_width || display_width_div != 1 || display_height_div != 1) {
if (IS_WEBM(mkv) || display_width_div != 1 || display_height_div != 1) {
ebml_writer_add_uint(&writer, MATROSKA_ID_VIDEODISPLAYWIDTH,
d_width / display_width_div);
ebml_writer_add_uint(&writer, MATROSKA_ID_VIDEODISPLAYHEIGHT,
- par->height / display_height_div);
+ cropped_height / display_height_div);
} else {
AVRational display_aspect_ratio;
av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den,
- par->width * (int64_t)st->sample_aspect_ratio.num,
- par->height * (int64_t)st->sample_aspect_ratio.den,
+ cropped_width * (int64_t)st->sample_aspect_ratio.num,
+ cropped_height * (int64_t)st->sample_aspect_ratio.den,
1024 * 1024);
ebml_writer_add_uint(&writer, MATROSKA_ID_VIDEODISPLAYWIDTH,
display_aspect_ratio.num);
@@ -1809,9 +1839,9 @@ static int mkv_write_track_video(AVFormatContext *s, MatroskaMuxContext *mkv,
}
} else if (display_width_div != 1 || display_height_div != 1) {
ebml_writer_add_uint(&writer, MATROSKA_ID_VIDEODISPLAYWIDTH,
- par->width / display_width_div);
+ cropped_width / display_width_div);
ebml_writer_add_uint(&writer, MATROSKA_ID_VIDEODISPLAYHEIGHT,
- par->height / display_height_div);
+ cropped_height / display_height_div);
} else if (!IS_WEBM(mkv))
ebml_writer_add_uint(&writer, MATROSKA_ID_VIDEODISPLAYUNIT,
MATROSKA_VIDEO_DISPLAYUNIT_UNKNOWN);
--
2.45.1
_______________________________________________
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] 27+ messages in thread
* [FFmpeg-devel] [PATCH 5/6] fftools/ffmpeg: support applying container level cropping
2024-05-29 21:46 [FFmpeg-devel] [PATCH 1/6] avcodec/packet: add a decoded frame cropping side data type James Almer
` (2 preceding siblings ...)
2024-05-29 21:46 ` [FFmpeg-devel] [PATCH 4/6] avformat/matroskaenc: support writing " James Almer
@ 2024-05-29 21:46 ` James Almer
2024-05-30 1:01 ` Lynne via ffmpeg-devel
` (2 more replies)
2024-05-29 21:46 ` [FFmpeg-devel] [PATCH 6/6] fftools/ffplay: " James Almer
` (2 subsequent siblings)
6 siblings, 3 replies; 27+ messages in thread
From: James Almer @ 2024-05-29 21:46 UTC (permalink / raw)
To: ffmpeg-devel
Signed-off-by: James Almer <jamrial@gmail.com>
---
fftools/ffmpeg.h | 7 +++++++
fftools/ffmpeg_demux.c | 16 ++++++++++++++++
fftools/ffmpeg_filter.c | 11 +++++++++++
fftools/ffmpeg_opt.c | 3 +++
4 files changed, 37 insertions(+)
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index fe75706afd..f908e16549 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -155,6 +155,7 @@ typedef struct OptionsContext {
SpecifierOptList hwaccel_devices;
SpecifierOptList hwaccel_output_formats;
SpecifierOptList autorotate;
+ SpecifierOptList apply_cropping;
/* output options */
StreamMap *stream_maps;
@@ -239,6 +240,7 @@ enum IFilterFlags {
IFILTER_FLAG_AUTOROTATE = (1 << 0),
IFILTER_FLAG_REINIT = (1 << 1),
IFILTER_FLAG_CFR = (1 << 2),
+ IFILTER_FLAG_CROP = (1 << 3),
};
typedef struct InputFilterOptions {
@@ -254,6 +256,11 @@ typedef struct InputFilterOptions {
* accurate */
AVRational framerate;
+ unsigned crop_top;
+ unsigned crop_bottom;
+ unsigned crop_left;
+ unsigned crop_right;
+
int sub2video_width;
int sub2video_height;
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index 1ca8d804ae..4178b8f840 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -66,6 +66,7 @@ typedef struct DemuxStream {
int have_sub2video;
int reinit_filters;
int autorotate;
+ int apply_cropping;
int wrap_correction_done;
@@ -1000,11 +1001,20 @@ int ist_filter_add(InputStream *ist, InputFilter *ifilter, int is_simple,
ist->filters[ist->nb_filters - 1] = ifilter;
if (ist->par->codec_type == AVMEDIA_TYPE_VIDEO) {
+ const AVPacketSideData *sd = av_packet_side_data_get(ist->st->codecpar->coded_side_data,
+ ist->st->codecpar->nb_coded_side_data,
+ AV_PKT_DATA_FRAME_CROPPING);
if (ist->framerate.num > 0 && ist->framerate.den > 0) {
opts->framerate = ist->framerate;
opts->flags |= IFILTER_FLAG_CFR;
} else
opts->framerate = av_guess_frame_rate(d->f.ctx, ist->st, NULL);
+ if (sd && sd->size == sizeof(uint32_t) * 4) {
+ opts->crop_top = AV_RL32(sd->data + 0);
+ opts->crop_bottom = AV_RL32(sd->data + 4);
+ opts->crop_left = AV_RL32(sd->data + 8);
+ opts->crop_right = AV_RL32(sd->data + 12);
+ }
} else if (ist->par->codec_type == AVMEDIA_TYPE_SUBTITLE) {
/* Compute the size of the canvas for the subtitles stream.
If the subtitles codecpar has set a size, use it. Otherwise use the
@@ -1059,6 +1069,7 @@ int ist_filter_add(InputStream *ist, InputFilter *ifilter, int is_simple,
return AVERROR(ENOMEM);
opts->flags |= IFILTER_FLAG_AUTOROTATE * !!(ds->autorotate) |
+ IFILTER_FLAG_CROP * !!(ds->apply_cropping) |
IFILTER_FLAG_REINIT * !!(ds->reinit_filters);
return ds->sch_idx_dec;
@@ -1241,6 +1252,9 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st)
ds->autorotate = 1;
MATCH_PER_STREAM_OPT(autorotate, i, ds->autorotate, ic, st);
+ ds->apply_cropping = 1;
+ MATCH_PER_STREAM_OPT(apply_cropping, i, ds->apply_cropping, ic, st);
+
MATCH_PER_STREAM_OPT(codec_tags, str, codec_tag, ic, st);
if (codec_tag) {
uint32_t tag = strtol(codec_tag, &next, 0);
@@ -1362,6 +1376,8 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st)
ds->dec_opts.flags |= DECODER_FLAG_BITEXACT * !!o->bitexact;
+ av_dict_set_int(&ds->decoder_opts, "apply_cropping", ds->apply_cropping, 0);
+
/* Attached pics are sparse, therefore we would not want to delay their decoding
* till EOF. */
if (ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC)
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 12cca684b4..a31fa1be7f 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -1701,6 +1701,17 @@ static int configure_input_video_filter(FilterGraph *fg, AVFilterGraph *graph,
desc = av_pix_fmt_desc_get(ifp->format);
av_assert0(desc);
+ if ((ifp->opts.flags & IFILTER_FLAG_CROP) &&
+ !(desc->flags & AV_PIX_FMT_FLAG_HWACCEL)) {
+ char crop_buf[64];
+ snprintf(crop_buf, sizeof(crop_buf), "w=iw-%d-%d:h=ih-%d-%d",
+ ifp->opts.crop_left, ifp->opts.crop_right,
+ ifp->opts.crop_top, ifp->opts.crop_bottom);
+ ret = insert_filter(&last_filter, &pad_idx, "crop", crop_buf);
+ if (ret < 0)
+ return ret;
+ }
+
// TODO: insert hwaccel enabled filters like transpose_vaapi into the graph
ifp->displaymatrix_applied = 0;
if ((ifp->opts.flags & IFILTER_FLAG_AUTOROTATE) &&
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index 910e4a336b..0c50ce16ba 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -1732,6 +1732,9 @@ const OptionDef options[] = {
{ "autoscale", OPT_TYPE_BOOL, OPT_PERSTREAM | OPT_EXPERT | OPT_OUTPUT,
{ .off = OFFSET(autoscale) },
"automatically insert a scale filter at the end of the filter graph" },
+ { "apply_cropping", OPT_TYPE_BOOL, OPT_PERSTREAM | OPT_EXPERT | OPT_INPUT,
+ { .off = OFFSET(apply_cropping) },
+ "apply frame cropping" },
{ "fix_sub_duration_heartbeat", OPT_TYPE_BOOL, OPT_VIDEO | OPT_EXPERT | OPT_PERSTREAM | OPT_OUTPUT,
{ .off = OFFSET(fix_sub_duration_heartbeat) },
"set this video output stream to be a heartbeat stream for "
--
2.45.1
_______________________________________________
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] 27+ messages in thread
* [FFmpeg-devel] [PATCH 6/6] fftools/ffplay: support applying container level cropping
2024-05-29 21:46 [FFmpeg-devel] [PATCH 1/6] avcodec/packet: add a decoded frame cropping side data type James Almer
` (3 preceding siblings ...)
2024-05-29 21:46 ` [FFmpeg-devel] [PATCH 5/6] fftools/ffmpeg: support applying container level cropping James Almer
@ 2024-05-29 21:46 ` James Almer
2024-05-30 1:02 ` [FFmpeg-devel] [PATCH 1/6] avcodec/packet: add a decoded frame cropping side data type Lynne via ffmpeg-devel
2024-06-25 18:13 ` Andreas Rheinhardt
6 siblings, 0 replies; 27+ messages in thread
From: James Almer @ 2024-05-29 21:46 UTC (permalink / raw)
To: ffmpeg-devel
Signed-off-by: James Almer <jamrial@gmail.com>
---
fftools/ffplay.c | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/fftools/ffplay.c b/fftools/ffplay.c
index 1d0511b254..47e2865abb 100644
--- a/fftools/ffplay.c
+++ b/fftools/ffplay.c
@@ -32,6 +32,7 @@
#include "libavutil/avstring.h"
#include "libavutil/channel_layout.h"
+#include "libavutil/intreadwrite.h"
#include "libavutil/mathematics.h"
#include "libavutil/mem.h"
#include "libavutil/pixdesc.h"
@@ -346,6 +347,7 @@ static const char **vfilters_list = NULL;
static int nb_vfilters = 0;
static char *afilters = NULL;
static int autorotate = 1;
+static int apply_cropping = 1;
static int find_stream_info = 1;
static int filter_nbthreads = 0;
static int enable_vulkan = 0;
@@ -1947,6 +1949,28 @@ static int configure_video_filters(AVFilterGraph *graph, VideoState *is, const c
last_filter = filt_ctx; \
} while (0)
+ if (apply_cropping) {
+ const AVPacketSideData *sd = av_packet_side_data_get(is->video_st->codecpar->coded_side_data,
+ is->video_st->codecpar->nb_coded_side_data,
+ AV_PKT_DATA_FRAME_CROPPING);
+
+ if (sd && sd->size == sizeof(uint32_t) * 4) {
+ char crop_buf[64];
+ int top = AV_RL32(sd->data + 0);
+ int bottom = AV_RL32(sd->data + 4);
+ int left = AV_RL32(sd->data + 8);
+ int right = AV_RL32(sd->data + 12);
+
+ if (top < 0 || bottom < 0 || left < 0 || right < 0) {
+ ret = AVERROR(EINVAL);
+ goto fail;
+ }
+
+ snprintf(crop_buf, sizeof(crop_buf), "w=iw-%d-%d:h=ih-%d-%d", left, right, top, bottom);
+ INSERT_FILT("crop", crop_buf);
+ }
+ }
+
if (autorotate) {
double theta = 0.0;
int32_t *displaymatrix = NULL;
@@ -3691,6 +3715,7 @@ static const OptionDef options[] = {
{ "scodec", OPT_TYPE_STRING, OPT_EXPERT, { &subtitle_codec_name }, "force subtitle decoder", "decoder_name" },
{ "vcodec", OPT_TYPE_STRING, OPT_EXPERT, { &video_codec_name }, "force video decoder", "decoder_name" },
{ "autorotate", OPT_TYPE_BOOL, 0, { &autorotate }, "automatically rotate video", "" },
+ { "apply_cropping", OPT_TYPE_BOOL, 0, { &apply_cropping }, "apply container level frame cropping", "" },
{ "find_stream_info", OPT_TYPE_BOOL, OPT_INPUT | OPT_EXPERT, { &find_stream_info },
"read and decode the streams to fill missing information with heuristics" },
{ "filter_threads", OPT_TYPE_INT, OPT_EXPERT, { &filter_nbthreads }, "number of filter threads per graph" },
--
2.45.1
_______________________________________________
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] 27+ messages in thread
* Re: [FFmpeg-devel] [PATCH 5/6] fftools/ffmpeg: support applying container level cropping
2024-05-29 21:46 ` [FFmpeg-devel] [PATCH 5/6] fftools/ffmpeg: support applying container level cropping James Almer
@ 2024-05-30 1:01 ` Lynne via ffmpeg-devel
2024-05-30 1:04 ` James Almer
2024-05-30 22:57 ` Michael Niedermayer
2024-06-25 10:19 ` [FFmpeg-devel] [PATCH 5/6] " Anton Khirnov
2 siblings, 1 reply; 27+ messages in thread
From: Lynne via ffmpeg-devel @ 2024-05-30 1:01 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Lynne
[-- Attachment #1.1.1.1: Type: text/plain, Size: 6521 bytes --]
On 29/05/2024 23:46, James Almer wrote:
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
> fftools/ffmpeg.h | 7 +++++++
> fftools/ffmpeg_demux.c | 16 ++++++++++++++++
> fftools/ffmpeg_filter.c | 11 +++++++++++
> fftools/ffmpeg_opt.c | 3 +++
> 4 files changed, 37 insertions(+)
>
> diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
> index fe75706afd..f908e16549 100644
> --- a/fftools/ffmpeg.h
> +++ b/fftools/ffmpeg.h
> @@ -155,6 +155,7 @@ typedef struct OptionsContext {
> SpecifierOptList hwaccel_devices;
> SpecifierOptList hwaccel_output_formats;
> SpecifierOptList autorotate;
> + SpecifierOptList apply_cropping;
>
> /* output options */
> StreamMap *stream_maps;
> @@ -239,6 +240,7 @@ enum IFilterFlags {
> IFILTER_FLAG_AUTOROTATE = (1 << 0),
> IFILTER_FLAG_REINIT = (1 << 1),
> IFILTER_FLAG_CFR = (1 << 2),
> + IFILTER_FLAG_CROP = (1 << 3),
> };
>
> typedef struct InputFilterOptions {
> @@ -254,6 +256,11 @@ typedef struct InputFilterOptions {
> * accurate */
> AVRational framerate;
>
> + unsigned crop_top;
> + unsigned crop_bottom;
> + unsigned crop_left;
> + unsigned crop_right;
> +
> int sub2video_width;
> int sub2video_height;
>
> diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
> index 1ca8d804ae..4178b8f840 100644
> --- a/fftools/ffmpeg_demux.c
> +++ b/fftools/ffmpeg_demux.c
> @@ -66,6 +66,7 @@ typedef struct DemuxStream {
> int have_sub2video;
> int reinit_filters;
> int autorotate;
> + int apply_cropping;
>
>
> int wrap_correction_done;
> @@ -1000,11 +1001,20 @@ int ist_filter_add(InputStream *ist, InputFilter *ifilter, int is_simple,
> ist->filters[ist->nb_filters - 1] = ifilter;
>
> if (ist->par->codec_type == AVMEDIA_TYPE_VIDEO) {
> + const AVPacketSideData *sd = av_packet_side_data_get(ist->st->codecpar->coded_side_data,
> + ist->st->codecpar->nb_coded_side_data,
> + AV_PKT_DATA_FRAME_CROPPING);
> if (ist->framerate.num > 0 && ist->framerate.den > 0) {
> opts->framerate = ist->framerate;
> opts->flags |= IFILTER_FLAG_CFR;
> } else
> opts->framerate = av_guess_frame_rate(d->f.ctx, ist->st, NULL);
> + if (sd && sd->size == sizeof(uint32_t) * 4) {
> + opts->crop_top = AV_RL32(sd->data + 0);
> + opts->crop_bottom = AV_RL32(sd->data + 4);
> + opts->crop_left = AV_RL32(sd->data + 8);
> + opts->crop_right = AV_RL32(sd->data + 12);
> + }
> } else if (ist->par->codec_type == AVMEDIA_TYPE_SUBTITLE) {
> /* Compute the size of the canvas for the subtitles stream.
> If the subtitles codecpar has set a size, use it. Otherwise use the
> @@ -1059,6 +1069,7 @@ int ist_filter_add(InputStream *ist, InputFilter *ifilter, int is_simple,
> return AVERROR(ENOMEM);
>
> opts->flags |= IFILTER_FLAG_AUTOROTATE * !!(ds->autorotate) |
> + IFILTER_FLAG_CROP * !!(ds->apply_cropping) |
> IFILTER_FLAG_REINIT * !!(ds->reinit_filters);
>
> return ds->sch_idx_dec;
> @@ -1241,6 +1252,9 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st)
> ds->autorotate = 1;
> MATCH_PER_STREAM_OPT(autorotate, i, ds->autorotate, ic, st);
>
> + ds->apply_cropping = 1;
> + MATCH_PER_STREAM_OPT(apply_cropping, i, ds->apply_cropping, ic, st);
> +
> MATCH_PER_STREAM_OPT(codec_tags, str, codec_tag, ic, st);
> if (codec_tag) {
> uint32_t tag = strtol(codec_tag, &next, 0);
> @@ -1362,6 +1376,8 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st)
>
> ds->dec_opts.flags |= DECODER_FLAG_BITEXACT * !!o->bitexact;
>
> + av_dict_set_int(&ds->decoder_opts, "apply_cropping", ds->apply_cropping, 0);
> +
> /* Attached pics are sparse, therefore we would not want to delay their decoding
> * till EOF. */
> if (ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC)
> diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
> index 12cca684b4..a31fa1be7f 100644
> --- a/fftools/ffmpeg_filter.c
> +++ b/fftools/ffmpeg_filter.c
> @@ -1701,6 +1701,17 @@ static int configure_input_video_filter(FilterGraph *fg, AVFilterGraph *graph,
> desc = av_pix_fmt_desc_get(ifp->format);
> av_assert0(desc);
>
> + if ((ifp->opts.flags & IFILTER_FLAG_CROP) &&
> + !(desc->flags & AV_PIX_FMT_FLAG_HWACCEL)) {
> + char crop_buf[64];
> + snprintf(crop_buf, sizeof(crop_buf), "w=iw-%d-%d:h=ih-%d-%d",
> + ifp->opts.crop_left, ifp->opts.crop_right,
> + ifp->opts.crop_top, ifp->opts.crop_bottom);
> + ret = insert_filter(&last_filter, &pad_idx, "crop", crop_buf);
> + if (ret < 0)
> + return ret;
> + }
The crop filter supports hardware frames too.
> +
> // TODO: insert hwaccel enabled filters like transpose_vaapi into the graph
> ifp->displaymatrix_applied = 0;
> if ((ifp->opts.flags & IFILTER_FLAG_AUTOROTATE) &&
> diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
> index 910e4a336b..0c50ce16ba 100644
> --- a/fftools/ffmpeg_opt.c
> +++ b/fftools/ffmpeg_opt.c
> @@ -1732,6 +1732,9 @@ const OptionDef options[] = {
> { "autoscale", OPT_TYPE_BOOL, OPT_PERSTREAM | OPT_EXPERT | OPT_OUTPUT,
> { .off = OFFSET(autoscale) },
> "automatically insert a scale filter at the end of the filter graph" },
> + { "apply_cropping", OPT_TYPE_BOOL, OPT_PERSTREAM | OPT_EXPERT | OPT_INPUT,
> + { .off = OFFSET(apply_cropping) },
> + "apply frame cropping" },
Any reason why it can't be enabled by default?
> { "fix_sub_duration_heartbeat", OPT_TYPE_BOOL, OPT_VIDEO | OPT_EXPERT | OPT_PERSTREAM | OPT_OUTPUT,
> { .off = OFFSET(fix_sub_duration_heartbeat) },
> "set this video output stream to be a heartbeat stream for "
[-- Attachment #1.1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 637 bytes --]
[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 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] 27+ messages in thread
* Re: [FFmpeg-devel] [PATCH 1/6] avcodec/packet: add a decoded frame cropping side data type
2024-05-29 21:46 [FFmpeg-devel] [PATCH 1/6] avcodec/packet: add a decoded frame cropping side data type James Almer
` (4 preceding siblings ...)
2024-05-29 21:46 ` [FFmpeg-devel] [PATCH 6/6] fftools/ffplay: " James Almer
@ 2024-05-30 1:02 ` Lynne via ffmpeg-devel
2024-05-30 1:08 ` James Almer
2024-06-25 18:13 ` Andreas Rheinhardt
6 siblings, 1 reply; 27+ messages in thread
From: Lynne via ffmpeg-devel @ 2024-05-30 1:02 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Lynne
[-- Attachment #1.1.1.1: Type: text/plain, Size: 1111 bytes --]
On 29/05/2024 23:46, James Almer wrote:
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
> libavcodec/packet.h | 14 ++++++++++++++
> 1 file changed, 14 insertions(+)
>
> diff --git a/libavcodec/packet.h b/libavcodec/packet.h
> index a9a41576da..9dee035690 100644
> --- a/libavcodec/packet.h
> +++ b/libavcodec/packet.h
> @@ -330,6 +330,20 @@ enum AVPacketSideDataType {
> */
> AV_PKT_DATA_AMBIENT_VIEWING_ENVIRONMENT,
>
> + /**
> + * The number of pixels to discard from the
> + * top/bottom/left/right border of the decoded frame to obtain the sub-rectangle
> + * intended for presentation.
> + *
> + * @code
> + * u32le crop_top
> + * u32le crop_bottom
> + * u32le crop_left
> + * u32le crop_right
> + * @endcode
> + */
> + AV_PKT_DATA_FRAME_CROPPING,
> +
> /**
> * The number of side data types.
> * This is not part of the public API/ABI in the sense that it may
Shouldn't this be propagated to the frame's crop fields, and back from
the crop fields to the packet side-data?
[-- Attachment #1.1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 637 bytes --]
[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 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] 27+ messages in thread
* Re: [FFmpeg-devel] [PATCH 5/6] fftools/ffmpeg: support applying container level cropping
2024-05-30 1:01 ` Lynne via ffmpeg-devel
@ 2024-05-30 1:04 ` James Almer
2024-05-31 1:13 ` Lynne via ffmpeg-devel
0 siblings, 1 reply; 27+ messages in thread
From: James Almer @ 2024-05-30 1:04 UTC (permalink / raw)
To: ffmpeg-devel
On 5/29/2024 10:01 PM, Lynne via ffmpeg-devel wrote:
> On 29/05/2024 23:46, James Almer wrote:
>> Signed-off-by: James Almer <jamrial@gmail.com>
>> ---
>> fftools/ffmpeg.h | 7 +++++++
>> fftools/ffmpeg_demux.c | 16 ++++++++++++++++
>> fftools/ffmpeg_filter.c | 11 +++++++++++
>> fftools/ffmpeg_opt.c | 3 +++
>> 4 files changed, 37 insertions(+)
>>
>> diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
>> index fe75706afd..f908e16549 100644
>> --- a/fftools/ffmpeg.h
>> +++ b/fftools/ffmpeg.h
>> @@ -155,6 +155,7 @@ typedef struct OptionsContext {
>> SpecifierOptList hwaccel_devices;
>> SpecifierOptList hwaccel_output_formats;
>> SpecifierOptList autorotate;
>> + SpecifierOptList apply_cropping;
>> /* output options */
>> StreamMap *stream_maps;
>> @@ -239,6 +240,7 @@ enum IFilterFlags {
>> IFILTER_FLAG_AUTOROTATE = (1 << 0),
>> IFILTER_FLAG_REINIT = (1 << 1),
>> IFILTER_FLAG_CFR = (1 << 2),
>> + IFILTER_FLAG_CROP = (1 << 3),
>> };
>> typedef struct InputFilterOptions {
>> @@ -254,6 +256,11 @@ typedef struct InputFilterOptions {
>> * accurate */
>> AVRational framerate;
>> + unsigned crop_top;
>> + unsigned crop_bottom;
>> + unsigned crop_left;
>> + unsigned crop_right;
>> +
>> int sub2video_width;
>> int sub2video_height;
>> diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
>> index 1ca8d804ae..4178b8f840 100644
>> --- a/fftools/ffmpeg_demux.c
>> +++ b/fftools/ffmpeg_demux.c
>> @@ -66,6 +66,7 @@ typedef struct DemuxStream {
>> int have_sub2video;
>> int reinit_filters;
>> int autorotate;
>> + int apply_cropping;
>> int wrap_correction_done;
>> @@ -1000,11 +1001,20 @@ int ist_filter_add(InputStream *ist,
>> InputFilter *ifilter, int is_simple,
>> ist->filters[ist->nb_filters - 1] = ifilter;
>> if (ist->par->codec_type == AVMEDIA_TYPE_VIDEO) {
>> + const AVPacketSideData *sd =
>> av_packet_side_data_get(ist->st->codecpar->coded_side_data,
>> +
>> ist->st->codecpar->nb_coded_side_data,
>> +
>> AV_PKT_DATA_FRAME_CROPPING);
>> if (ist->framerate.num > 0 && ist->framerate.den > 0) {
>> opts->framerate = ist->framerate;
>> opts->flags |= IFILTER_FLAG_CFR;
>> } else
>> opts->framerate = av_guess_frame_rate(d->f.ctx, ist->st,
>> NULL);
>> + if (sd && sd->size == sizeof(uint32_t) * 4) {
>> + opts->crop_top = AV_RL32(sd->data + 0);
>> + opts->crop_bottom = AV_RL32(sd->data + 4);
>> + opts->crop_left = AV_RL32(sd->data + 8);
>> + opts->crop_right = AV_RL32(sd->data + 12);
>> + }
>> } else if (ist->par->codec_type == AVMEDIA_TYPE_SUBTITLE) {
>> /* Compute the size of the canvas for the subtitles stream.
>> If the subtitles codecpar has set a size, use it.
>> Otherwise use the
>> @@ -1059,6 +1069,7 @@ int ist_filter_add(InputStream *ist, InputFilter
>> *ifilter, int is_simple,
>> return AVERROR(ENOMEM);
>> opts->flags |= IFILTER_FLAG_AUTOROTATE * !!(ds->autorotate) |
>> + IFILTER_FLAG_CROP * !!(ds->apply_cropping) |
>> IFILTER_FLAG_REINIT * !!(ds->reinit_filters);
>> return ds->sch_idx_dec;
>> @@ -1241,6 +1252,9 @@ static int ist_add(const OptionsContext *o,
>> Demuxer *d, AVStream *st)
>> ds->autorotate = 1;
>> MATCH_PER_STREAM_OPT(autorotate, i, ds->autorotate, ic, st);
>> + ds->apply_cropping = 1;
>> + MATCH_PER_STREAM_OPT(apply_cropping, i, ds->apply_cropping, ic, st);
>> +
>> MATCH_PER_STREAM_OPT(codec_tags, str, codec_tag, ic, st);
>> if (codec_tag) {
>> uint32_t tag = strtol(codec_tag, &next, 0);
>> @@ -1362,6 +1376,8 @@ static int ist_add(const OptionsContext *o,
>> Demuxer *d, AVStream *st)
>> ds->dec_opts.flags |= DECODER_FLAG_BITEXACT * !!o->bitexact;
>> + av_dict_set_int(&ds->decoder_opts, "apply_cropping",
>> ds->apply_cropping, 0);
>> +
>> /* Attached pics are sparse, therefore we would not want to
>> delay their decoding
>> * till EOF. */
>> if (ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC)
>> diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
>> index 12cca684b4..a31fa1be7f 100644
>> --- a/fftools/ffmpeg_filter.c
>> +++ b/fftools/ffmpeg_filter.c
>> @@ -1701,6 +1701,17 @@ static int
>> configure_input_video_filter(FilterGraph *fg, AVFilterGraph *graph,
>> desc = av_pix_fmt_desc_get(ifp->format);
>> av_assert0(desc);
>> + if ((ifp->opts.flags & IFILTER_FLAG_CROP) &&
>> + !(desc->flags & AV_PIX_FMT_FLAG_HWACCEL)) {
>> + char crop_buf[64];
>> + snprintf(crop_buf, sizeof(crop_buf), "w=iw-%d-%d:h=ih-%d-%d",
>> + ifp->opts.crop_left, ifp->opts.crop_right,
>> + ifp->opts.crop_top, ifp->opts.crop_bottom);
>> + ret = insert_filter(&last_filter, &pad_idx, "crop", crop_buf);
>> + if (ret < 0)
>> + return ret;
>> + }
>
> The crop filter supports hardware frames too.
It exports the values within the AVFrame fields. If that's acceptable
then i can remove this check.
>
>> +
>> // TODO: insert hwaccel enabled filters like transpose_vaapi
>> into the graph
>> ifp->displaymatrix_applied = 0;
>> if ((ifp->opts.flags & IFILTER_FLAG_AUTOROTATE) &&
>> diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
>> index 910e4a336b..0c50ce16ba 100644
>> --- a/fftools/ffmpeg_opt.c
>> +++ b/fftools/ffmpeg_opt.c
>> @@ -1732,6 +1732,9 @@ const OptionDef options[] = {
>> { "autoscale", OPT_TYPE_BOOL, OPT_PERSTREAM |
>> OPT_EXPERT | OPT_OUTPUT,
>> { .off = OFFSET(autoscale) },
>> "automatically insert a scale filter at the end of the
>> filter graph" },
>> + { "apply_cropping", OPT_TYPE_BOOL, OPT_PERSTREAM |
>> OPT_EXPERT | OPT_INPUT,
>> + { .off = OFFSET(apply_cropping) },
>> + "apply frame cropping" },
>
> Any reason why it can't be enabled by default?
Is is. Look at the line above the relevant MATCH_PER_STREAM_OPT line.
>
>> { "fix_sub_duration_heartbeat", OPT_TYPE_BOOL, OPT_VIDEO |
>> OPT_EXPERT | OPT_PERSTREAM | OPT_OUTPUT,
>> { .off = OFFSET(fix_sub_duration_heartbeat) },
>> "set this video output stream to be a heartbeat stream for "
>
>
> _______________________________________________
> 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".
_______________________________________________
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] 27+ messages in thread
* Re: [FFmpeg-devel] [PATCH 1/6] avcodec/packet: add a decoded frame cropping side data type
2024-05-30 1:02 ` [FFmpeg-devel] [PATCH 1/6] avcodec/packet: add a decoded frame cropping side data type Lynne via ffmpeg-devel
@ 2024-05-30 1:08 ` James Almer
0 siblings, 0 replies; 27+ messages in thread
From: James Almer @ 2024-05-30 1:08 UTC (permalink / raw)
To: ffmpeg-devel
On 5/29/2024 10:02 PM, Lynne via ffmpeg-devel wrote:
> On 29/05/2024 23:46, James Almer wrote:
>> Signed-off-by: James Almer <jamrial@gmail.com>
>> ---
>> libavcodec/packet.h | 14 ++++++++++++++
>> 1 file changed, 14 insertions(+)
>>
>> diff --git a/libavcodec/packet.h b/libavcodec/packet.h
>> index a9a41576da..9dee035690 100644
>> --- a/libavcodec/packet.h
>> +++ b/libavcodec/packet.h
>> @@ -330,6 +330,20 @@ enum AVPacketSideDataType {
>> */
>> AV_PKT_DATA_AMBIENT_VIEWING_ENVIRONMENT,
>> + /**
>> + * The number of pixels to discard from the
>> + * top/bottom/left/right border of the decoded frame to obtain
>> the sub-rectangle
>> + * intended for presentation.
>> + *
>> + * @code
>> + * u32le crop_top
>> + * u32le crop_bottom
>> + * u32le crop_left
>> + * u32le crop_right
>> + * @endcode
>> + */
>> + AV_PKT_DATA_FRAME_CROPPING,
>> +
>> /**
>> * The number of side data types.
>> * This is not part of the public API/ABI in the sense that it may
>
> Shouldn't this be propagated to the frame's crop fields, and back from
> the crop fields to the packet side-data?
We no longer use frames and packets to communicate global side data, and
we can't use frame cropping values as global metadata for the
container's header because there's codec level cropping too (like h264
to remove padding coded at certain dimensions) in them.
_______________________________________________
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] 27+ messages in thread
* Re: [FFmpeg-devel] [PATCH 5/6] fftools/ffmpeg: support applying container level cropping
2024-05-29 21:46 ` [FFmpeg-devel] [PATCH 5/6] fftools/ffmpeg: support applying container level cropping James Almer
2024-05-30 1:01 ` Lynne via ffmpeg-devel
@ 2024-05-30 22:57 ` Michael Niedermayer
2024-05-30 23:22 ` [FFmpeg-devel] [PATCH 1/2 v2] " James Almer
2024-06-25 10:19 ` [FFmpeg-devel] [PATCH 5/6] " Anton Khirnov
2 siblings, 1 reply; 27+ messages in thread
From: Michael Niedermayer @ 2024-05-30 22:57 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1.1: Type: text/plain, Size: 1367 bytes --]
On Wed, May 29, 2024 at 06:46:31PM -0300, James Almer wrote:
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
> fftools/ffmpeg.h | 7 +++++++
> fftools/ffmpeg_demux.c | 16 ++++++++++++++++
> fftools/ffmpeg_filter.c | 11 +++++++++++
> fftools/ffmpeg_opt.c | 3 +++
> 4 files changed, 37 insertions(+)
seems to break fate here
--- ./tests/ref/vsynth/vsynth1-dnxhd-edge2-hr 2024-05-28 01:00:33.943039144 +0200
+++ tests/data/fate/vsynth1-dnxhd-edge2-hr 2024-05-31 00:56:06.577710365 +0200
@@ -1,4 +1,4 @@
3ebeb52ae53a5b2ae4a0d90fa728c4fa *tests/data/fate/vsynth1-dnxhd-edge2-hr.dnxhd
81920 tests/data/fate/vsynth1-dnxhd-edge2-hr.dnxhd
-1763637504f89c4e1a50a4de25c5e58a *tests/data/fate/vsynth1-dnxhd-edge2-hr.out.rawvideo
-stddev: 15.86 PSNR: 24.12 MAXDIFF: 157 bytes: 7603200/ 760320
+dfa27c2e0f422c873c45d5abfcedf75f *tests/data/fate/vsynth1-dnxhd-edge2-hr.out.rawvideo
+stddev: 19.61 PSNR: 22.28 MAXDIFF: 170 bytes: 7603200/ 760320
Test vsynth1-dnxhd-edge2-hr failed. Look at tests/data/fate/vsynth1-dnxhd-edge2-hr.err for details.
make: *** [tests/Makefile:311: fate-vsynth1-dnxhd-edge2-hr] Error 1
thx
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
If you think the mosad wants you dead since a long time then you are either
wrong or dead since a long time.
[-- 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] 27+ messages in thread
* [FFmpeg-devel] [PATCH 1/2 v2] fftools/ffmpeg: support applying container level cropping
2024-05-30 22:57 ` Michael Niedermayer
@ 2024-05-30 23:22 ` James Almer
2024-06-25 10:25 ` Anton Khirnov
0 siblings, 1 reply; 27+ messages in thread
From: James Almer @ 2024-05-30 23:22 UTC (permalink / raw)
To: ffmpeg-devel
Signed-off-by: James Almer <jamrial@gmail.com>
---
fftools/ffmpeg.h | 7 +++++++
fftools/ffmpeg_demux.c | 16 ++++++++++++++++
fftools/ffmpeg_filter.c | 10 ++++++++++
fftools/ffmpeg_opt.c | 3 +++
4 files changed, 36 insertions(+)
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index fe75706afd..f908e16549 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -155,6 +155,7 @@ typedef struct OptionsContext {
SpecifierOptList hwaccel_devices;
SpecifierOptList hwaccel_output_formats;
SpecifierOptList autorotate;
+ SpecifierOptList apply_cropping;
/* output options */
StreamMap *stream_maps;
@@ -239,6 +240,7 @@ enum IFilterFlags {
IFILTER_FLAG_AUTOROTATE = (1 << 0),
IFILTER_FLAG_REINIT = (1 << 1),
IFILTER_FLAG_CFR = (1 << 2),
+ IFILTER_FLAG_CROP = (1 << 3),
};
typedef struct InputFilterOptions {
@@ -254,6 +256,11 @@ typedef struct InputFilterOptions {
* accurate */
AVRational framerate;
+ unsigned crop_top;
+ unsigned crop_bottom;
+ unsigned crop_left;
+ unsigned crop_right;
+
int sub2video_width;
int sub2video_height;
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index 1ca8d804ae..011b56709f 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -66,6 +66,7 @@ typedef struct DemuxStream {
int have_sub2video;
int reinit_filters;
int autorotate;
+ int apply_cropping;
int wrap_correction_done;
@@ -1000,11 +1001,21 @@ int ist_filter_add(InputStream *ist, InputFilter *ifilter, int is_simple,
ist->filters[ist->nb_filters - 1] = ifilter;
if (ist->par->codec_type == AVMEDIA_TYPE_VIDEO) {
+ const AVPacketSideData *sd = av_packet_side_data_get(ist->par->coded_side_data,
+ ist->par->nb_coded_side_data,
+ AV_PKT_DATA_FRAME_CROPPING);
if (ist->framerate.num > 0 && ist->framerate.den > 0) {
opts->framerate = ist->framerate;
opts->flags |= IFILTER_FLAG_CFR;
} else
opts->framerate = av_guess_frame_rate(d->f.ctx, ist->st, NULL);
+ if (sd && sd->size == sizeof(uint32_t) * 4) {
+ opts->crop_top = AV_RL32(sd->data + 0);
+ opts->crop_bottom = AV_RL32(sd->data + 4);
+ opts->crop_left = AV_RL32(sd->data + 8);
+ opts->crop_right = AV_RL32(sd->data + 12);
+ opts->flags |= IFILTER_FLAG_CROP;
+ }
} else if (ist->par->codec_type == AVMEDIA_TYPE_SUBTITLE) {
/* Compute the size of the canvas for the subtitles stream.
If the subtitles codecpar has set a size, use it. Otherwise use the
@@ -1241,6 +1252,9 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st)
ds->autorotate = 1;
MATCH_PER_STREAM_OPT(autorotate, i, ds->autorotate, ic, st);
+ ds->apply_cropping = 1;
+ MATCH_PER_STREAM_OPT(apply_cropping, i, ds->apply_cropping, ic, st);
+
MATCH_PER_STREAM_OPT(codec_tags, str, codec_tag, ic, st);
if (codec_tag) {
uint32_t tag = strtol(codec_tag, &next, 0);
@@ -1362,6 +1376,8 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st)
ds->dec_opts.flags |= DECODER_FLAG_BITEXACT * !!o->bitexact;
+ av_dict_set_int(&ds->decoder_opts, "apply_cropping", ds->apply_cropping, 0);
+
/* Attached pics are sparse, therefore we would not want to delay their decoding
* till EOF. */
if (ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC)
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 12cca684b4..f3087afc88 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -1701,6 +1701,16 @@ static int configure_input_video_filter(FilterGraph *fg, AVFilterGraph *graph,
desc = av_pix_fmt_desc_get(ifp->format);
av_assert0(desc);
+ if ((ifp->opts.flags & IFILTER_FLAG_CROP)) {
+ char crop_buf[64];
+ snprintf(crop_buf, sizeof(crop_buf), "w=iw-%d-%d:h=ih-%d-%d",
+ ifp->opts.crop_left, ifp->opts.crop_right,
+ ifp->opts.crop_top, ifp->opts.crop_bottom);
+ ret = insert_filter(&last_filter, &pad_idx, "crop", crop_buf);
+ if (ret < 0)
+ return ret;
+ }
+
// TODO: insert hwaccel enabled filters like transpose_vaapi into the graph
ifp->displaymatrix_applied = 0;
if ((ifp->opts.flags & IFILTER_FLAG_AUTOROTATE) &&
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index 910e4a336b..0c50ce16ba 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -1732,6 +1732,9 @@ const OptionDef options[] = {
{ "autoscale", OPT_TYPE_BOOL, OPT_PERSTREAM | OPT_EXPERT | OPT_OUTPUT,
{ .off = OFFSET(autoscale) },
"automatically insert a scale filter at the end of the filter graph" },
+ { "apply_cropping", OPT_TYPE_BOOL, OPT_PERSTREAM | OPT_EXPERT | OPT_INPUT,
+ { .off = OFFSET(apply_cropping) },
+ "apply frame cropping" },
{ "fix_sub_duration_heartbeat", OPT_TYPE_BOOL, OPT_VIDEO | OPT_EXPERT | OPT_PERSTREAM | OPT_OUTPUT,
{ .off = OFFSET(fix_sub_duration_heartbeat) },
"set this video output stream to be a heartbeat stream for "
--
2.45.1
_______________________________________________
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] 27+ messages in thread
* Re: [FFmpeg-devel] [PATCH 5/6] fftools/ffmpeg: support applying container level cropping
2024-05-30 1:04 ` James Almer
@ 2024-05-31 1:13 ` Lynne via ffmpeg-devel
0 siblings, 0 replies; 27+ messages in thread
From: Lynne via ffmpeg-devel @ 2024-05-31 1:13 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Lynne
[-- Attachment #1.1.1.1: Type: text/plain, Size: 6509 bytes --]
On 30/05/2024 03:04, James Almer wrote:
> On 5/29/2024 10:01 PM, Lynne via ffmpeg-devel wrote:
>> On 29/05/2024 23:46, James Almer wrote:
>>> Signed-off-by: James Almer <jamrial@gmail.com>
>>> ---
>>> fftools/ffmpeg.h | 7 +++++++
>>> fftools/ffmpeg_demux.c | 16 ++++++++++++++++
>>> fftools/ffmpeg_filter.c | 11 +++++++++++
>>> fftools/ffmpeg_opt.c | 3 +++
>>> 4 files changed, 37 insertions(+)
>>>
>>> diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
>>> index fe75706afd..f908e16549 100644
>>> --- a/fftools/ffmpeg.h
>>> +++ b/fftools/ffmpeg.h
>>> @@ -155,6 +155,7 @@ typedef struct OptionsContext {
>>> SpecifierOptList hwaccel_devices;
>>> SpecifierOptList hwaccel_output_formats;
>>> SpecifierOptList autorotate;
>>> + SpecifierOptList apply_cropping;
>>> /* output options */
>>> StreamMap *stream_maps;
>>> @@ -239,6 +240,7 @@ enum IFilterFlags {
>>> IFILTER_FLAG_AUTOROTATE = (1 << 0),
>>> IFILTER_FLAG_REINIT = (1 << 1),
>>> IFILTER_FLAG_CFR = (1 << 2),
>>> + IFILTER_FLAG_CROP = (1 << 3),
>>> };
>>> typedef struct InputFilterOptions {
>>> @@ -254,6 +256,11 @@ typedef struct InputFilterOptions {
>>> * accurate */
>>> AVRational framerate;
>>> + unsigned crop_top;
>>> + unsigned crop_bottom;
>>> + unsigned crop_left;
>>> + unsigned crop_right;
>>> +
>>> int sub2video_width;
>>> int sub2video_height;
>>> diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
>>> index 1ca8d804ae..4178b8f840 100644
>>> --- a/fftools/ffmpeg_demux.c
>>> +++ b/fftools/ffmpeg_demux.c
>>> @@ -66,6 +66,7 @@ typedef struct DemuxStream {
>>> int have_sub2video;
>>> int reinit_filters;
>>> int autorotate;
>>> + int apply_cropping;
>>> int wrap_correction_done;
>>> @@ -1000,11 +1001,20 @@ int ist_filter_add(InputStream *ist,
>>> InputFilter *ifilter, int is_simple,
>>> ist->filters[ist->nb_filters - 1] = ifilter;
>>> if (ist->par->codec_type == AVMEDIA_TYPE_VIDEO) {
>>> + const AVPacketSideData *sd =
>>> av_packet_side_data_get(ist->st->codecpar->coded_side_data,
>>> + ist->st->codecpar->nb_coded_side_data,
>>> + AV_PKT_DATA_FRAME_CROPPING);
>>> if (ist->framerate.num > 0 && ist->framerate.den > 0) {
>>> opts->framerate = ist->framerate;
>>> opts->flags |= IFILTER_FLAG_CFR;
>>> } else
>>> opts->framerate = av_guess_frame_rate(d->f.ctx,
>>> ist->st, NULL);
>>> + if (sd && sd->size == sizeof(uint32_t) * 4) {
>>> + opts->crop_top = AV_RL32(sd->data + 0);
>>> + opts->crop_bottom = AV_RL32(sd->data + 4);
>>> + opts->crop_left = AV_RL32(sd->data + 8);
>>> + opts->crop_right = AV_RL32(sd->data + 12);
>>> + }
>>> } else if (ist->par->codec_type == AVMEDIA_TYPE_SUBTITLE) {
>>> /* Compute the size of the canvas for the subtitles stream.
>>> If the subtitles codecpar has set a size, use it.
>>> Otherwise use the
>>> @@ -1059,6 +1069,7 @@ int ist_filter_add(InputStream *ist,
>>> InputFilter *ifilter, int is_simple,
>>> return AVERROR(ENOMEM);
>>> opts->flags |= IFILTER_FLAG_AUTOROTATE * !!(ds->autorotate) |
>>> + IFILTER_FLAG_CROP * !!(ds->apply_cropping) |
>>> IFILTER_FLAG_REINIT * !!(ds->reinit_filters);
>>> return ds->sch_idx_dec;
>>> @@ -1241,6 +1252,9 @@ static int ist_add(const OptionsContext *o,
>>> Demuxer *d, AVStream *st)
>>> ds->autorotate = 1;
>>> MATCH_PER_STREAM_OPT(autorotate, i, ds->autorotate, ic, st);
>>> + ds->apply_cropping = 1;
>>> + MATCH_PER_STREAM_OPT(apply_cropping, i, ds->apply_cropping, ic,
>>> st);
>>> +
>>> MATCH_PER_STREAM_OPT(codec_tags, str, codec_tag, ic, st);
>>> if (codec_tag) {
>>> uint32_t tag = strtol(codec_tag, &next, 0);
>>> @@ -1362,6 +1376,8 @@ static int ist_add(const OptionsContext *o,
>>> Demuxer *d, AVStream *st)
>>> ds->dec_opts.flags |= DECODER_FLAG_BITEXACT * !!o->bitexact;
>>> + av_dict_set_int(&ds->decoder_opts, "apply_cropping",
>>> ds->apply_cropping, 0);
>>> +
>>> /* Attached pics are sparse, therefore we would not want to
>>> delay their decoding
>>> * till EOF. */
>>> if (ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC)
>>> diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
>>> index 12cca684b4..a31fa1be7f 100644
>>> --- a/fftools/ffmpeg_filter.c
>>> +++ b/fftools/ffmpeg_filter.c
>>> @@ -1701,6 +1701,17 @@ static int
>>> configure_input_video_filter(FilterGraph *fg, AVFilterGraph *graph,
>>> desc = av_pix_fmt_desc_get(ifp->format);
>>> av_assert0(desc);
>>> + if ((ifp->opts.flags & IFILTER_FLAG_CROP) &&
>>> + !(desc->flags & AV_PIX_FMT_FLAG_HWACCEL)) {
>>> + char crop_buf[64];
>>> + snprintf(crop_buf, sizeof(crop_buf), "w=iw-%d-%d:h=ih-%d-%d",
>>> + ifp->opts.crop_left, ifp->opts.crop_right,
>>> + ifp->opts.crop_top, ifp->opts.crop_bottom);
>>> + ret = insert_filter(&last_filter, &pad_idx, "crop", crop_buf);
>>> + if (ret < 0)
>>> + return ret;
>>> + }
>>
>> The crop filter supports hardware frames too.
>
> It exports the values within the AVFrame fields. If that's acceptable
> then i can remove this check.
Sure, that's acceptable. If anything, it would help get better support
for AVFrame's crop fields through the codebase.
[-- Attachment #1.1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 637 bytes --]
[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 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] 27+ messages in thread
* Re: [FFmpeg-devel] [PATCH 3/6] avformat/matroskadec: export cropping values
2024-05-29 21:46 ` [FFmpeg-devel] [PATCH 3/6] avformat/matroskadec: export cropping values James Almer
@ 2024-06-01 11:24 ` Kacper Michajlow
2024-07-05 20:51 ` James Almer
0 siblings, 1 reply; 27+ messages in thread
From: Kacper Michajlow @ 2024-06-01 11:24 UTC (permalink / raw)
To: FFmpeg development discussions and patches
On Wed, 29 May 2024 at 23:47, James Almer <jamrial@gmail.com> wrote:
>
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
> libavformat/matroskadec.c | 53 +++++++++++++++++++++++++++++++--------
> 1 file changed, 43 insertions(+), 10 deletions(-)
>
> diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
> index 2f07e11d87..a30bac786b 100644
> --- a/libavformat/matroskadec.c
> +++ b/libavformat/matroskadec.c
> @@ -213,7 +213,13 @@ typedef struct MatroskaTrackVideo {
> uint64_t display_height;
> uint64_t pixel_width;
> uint64_t pixel_height;
> + uint64_t cropped_width;
> + uint64_t cropped_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;
> @@ -527,10 +533,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_VIDEOPIXELCROPB, EBML_UINT, 0, 0, offsetof(MatroskaTrackVideo, pixel_cropb), {.u = 0 } },
> + { 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_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 } },
> @@ -2963,14 +2969,30 @@ static int mkv_parse_video(MatroskaTrack *track, AVStream *st,
>
> if (track->video.display_unit < MATROSKA_VIDEO_DISPLAYUNIT_UNKNOWN) {
> if (track->video.display_width && track->video.display_height &&
> - par->height < INT64_MAX / track->video.display_width / display_width_mul &&
> - par->width < INT64_MAX / track->video.display_height / display_height_mul)
> + track->video.cropped_height < INT64_MAX / track->video.display_width / display_width_mul &&
> + track->video.cropped_width < INT64_MAX / track->video.display_height / display_height_mul)
> av_reduce(&st->sample_aspect_ratio.num,
> &st->sample_aspect_ratio.den,
> - par->height * track->video.display_width * display_width_mul,
> - par->width * track->video.display_height * display_height_mul,
> + track->video.cropped_height * track->video.display_width * display_width_mul,
> + track->video.cropped_width * track->video.display_height * display_height_mul,
> INT_MAX);
> }
> + if (track->video.cropped_width != track->video.pixel_width ||
> + track->video.cropped_height != track->video.pixel_height) {
> + uint8_t *cropping;
> + AVPacketSideData *sd = av_packet_side_data_new(&st->codecpar->coded_side_data,
> + &st->codecpar->nb_coded_side_data,
> + AV_PKT_DATA_FRAME_CROPPING,
> + sizeof(uint32_t) * 4, 0);
> + if (!sd)
> + return AVERROR(ENOMEM);
> +
> + cropping = sd->data;
> + bytestream_put_le32(&cropping, track->video.pixel_cropt);
> + bytestream_put_le32(&cropping, track->video.pixel_cropb);
> + bytestream_put_le32(&cropping, track->video.pixel_cropl);
> + bytestream_put_le32(&cropping, track->video.pixel_cropr);
> + }
> if (par->codec_id != AV_CODEC_ID_HEVC)
> sti->need_parsing = AVSTREAM_PARSE_HEADERS;
>
> @@ -3136,10 +3158,21 @@ static int matroska_parse_tracks(AVFormatContext *s)
> track->default_duration = default_duration;
> }
> }
> + track->video.cropped_width = track->video.pixel_width;
> + track->video.cropped_height = track->video.pixel_height;
> + if (track->video.display_unit == 0) {
> + if (track->video.pixel_cropl >= INT_MAX - track->video.pixel_cropr ||
> + track->video.pixel_cropt >= INT_MAX - track->video.pixel_cropb ||
> + (track->video.pixel_cropl + track->video.pixel_cropr) >= track->video.pixel_width ||
> + (track->video.pixel_cropt + track->video.pixel_cropb) >= track->video.pixel_height)
> + return AVERROR_INVALIDDATA;
> + track->video.cropped_width -= track->video.pixel_cropl + track->video.pixel_cropr;
> + track->video.cropped_height -= track->video.pixel_cropt + track->video.pixel_cropb;
> + }
> if (track->video.display_width == -1)
> - track->video.display_width = track->video.pixel_width;
> + track->video.display_width = track->video.cropped_width;
> if (track->video.display_height == -1)
> - track->video.display_height = track->video.pixel_height;
> + track->video.display_height = track->video.cropped_height;
> } else if (track->type == MATROSKA_TRACK_TYPE_AUDIO) {
> if (!track->audio.out_samplerate)
> track->audio.out_samplerate = track->audio.samplerate;
> --
> 2.45.1
Have you seen the discussion over the MKVToolNix issue tracker?
https://gitlab.com/mbunkus/mkvtoolnix/-/issues/2389
I think it is the reason it wasn't implemented in ffmpeg sooner. The
issue summarizes the problem and current status quo, quite well I
think. I think the main problem is that vast majority of Matroska
files doesn't are not following the standard with regards to
DisplayWidth/Height.
- Kacper
_______________________________________________
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] 27+ messages in thread
* Re: [FFmpeg-devel] [PATCH 5/6] fftools/ffmpeg: support applying container level cropping
2024-05-29 21:46 ` [FFmpeg-devel] [PATCH 5/6] fftools/ffmpeg: support applying container level cropping James Almer
2024-05-30 1:01 ` Lynne via ffmpeg-devel
2024-05-30 22:57 ` Michael Niedermayer
@ 2024-06-25 10:19 ` Anton Khirnov
2024-07-02 16:49 ` [FFmpeg-devel] [PATCH 5/6 v3] " James Almer
2 siblings, 1 reply; 27+ messages in thread
From: Anton Khirnov @ 2024-06-25 10:19 UTC (permalink / raw)
To: FFmpeg development discussions and patches
Quoting James Almer (2024-05-29 23:46:31)
> @@ -254,6 +256,11 @@ typedef struct InputFilterOptions {
> * accurate */
> AVRational framerate;
>
> + unsigned crop_top;
> + unsigned crop_bottom;
> + unsigned crop_left;
> + unsigned crop_right;
breaks vertical alignment
> +
> int sub2video_width;
> int sub2video_height;
>
> diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
> index 1ca8d804ae..4178b8f840 100644
> --- a/fftools/ffmpeg_demux.c
> +++ b/fftools/ffmpeg_demux.c
> @@ -66,6 +66,7 @@ typedef struct DemuxStream {
> int have_sub2video;
> int reinit_filters;
> int autorotate;
> + int apply_cropping;
>
>
> int wrap_correction_done;
> @@ -1000,11 +1001,20 @@ int ist_filter_add(InputStream *ist, InputFilter *ifilter, int is_simple,
> ist->filters[ist->nb_filters - 1] = ifilter;
>
> if (ist->par->codec_type == AVMEDIA_TYPE_VIDEO) {
> + const AVPacketSideData *sd = av_packet_side_data_get(ist->st->codecpar->coded_side_data,
> + ist->st->codecpar->nb_coded_side_data,
> + AV_PKT_DATA_FRAME_CROPPING);
> if (ist->framerate.num > 0 && ist->framerate.den > 0) {
> opts->framerate = ist->framerate;
> opts->flags |= IFILTER_FLAG_CFR;
> } else
> opts->framerate = av_guess_frame_rate(d->f.ctx, ist->st, NULL);
> + if (sd && sd->size == sizeof(uint32_t) * 4) {
better make it <= to account for future extensions, e.g. we might want
to add sub-pixel resolution in there
> diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
> index 910e4a336b..0c50ce16ba 100644
> --- a/fftools/ffmpeg_opt.c
> +++ b/fftools/ffmpeg_opt.c
> @@ -1732,6 +1732,9 @@ const OptionDef options[] = {
> { "autoscale", OPT_TYPE_BOOL, OPT_PERSTREAM | OPT_EXPERT | OPT_OUTPUT,
> { .off = OFFSET(autoscale) },
> "automatically insert a scale filter at the end of the filter graph" },
> + { "apply_cropping", OPT_TYPE_BOOL, OPT_PERSTREAM | OPT_EXPERT | OPT_INPUT,
> + { .off = OFFSET(apply_cropping) },
> + "apply frame cropping" },
Apply container-level cropping (in addition to codec-level cropping)
Also, missing docs.
--
Anton Khirnov
_______________________________________________
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] 27+ messages in thread
* Re: [FFmpeg-devel] [PATCH 1/2 v2] fftools/ffmpeg: support applying container level cropping
2024-05-30 23:22 ` [FFmpeg-devel] [PATCH 1/2 v2] " James Almer
@ 2024-06-25 10:25 ` Anton Khirnov
2024-06-25 12:38 ` James Almer
0 siblings, 1 reply; 27+ messages in thread
From: Anton Khirnov @ 2024-06-25 10:25 UTC (permalink / raw)
To: FFmpeg development discussions and patches
Quoting James Almer (2024-05-31 01:22:51)
> @@ -1000,11 +1001,21 @@ int ist_filter_add(InputStream *ist, InputFilter *ifilter, int is_simple,
> ist->filters[ist->nb_filters - 1] = ifilter;
>
> if (ist->par->codec_type == AVMEDIA_TYPE_VIDEO) {
> + const AVPacketSideData *sd = av_packet_side_data_get(ist->par->coded_side_data,
> + ist->par->nb_coded_side_data,
> + AV_PKT_DATA_FRAME_CROPPING);
> if (ist->framerate.num > 0 && ist->framerate.den > 0) {
> opts->framerate = ist->framerate;
> opts->flags |= IFILTER_FLAG_CFR;
> } else
> opts->framerate = av_guess_frame_rate(d->f.ctx, ist->st, NULL);
> + if (sd && sd->size == sizeof(uint32_t) * 4) {
> + opts->crop_top = AV_RL32(sd->data + 0);
> + opts->crop_bottom = AV_RL32(sd->data + 4);
> + opts->crop_left = AV_RL32(sd->data + 8);
> + opts->crop_right = AV_RL32(sd->data + 12);
> + opts->flags |= IFILTER_FLAG_CROP;
> + }
> } else if (ist->par->codec_type == AVMEDIA_TYPE_SUBTITLE) {
> /* Compute the size of the canvas for the subtitles stream.
> If the subtitles codecpar has set a size, use it. Otherwise use the
> @@ -1241,6 +1252,9 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st)
> ds->autorotate = 1;
> MATCH_PER_STREAM_OPT(autorotate, i, ds->autorotate, ic, st);
>
> + ds->apply_cropping = 1;
> + MATCH_PER_STREAM_OPT(apply_cropping, i, ds->apply_cropping, ic, st);
> +
> MATCH_PER_STREAM_OPT(codec_tags, str, codec_tag, ic, st);
> if (codec_tag) {
> uint32_t tag = strtol(codec_tag, &next, 0);
> @@ -1362,6 +1376,8 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st)
>
> ds->dec_opts.flags |= DECODER_FLAG_BITEXACT * !!o->bitexact;
>
> + av_dict_set_int(&ds->decoder_opts, "apply_cropping", ds->apply_cropping, 0);
If I'm reading it right, this new option now applies only to decoder
cropping (breaking syntax, because AVOptions always take an argument),
while container cropping is always applied unconditionally.
That seems wrong.
--
Anton Khirnov
_______________________________________________
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] 27+ messages in thread
* Re: [FFmpeg-devel] [PATCH 1/2 v2] fftools/ffmpeg: support applying container level cropping
2024-06-25 10:25 ` Anton Khirnov
@ 2024-06-25 12:38 ` James Almer
2024-06-25 13:12 ` Anton Khirnov
0 siblings, 1 reply; 27+ messages in thread
From: James Almer @ 2024-06-25 12:38 UTC (permalink / raw)
To: ffmpeg-devel
On 6/25/2024 7:25 AM, Anton Khirnov wrote:
> Quoting James Almer (2024-05-31 01:22:51)
>> @@ -1000,11 +1001,21 @@ int ist_filter_add(InputStream *ist, InputFilter *ifilter, int is_simple,
>> ist->filters[ist->nb_filters - 1] = ifilter;
>>
>> if (ist->par->codec_type == AVMEDIA_TYPE_VIDEO) {
>> + const AVPacketSideData *sd = av_packet_side_data_get(ist->par->coded_side_data,
>> + ist->par->nb_coded_side_data,
>> + AV_PKT_DATA_FRAME_CROPPING);
>> if (ist->framerate.num > 0 && ist->framerate.den > 0) {
>> opts->framerate = ist->framerate;
>> opts->flags |= IFILTER_FLAG_CFR;
>> } else
>> opts->framerate = av_guess_frame_rate(d->f.ctx, ist->st, NULL);
>> + if (sd && sd->size == sizeof(uint32_t) * 4) {
>> + opts->crop_top = AV_RL32(sd->data + 0);
>> + opts->crop_bottom = AV_RL32(sd->data + 4);
>> + opts->crop_left = AV_RL32(sd->data + 8);
>> + opts->crop_right = AV_RL32(sd->data + 12);
>> + opts->flags |= IFILTER_FLAG_CROP;
>> + }
>> } else if (ist->par->codec_type == AVMEDIA_TYPE_SUBTITLE) {
>> /* Compute the size of the canvas for the subtitles stream.
>> If the subtitles codecpar has set a size, use it. Otherwise use the
>> @@ -1241,6 +1252,9 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st)
>> ds->autorotate = 1;
>> MATCH_PER_STREAM_OPT(autorotate, i, ds->autorotate, ic, st);
>>
>> + ds->apply_cropping = 1;
>> + MATCH_PER_STREAM_OPT(apply_cropping, i, ds->apply_cropping, ic, st);
>> +
>> MATCH_PER_STREAM_OPT(codec_tags, str, codec_tag, ic, st);
>> if (codec_tag) {
>> uint32_t tag = strtol(codec_tag, &next, 0);
>> @@ -1362,6 +1376,8 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st)
>>
>> ds->dec_opts.flags |= DECODER_FLAG_BITEXACT * !!o->bitexact;
>>
>> + av_dict_set_int(&ds->decoder_opts, "apply_cropping", ds->apply_cropping, 0);
>
> If I'm reading it right, this new option now applies only to decoder
> cropping (breaking syntax, because AVOptions always take an argument),
> while container cropping is always applied unconditionally.
>
> That seems wrong.
Yeah, for some reason i missed a "* !!ds->apply_cropping" next to the
IFILTER_FLAG_CROP above. With it container cropping is applied depending
on the value of apply_cropping.
And how can i work around the ffmpeg option shadowing the avcodec one of
the same name? Using a different name for container cropping option
exclusively in ffmpeg is not really nice for the user. They either care
about cropping no matter the source, or no cropping.
_______________________________________________
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] 27+ messages in thread
* Re: [FFmpeg-devel] [PATCH 1/2 v2] fftools/ffmpeg: support applying container level cropping
2024-06-25 12:38 ` James Almer
@ 2024-06-25 13:12 ` Anton Khirnov
2024-06-25 13:23 ` Paul B Mahol
0 siblings, 1 reply; 27+ messages in thread
From: Anton Khirnov @ 2024-06-25 13:12 UTC (permalink / raw)
To: FFmpeg development discussions and patches
Quoting James Almer (2024-06-25 14:38:58)
> On 6/25/2024 7:25 AM, Anton Khirnov wrote:
> > Quoting James Almer (2024-05-31 01:22:51)
> >> @@ -1000,11 +1001,21 @@ int ist_filter_add(InputStream *ist, InputFilter *ifilter, int is_simple,
> >> ist->filters[ist->nb_filters - 1] = ifilter;
> >>
> >> if (ist->par->codec_type == AVMEDIA_TYPE_VIDEO) {
> >> + const AVPacketSideData *sd = av_packet_side_data_get(ist->par->coded_side_data,
> >> + ist->par->nb_coded_side_data,
> >> + AV_PKT_DATA_FRAME_CROPPING);
> >> if (ist->framerate.num > 0 && ist->framerate.den > 0) {
> >> opts->framerate = ist->framerate;
> >> opts->flags |= IFILTER_FLAG_CFR;
> >> } else
> >> opts->framerate = av_guess_frame_rate(d->f.ctx, ist->st, NULL);
> >> + if (sd && sd->size == sizeof(uint32_t) * 4) {
> >> + opts->crop_top = AV_RL32(sd->data + 0);
> >> + opts->crop_bottom = AV_RL32(sd->data + 4);
> >> + opts->crop_left = AV_RL32(sd->data + 8);
> >> + opts->crop_right = AV_RL32(sd->data + 12);
> >> + opts->flags |= IFILTER_FLAG_CROP;
> >> + }
> >> } else if (ist->par->codec_type == AVMEDIA_TYPE_SUBTITLE) {
> >> /* Compute the size of the canvas for the subtitles stream.
> >> If the subtitles codecpar has set a size, use it. Otherwise use the
> >> @@ -1241,6 +1252,9 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st)
> >> ds->autorotate = 1;
> >> MATCH_PER_STREAM_OPT(autorotate, i, ds->autorotate, ic, st);
> >>
> >> + ds->apply_cropping = 1;
> >> + MATCH_PER_STREAM_OPT(apply_cropping, i, ds->apply_cropping, ic, st);
> >> +
> >> MATCH_PER_STREAM_OPT(codec_tags, str, codec_tag, ic, st);
> >> if (codec_tag) {
> >> uint32_t tag = strtol(codec_tag, &next, 0);
> >> @@ -1362,6 +1376,8 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st)
> >>
> >> ds->dec_opts.flags |= DECODER_FLAG_BITEXACT * !!o->bitexact;
> >>
> >> + av_dict_set_int(&ds->decoder_opts, "apply_cropping", ds->apply_cropping, 0);
> >
> > If I'm reading it right, this new option now applies only to decoder
> > cropping (breaking syntax, because AVOptions always take an argument),
> > while container cropping is always applied unconditionally.
> >
> > That seems wrong.
>
> Yeah, for some reason i missed a "* !!ds->apply_cropping" next to the
> IFILTER_FLAG_CROP above. With it container cropping is applied depending
> on the value of apply_cropping.
>
> And how can i work around the ffmpeg option shadowing the avcodec one of
> the same name? Using a different name for container cropping option
> exclusively in ffmpeg is not really nice for the user. They either care
> about cropping no matter the source, or no cropping.
I expect plenty of broken files from various sources where the user will
want to selectively ignore either codec or container cropping.
So we could make this an enum option, with values
none/all/codec/container, mapping to 0/1/2/3 respectively. That should
keep compatibility with current syntax.
--
Anton Khirnov
_______________________________________________
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] 27+ messages in thread
* Re: [FFmpeg-devel] [PATCH 1/2 v2] fftools/ffmpeg: support applying container level cropping
2024-06-25 13:12 ` Anton Khirnov
@ 2024-06-25 13:23 ` Paul B Mahol
2024-06-25 13:54 ` Anton Khirnov
0 siblings, 1 reply; 27+ messages in thread
From: Paul B Mahol @ 2024-06-25 13:23 UTC (permalink / raw)
To: FFmpeg development discussions and patches
On Tue, Jun 25, 2024 at 3:12 PM Anton Khirnov <anton@khirnov.net> wrote:
> Quoting James Almer (2024-06-25 14:38:58)
> > On 6/25/2024 7:25 AM, Anton Khirnov wrote:
> > > Quoting James Almer (2024-05-31 01:22:51)
> > >> @@ -1000,11 +1001,21 @@ int ist_filter_add(InputStream *ist,
> InputFilter *ifilter, int is_simple,
> > >> ist->filters[ist->nb_filters - 1] = ifilter;
> > >>
> > >> if (ist->par->codec_type == AVMEDIA_TYPE_VIDEO) {
> > >> + const AVPacketSideData *sd =
> av_packet_side_data_get(ist->par->coded_side_data,
> > >> +
> ist->par->nb_coded_side_data,
> > >> +
> AV_PKT_DATA_FRAME_CROPPING);
> > >> if (ist->framerate.num > 0 && ist->framerate.den > 0) {
> > >> opts->framerate = ist->framerate;
> > >> opts->flags |= IFILTER_FLAG_CFR;
> > >> } else
> > >> opts->framerate = av_guess_frame_rate(d->f.ctx,
> ist->st, NULL);
> > >> + if (sd && sd->size == sizeof(uint32_t) * 4) {
> > >> + opts->crop_top = AV_RL32(sd->data + 0);
> > >> + opts->crop_bottom = AV_RL32(sd->data + 4);
> > >> + opts->crop_left = AV_RL32(sd->data + 8);
> > >> + opts->crop_right = AV_RL32(sd->data + 12);
> > >> + opts->flags |= IFILTER_FLAG_CROP;
> > >> + }
> > >> } else if (ist->par->codec_type == AVMEDIA_TYPE_SUBTITLE) {
> > >> /* Compute the size of the canvas for the subtitles stream.
> > >> If the subtitles codecpar has set a size, use it.
> Otherwise use the
> > >> @@ -1241,6 +1252,9 @@ static int ist_add(const OptionsContext *o,
> Demuxer *d, AVStream *st)
> > >> ds->autorotate = 1;
> > >> MATCH_PER_STREAM_OPT(autorotate, i, ds->autorotate, ic, st);
> > >>
> > >> + ds->apply_cropping = 1;
> > >> + MATCH_PER_STREAM_OPT(apply_cropping, i, ds->apply_cropping, ic,
> st);
> > >> +
> > >> MATCH_PER_STREAM_OPT(codec_tags, str, codec_tag, ic, st);
> > >> if (codec_tag) {
> > >> uint32_t tag = strtol(codec_tag, &next, 0);
> > >> @@ -1362,6 +1376,8 @@ static int ist_add(const OptionsContext *o,
> Demuxer *d, AVStream *st)
> > >>
> > >> ds->dec_opts.flags |= DECODER_FLAG_BITEXACT * !!o->bitexact;
> > >>
> > >> + av_dict_set_int(&ds->decoder_opts, "apply_cropping",
> ds->apply_cropping, 0);
> > >
> > > If I'm reading it right, this new option now applies only to decoder
> > > cropping (breaking syntax, because AVOptions always take an argument),
> > > while container cropping is always applied unconditionally.
> > >
> > > That seems wrong.
> >
> > Yeah, for some reason i missed a "* !!ds->apply_cropping" next to the
> > IFILTER_FLAG_CROP above. With it container cropping is applied depending
> > on the value of apply_cropping.
> >
> > And how can i work around the ffmpeg option shadowing the avcodec one of
> > the same name? Using a different name for container cropping option
> > exclusively in ffmpeg is not really nice for the user. They either care
> > about cropping no matter the source, or no cropping.
>
> I expect plenty of broken files from various sources where the user will
> want to selectively ignore either codec or container cropping.
> So we could make this an enum option, with values
> none/all/codec/container, mapping to 0/1/2/3 respectively. That should
> keep compatibility with current syntax.
>
Enum? Why not flags?
>
> --
> Anton Khirnov
> _______________________________________________
> 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".
>
_______________________________________________
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] 27+ messages in thread
* Re: [FFmpeg-devel] [PATCH 1/2 v2] fftools/ffmpeg: support applying container level cropping
2024-06-25 13:23 ` Paul B Mahol
@ 2024-06-25 13:54 ` Anton Khirnov
0 siblings, 0 replies; 27+ messages in thread
From: Anton Khirnov @ 2024-06-25 13:54 UTC (permalink / raw)
To: FFmpeg development discussions and patches
Quoting Paul B Mahol (2024-06-25 15:23:53)
> On Tue, Jun 25, 2024 at 3:12 PM Anton Khirnov <anton@khirnov.net> wrote:
> > I expect plenty of broken files from various sources where the user will
> > want to selectively ignore either codec or container cropping.
> > So we could make this an enum option, with values
> > none/all/codec/container, mapping to 0/1/2/3 respectively. That should
> > keep compatibility with current syntax.
> >
>
> Enum? Why not flags?
For compatibility reasons we want 1 to be 'all'.
The other option is to special-case numeric values.
--
Anton Khirnov
_______________________________________________
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] 27+ messages in thread
* Re: [FFmpeg-devel] [PATCH 1/6] avcodec/packet: add a decoded frame cropping side data type
2024-05-29 21:46 [FFmpeg-devel] [PATCH 1/6] avcodec/packet: add a decoded frame cropping side data type James Almer
` (5 preceding siblings ...)
2024-05-30 1:02 ` [FFmpeg-devel] [PATCH 1/6] avcodec/packet: add a decoded frame cropping side data type Lynne via ffmpeg-devel
@ 2024-06-25 18:13 ` Andreas Rheinhardt
2024-06-25 18:17 ` James Almer
6 siblings, 1 reply; 27+ messages in thread
From: Andreas Rheinhardt @ 2024-06-25 18:13 UTC (permalink / raw)
To: ffmpeg-devel
James Almer:
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
> libavcodec/packet.h | 14 ++++++++++++++
> 1 file changed, 14 insertions(+)
>
> diff --git a/libavcodec/packet.h b/libavcodec/packet.h
> index a9a41576da..9dee035690 100644
> --- a/libavcodec/packet.h
> +++ b/libavcodec/packet.h
> @@ -330,6 +330,20 @@ enum AVPacketSideDataType {
> */
> AV_PKT_DATA_AMBIENT_VIEWING_ENVIRONMENT,
>
> + /**
> + * The number of pixels to discard from the
> + * top/bottom/left/right border of the decoded frame to obtain the sub-rectangle
> + * intended for presentation.
> + *
> + * @code
> + * u32le crop_top
> + * u32le crop_bottom
> + * u32le crop_left
> + * u32le crop_right
> + * @endcode
> + */
> + AV_PKT_DATA_FRAME_CROPPING,
> +
> /**
> * The number of side data types.
> * This is not part of the public API/ABI in the sense that it may
As I already said about an earlier iteration of this: The cropping is a
rational in ISOBMFF, so it should be here, too.
- Andreas
_______________________________________________
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] 27+ messages in thread
* Re: [FFmpeg-devel] [PATCH 1/6] avcodec/packet: add a decoded frame cropping side data type
2024-06-25 18:13 ` Andreas Rheinhardt
@ 2024-06-25 18:17 ` James Almer
0 siblings, 0 replies; 27+ messages in thread
From: James Almer @ 2024-06-25 18:17 UTC (permalink / raw)
To: ffmpeg-devel
On 6/25/2024 3:13 PM, Andreas Rheinhardt wrote:
> James Almer:
>> Signed-off-by: James Almer <jamrial@gmail.com>
>> ---
>> libavcodec/packet.h | 14 ++++++++++++++
>> 1 file changed, 14 insertions(+)
>>
>> diff --git a/libavcodec/packet.h b/libavcodec/packet.h
>> index a9a41576da..9dee035690 100644
>> --- a/libavcodec/packet.h
>> +++ b/libavcodec/packet.h
>> @@ -330,6 +330,20 @@ enum AVPacketSideDataType {
>> */
>> AV_PKT_DATA_AMBIENT_VIEWING_ENVIRONMENT,
>>
>> + /**
>> + * The number of pixels to discard from the
>> + * top/bottom/left/right border of the decoded frame to obtain the sub-rectangle
>> + * intended for presentation.
>> + *
>> + * @code
>> + * u32le crop_top
>> + * u32le crop_bottom
>> + * u32le crop_left
>> + * u32le crop_right
>> + * @endcode
>> + */
>> + AV_PKT_DATA_FRAME_CROPPING,
>> +
>> /**
>> * The number of side data types.
>> * This is not part of the public API/ABI in the sense that it may
>
> As I already said about an earlier iteration of this: The cropping is a
> rational in ISOBMFF, so it should be here, too.
No, i don't want it being a rational. It even makes no sense being one
in ISOBMFF to begin with. I don't consider it worth making things any
more complex.
_______________________________________________
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] 27+ messages in thread
* [FFmpeg-devel] [PATCH 5/6 v3] fftools/ffmpeg: support applying container level cropping
2024-06-25 10:19 ` [FFmpeg-devel] [PATCH 5/6] " Anton Khirnov
@ 2024-07-02 16:49 ` James Almer
2024-07-02 17:55 ` Anton Khirnov
0 siblings, 1 reply; 27+ messages in thread
From: James Almer @ 2024-07-02 16:49 UTC (permalink / raw)
To: ffmpeg-devel
Signed-off-by: James Almer <jamrial@gmail.com>
---
doc/ffmpeg.texi | 16 ++++++++++++++++
fftools/ffmpeg.h | 15 +++++++++++++++
fftools/ffmpeg_demux.c | 26 ++++++++++++++++++++++++++
fftools/ffmpeg_filter.c | 10 ++++++++++
fftools/ffmpeg_opt.c | 25 +++++++++++++++++++++++++
5 files changed, 92 insertions(+)
diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
index f25f6192eb..f75ed681cf 100644
--- a/doc/ffmpeg.texi
+++ b/doc/ffmpeg.texi
@@ -1262,6 +1262,22 @@ disabled, all output frames of filter graph might not be in the same resolution
and may be inadequate for some encoder/muxer. Therefore, it is not recommended
to disable it unless you really know what you are doing.
Disable autoscale at your own risk.
+
+@item -apply_cropping
+Automatically crop the video according to file metadata. Default is @emph{all}.
+
+@table @option
+@item none (0)
+Don't apply any cropping metadata.
+@item all (1)
+Apply both codec and container level croppping. This is the default mode.
+@item codec (2)
+Apply codec level croppping.
+@item container (3)
+Apply container level croppping.
+
+@end table
+
@end table
@section Advanced Video options
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index fe75706afd..810a5fa66c 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -155,6 +155,7 @@ typedef struct OptionsContext {
SpecifierOptList hwaccel_devices;
SpecifierOptList hwaccel_output_formats;
SpecifierOptList autorotate;
+ SpecifierOptList apply_cropping;
/* output options */
StreamMap *stream_maps;
@@ -239,6 +240,7 @@ enum IFilterFlags {
IFILTER_FLAG_AUTOROTATE = (1 << 0),
IFILTER_FLAG_REINIT = (1 << 1),
IFILTER_FLAG_CFR = (1 << 2),
+ IFILTER_FLAG_CROP = (1 << 3),
};
typedef struct InputFilterOptions {
@@ -254,6 +256,11 @@ typedef struct InputFilterOptions {
* accurate */
AVRational framerate;
+ unsigned crop_top;
+ unsigned crop_bottom;
+ unsigned crop_left;
+ unsigned crop_right;
+
int sub2video_width;
int sub2video_height;
@@ -539,6 +546,13 @@ typedef struct KeyframeForceCtx {
typedef struct Encoder Encoder;
+enum CroppingType {
+ CROP_DISABLED = 0,
+ CROP_ALL,
+ CROP_CODEC,
+ CROP_CONTAINER,
+};
+
typedef struct OutputStream {
const AVClass *class;
@@ -715,6 +729,7 @@ AVDictionary *strip_specifiers(const AVDictionary *dict);
int find_codec(void *logctx, const char *name,
enum AVMediaType type, int encoder, const AVCodec **codec);
int parse_and_set_vsync(const char *arg, int *vsync_var, int file_idx, int st_idx, int is_global);
+int parse_and_set_cropping(const char *arg, int *out);
int filtergraph_is_simple(const FilterGraph *fg);
int init_simple_filtergraph(InputStream *ist, OutputStream *ost,
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index 1ca8d804ae..409d41eba7 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -66,6 +66,7 @@ typedef struct DemuxStream {
int have_sub2video;
int reinit_filters;
int autorotate;
+ int apply_cropping;
int wrap_correction_done;
@@ -1000,11 +1001,22 @@ int ist_filter_add(InputStream *ist, InputFilter *ifilter, int is_simple,
ist->filters[ist->nb_filters - 1] = ifilter;
if (ist->par->codec_type == AVMEDIA_TYPE_VIDEO) {
+ const AVPacketSideData *sd = av_packet_side_data_get(ist->par->coded_side_data,
+ ist->par->nb_coded_side_data,
+ AV_PKT_DATA_FRAME_CROPPING);
if (ist->framerate.num > 0 && ist->framerate.den > 0) {
opts->framerate = ist->framerate;
opts->flags |= IFILTER_FLAG_CFR;
} else
opts->framerate = av_guess_frame_rate(d->f.ctx, ist->st, NULL);
+ if (sd && sd->size >= sizeof(uint32_t) * 4) {
+ opts->crop_top = AV_RL32(sd->data + 0);
+ opts->crop_bottom = AV_RL32(sd->data + 4);
+ opts->crop_left = AV_RL32(sd->data + 8);
+ opts->crop_right = AV_RL32(sd->data + 12);
+ if (ds->apply_cropping && ds->apply_cropping != CROP_CODEC)
+ opts->flags |= IFILTER_FLAG_CROP;
+ }
} else if (ist->par->codec_type == AVMEDIA_TYPE_SUBTITLE) {
/* Compute the size of the canvas for the subtitles stream.
If the subtitles codecpar has set a size, use it. Otherwise use the
@@ -1215,6 +1227,7 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st)
InputStream *ist;
char *framerate = NULL, *hwaccel_device = NULL;
const char *hwaccel = NULL;
+ const char *apply_cropping = NULL;
char *hwaccel_output_format = NULL;
char *codec_tag = NULL;
char *bsfs = NULL;
@@ -1241,6 +1254,16 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st)
ds->autorotate = 1;
MATCH_PER_STREAM_OPT(autorotate, i, ds->autorotate, ic, st);
+ ds->apply_cropping = CROP_ALL;
+ MATCH_PER_STREAM_OPT(apply_cropping, str, apply_cropping, ic, st);
+ if (apply_cropping) {
+ ret = parse_and_set_cropping(apply_cropping, &ds->apply_cropping);
+ if (ret < 0) {
+ av_log(ist, AV_LOG_ERROR, "Invalid apply_cropping value '%s'.\n", apply_cropping);
+ return ret;
+ }
+ }
+
MATCH_PER_STREAM_OPT(codec_tags, str, codec_tag, ic, st);
if (codec_tag) {
uint32_t tag = strtol(codec_tag, &next, 0);
@@ -1362,6 +1385,9 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st)
ds->dec_opts.flags |= DECODER_FLAG_BITEXACT * !!o->bitexact;
+ av_dict_set_int(&ds->decoder_opts, "apply_cropping",
+ ds->apply_cropping && ds->apply_cropping != CROP_CONTAINER, 0);
+
/* Attached pics are sparse, therefore we would not want to delay their decoding
* till EOF. */
if (ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC)
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 12cca684b4..f3087afc88 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -1701,6 +1701,16 @@ static int configure_input_video_filter(FilterGraph *fg, AVFilterGraph *graph,
desc = av_pix_fmt_desc_get(ifp->format);
av_assert0(desc);
+ if ((ifp->opts.flags & IFILTER_FLAG_CROP)) {
+ char crop_buf[64];
+ snprintf(crop_buf, sizeof(crop_buf), "w=iw-%d-%d:h=ih-%d-%d",
+ ifp->opts.crop_left, ifp->opts.crop_right,
+ ifp->opts.crop_top, ifp->opts.crop_bottom);
+ ret = insert_filter(&last_filter, &pad_idx, "crop", crop_buf);
+ if (ret < 0)
+ return ret;
+ }
+
// TODO: insert hwaccel enabled filters like transpose_vaapi into the graph
ifp->displaymatrix_applied = 0;
if ((ifp->opts.flags & IFILTER_FLAG_AUTOROTATE) &&
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index 910e4a336b..fb104a356d 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -217,6 +217,28 @@ int parse_and_set_vsync(const char *arg, int *vsync_var, int file_idx, int st_id
return 0;
}
+int parse_and_set_cropping(const char *arg, int *out)
+{
+ const AVOption opts[] = {
+ { "apply_cropping", NULL, 0, AV_OPT_TYPE_INT,
+ { .i64 = CROP_ALL }, CROP_DISABLED, CROP_CONTAINER, AV_OPT_FLAG_DECODING_PARAM, .unit = "apply_cropping" },
+ { "none", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CROP_DISABLED }, .unit = "apply_cropping" },
+ { "all", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CROP_ALL }, .unit = "apply_cropping" },
+ { "codec", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CROP_CODEC }, .unit = "apply_cropping" },
+ { "container", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CROP_CONTAINER }, .unit = "apply_cropping" },
+ { NULL },
+ };
+ const AVClass class = {
+ .class_name = "apply_cropping",
+ .item_name = av_default_item_name,
+ .option = opts,
+ .version = LIBAVUTIL_VERSION_INT,
+ };
+ const AVClass *pclass = &class;
+
+ return av_opt_eval_int(&pclass, opts, arg, out);
+}
+
/* Correct input file start times based on enabled streams */
static void correct_input_start_times(void)
{
@@ -1732,6 +1754,9 @@ const OptionDef options[] = {
{ "autoscale", OPT_TYPE_BOOL, OPT_PERSTREAM | OPT_EXPERT | OPT_OUTPUT,
{ .off = OFFSET(autoscale) },
"automatically insert a scale filter at the end of the filter graph" },
+ { "apply_cropping", OPT_TYPE_STRING, OPT_VIDEO | OPT_PERSTREAM | OPT_EXPERT | OPT_INPUT,
+ { .off = OFFSET(apply_cropping) },
+ "select the cropping to apply" },
{ "fix_sub_duration_heartbeat", OPT_TYPE_BOOL, OPT_VIDEO | OPT_EXPERT | OPT_PERSTREAM | OPT_OUTPUT,
{ .off = OFFSET(fix_sub_duration_heartbeat) },
"set this video output stream to be a heartbeat stream for "
--
2.45.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] 27+ messages in thread
* Re: [FFmpeg-devel] [PATCH 5/6 v3] fftools/ffmpeg: support applying container level cropping
2024-07-02 16:49 ` [FFmpeg-devel] [PATCH 5/6 v3] " James Almer
@ 2024-07-02 17:55 ` Anton Khirnov
2024-07-02 18:43 ` James Almer
0 siblings, 1 reply; 27+ messages in thread
From: Anton Khirnov @ 2024-07-02 17:55 UTC (permalink / raw)
To: FFmpeg development discussions and patches
Quoting James Almer (2024-07-02 18:49:36)
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
> doc/ffmpeg.texi | 16 ++++++++++++++++
> fftools/ffmpeg.h | 15 +++++++++++++++
> fftools/ffmpeg_demux.c | 26 ++++++++++++++++++++++++++
> fftools/ffmpeg_filter.c | 10 ++++++++++
> fftools/ffmpeg_opt.c | 25 +++++++++++++++++++++++++
> 5 files changed, 92 insertions(+)
>
> diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
> index f25f6192eb..f75ed681cf 100644
> --- a/doc/ffmpeg.texi
> +++ b/doc/ffmpeg.texi
> @@ -1262,6 +1262,22 @@ disabled, all output frames of filter graph might not be in the same resolution
> and may be inadequate for some encoder/muxer. Therefore, it is not recommended
> to disable it unless you really know what you are doing.
> Disable autoscale at your own risk.
> +
> +@item -apply_cropping
+@item -apply_cropping[:@var{stream_specifier}] @var{source} (@emph{input,per-stream})
> +Automatically crop the video according to file metadata. Default is @emph{all}.
^
after decoding
> +
> +@table @option
> +@item none (0)
> +Don't apply any cropping metadata.
> +@item all (1)
> +Apply both codec and container level croppping. This is the default mode.
> +@item codec (2)
> +Apply codec level croppping.
> +@item container (3)
> +Apply container level croppping.
> +
> +@end table
> +
Also, this should probably be in the advanced section, since it's marked
as OPT_EXPERT.
> @@ -715,6 +729,7 @@ AVDictionary *strip_specifiers(const AVDictionary *dict);
> int find_codec(void *logctx, const char *name,
> enum AVMediaType type, int encoder, const AVCodec **codec);
> int parse_and_set_vsync(const char *arg, int *vsync_var, int file_idx, int st_idx, int is_global);
> +int parse_and_set_cropping(const char *arg, int *out);
What's the point of this being in a separate file when it's only used
from ffmpeg_demux?
--
Anton Khirnov
_______________________________________________
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] 27+ messages in thread
* Re: [FFmpeg-devel] [PATCH 5/6 v3] fftools/ffmpeg: support applying container level cropping
2024-07-02 17:55 ` Anton Khirnov
@ 2024-07-02 18:43 ` James Almer
2024-07-02 19:00 ` Anton Khirnov
0 siblings, 1 reply; 27+ messages in thread
From: James Almer @ 2024-07-02 18:43 UTC (permalink / raw)
To: ffmpeg-devel
On 7/2/2024 2:55 PM, Anton Khirnov wrote:
> Quoting James Almer (2024-07-02 18:49:36)
>> Signed-off-by: James Almer <jamrial@gmail.com>
>> ---
>> doc/ffmpeg.texi | 16 ++++++++++++++++
>> fftools/ffmpeg.h | 15 +++++++++++++++
>> fftools/ffmpeg_demux.c | 26 ++++++++++++++++++++++++++
>> fftools/ffmpeg_filter.c | 10 ++++++++++
>> fftools/ffmpeg_opt.c | 25 +++++++++++++++++++++++++
>> 5 files changed, 92 insertions(+)
>>
>> diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
>> index f25f6192eb..f75ed681cf 100644
>> --- a/doc/ffmpeg.texi
>> +++ b/doc/ffmpeg.texi
>> @@ -1262,6 +1262,22 @@ disabled, all output frames of filter graph might not be in the same resolution
>> and may be inadequate for some encoder/muxer. Therefore, it is not recommended
>> to disable it unless you really know what you are doing.
>> Disable autoscale at your own risk.
>> +
>> +@item -apply_cropping
>
> +@item -apply_cropping[:@var{stream_specifier}] @var{source} (@emph{input,per-stream})
Ok.
>
>
>> +Automatically crop the video according to file metadata. Default is @emph{all}.
> ^
> after decoding
Ok.
>> +
>> +@table @option
>> +@item none (0)
>> +Don't apply any cropping metadata.
>> +@item all (1)
>> +Apply both codec and container level croppping. This is the default mode.
>> +@item codec (2)
>> +Apply codec level croppping.
>> +@item container (3)
>> +Apply container level croppping.
>> +
>> +@end table
>> +
>
> Also, this should probably be in the advanced section, since it's marked
> as OPT_EXPERT.
So are autoscale and autorotate, which are also outside the advanced
section. But i can move it if you prefer.
>
>> @@ -715,6 +729,7 @@ AVDictionary *strip_specifiers(const AVDictionary *dict);
>> int find_codec(void *logctx, const char *name,
>> enum AVMediaType type, int encoder, const AVCodec **codec);
>> int parse_and_set_vsync(const char *arg, int *vsync_var, int file_idx, int st_idx, int is_global);
>> +int parse_and_set_cropping(const char *arg, int *out);
>
> What's the point of this being in a separate file when it's only used
> from ffmpeg_demux?
Copy-paste implementation from parse_and_set_vsync(). Will move.
_______________________________________________
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] 27+ messages in thread
* Re: [FFmpeg-devel] [PATCH 5/6 v3] fftools/ffmpeg: support applying container level cropping
2024-07-02 18:43 ` James Almer
@ 2024-07-02 19:00 ` Anton Khirnov
0 siblings, 0 replies; 27+ messages in thread
From: Anton Khirnov @ 2024-07-02 19:00 UTC (permalink / raw)
To: FFmpeg development discussions and patches
Quoting James Almer (2024-07-02 20:43:59)
> On 7/2/2024 2:55 PM, Anton Khirnov wrote:
> >> +
> >> +@table @option
> >> +@item none (0)
> >> +Don't apply any cropping metadata.
> >> +@item all (1)
> >> +Apply both codec and container level croppping. This is the default mode.
> >> +@item codec (2)
> >> +Apply codec level croppping.
> >> +@item container (3)
> >> +Apply container level croppping.
> >> +
> >> +@end table
> >> +
> >
> > Also, this should probably be in the advanced section, since it's marked
> > as OPT_EXPERT.
>
> So are autoscale and autorotate, which are also outside the advanced
> section. But i can move it if you prefer.
Please do.
Patch ok otherwise.
--
Anton Khirnov
_______________________________________________
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] 27+ messages in thread
* Re: [FFmpeg-devel] [PATCH 3/6] avformat/matroskadec: export cropping values
2024-06-01 11:24 ` Kacper Michajlow
@ 2024-07-05 20:51 ` James Almer
0 siblings, 0 replies; 27+ messages in thread
From: James Almer @ 2024-07-05 20:51 UTC (permalink / raw)
To: ffmpeg-devel
On 6/1/2024 8:24 AM, Kacper Michajlow wrote:
> On Wed, 29 May 2024 at 23:47, James Almer <jamrial@gmail.com> wrote:
>>
>> Signed-off-by: James Almer <jamrial@gmail.com>
>> ---
>> libavformat/matroskadec.c | 53 +++++++++++++++++++++++++++++++--------
>> 1 file changed, 43 insertions(+), 10 deletions(-)
>>
>> diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
>> index 2f07e11d87..a30bac786b 100644
>> --- a/libavformat/matroskadec.c
>> +++ b/libavformat/matroskadec.c
>> @@ -213,7 +213,13 @@ typedef struct MatroskaTrackVideo {
>> uint64_t display_height;
>> uint64_t pixel_width;
>> uint64_t pixel_height;
>> + uint64_t cropped_width;
>> + uint64_t cropped_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;
>> @@ -527,10 +533,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_VIDEOPIXELCROPB, EBML_UINT, 0, 0, offsetof(MatroskaTrackVideo, pixel_cropb), {.u = 0 } },
>> + { 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_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 } },
>> @@ -2963,14 +2969,30 @@ static int mkv_parse_video(MatroskaTrack *track, AVStream *st,
>>
>> if (track->video.display_unit < MATROSKA_VIDEO_DISPLAYUNIT_UNKNOWN) {
>> if (track->video.display_width && track->video.display_height &&
>> - par->height < INT64_MAX / track->video.display_width / display_width_mul &&
>> - par->width < INT64_MAX / track->video.display_height / display_height_mul)
>> + track->video.cropped_height < INT64_MAX / track->video.display_width / display_width_mul &&
>> + track->video.cropped_width < INT64_MAX / track->video.display_height / display_height_mul)
>> av_reduce(&st->sample_aspect_ratio.num,
>> &st->sample_aspect_ratio.den,
>> - par->height * track->video.display_width * display_width_mul,
>> - par->width * track->video.display_height * display_height_mul,
>> + track->video.cropped_height * track->video.display_width * display_width_mul,
>> + track->video.cropped_width * track->video.display_height * display_height_mul,
>> INT_MAX);
>> }
>> + if (track->video.cropped_width != track->video.pixel_width ||
>> + track->video.cropped_height != track->video.pixel_height) {
>> + uint8_t *cropping;
>> + AVPacketSideData *sd = av_packet_side_data_new(&st->codecpar->coded_side_data,
>> + &st->codecpar->nb_coded_side_data,
>> + AV_PKT_DATA_FRAME_CROPPING,
>> + sizeof(uint32_t) * 4, 0);
>> + if (!sd)
>> + return AVERROR(ENOMEM);
>> +
>> + cropping = sd->data;
>> + bytestream_put_le32(&cropping, track->video.pixel_cropt);
>> + bytestream_put_le32(&cropping, track->video.pixel_cropb);
>> + bytestream_put_le32(&cropping, track->video.pixel_cropl);
>> + bytestream_put_le32(&cropping, track->video.pixel_cropr);
>> + }
>> if (par->codec_id != AV_CODEC_ID_HEVC)
>> sti->need_parsing = AVSTREAM_PARSE_HEADERS;
>>
>> @@ -3136,10 +3158,21 @@ static int matroska_parse_tracks(AVFormatContext *s)
>> track->default_duration = default_duration;
>> }
>> }
>> + track->video.cropped_width = track->video.pixel_width;
>> + track->video.cropped_height = track->video.pixel_height;
>> + if (track->video.display_unit == 0) {
>> + if (track->video.pixel_cropl >= INT_MAX - track->video.pixel_cropr ||
>> + track->video.pixel_cropt >= INT_MAX - track->video.pixel_cropb ||
>> + (track->video.pixel_cropl + track->video.pixel_cropr) >= track->video.pixel_width ||
>> + (track->video.pixel_cropt + track->video.pixel_cropb) >= track->video.pixel_height)
>> + return AVERROR_INVALIDDATA;
>> + track->video.cropped_width -= track->video.pixel_cropl + track->video.pixel_cropr;
>> + track->video.cropped_height -= track->video.pixel_cropt + track->video.pixel_cropb;
>> + }
>> if (track->video.display_width == -1)
>> - track->video.display_width = track->video.pixel_width;
>> + track->video.display_width = track->video.cropped_width;
>> if (track->video.display_height == -1)
>> - track->video.display_height = track->video.pixel_height;
>> + track->video.display_height = track->video.cropped_height;
>> } else if (track->type == MATROSKA_TRACK_TYPE_AUDIO) {
>> if (!track->audio.out_samplerate)
>> track->audio.out_samplerate = track->audio.samplerate;
>> --
>> 2.45.1
>
> Have you seen the discussion over the MKVToolNix issue tracker?
> https://gitlab.com/mbunkus/mkvtoolnix/-/issues/2389
>
> I think it is the reason it wasn't implemented in ffmpeg sooner. The
> issue summarizes the problem and current status quo, quite well I
> think. I think the main problem is that vast majority of Matroska
> files doesn't are not following the standard with regards to
> DisplayWidth/Height.
The only thing i can think to do about this is adding an option to
ignore display dimension fields and have the demuxer derive them as if
they were not coded in. There's no amount of heuristics one could do to
figure out if the values in display dimension fields are correct and
intended (taking into account any cropping value that may be present,
and/or trying to achieve a certain DAR), or if they are bogus.
_______________________________________________
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] 27+ messages in thread
end of thread, other threads:[~2024-07-05 20:50 UTC | newest]
Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-29 21:46 [FFmpeg-devel] [PATCH 1/6] avcodec/packet: add a decoded frame cropping side data type James Almer
2024-05-29 21:46 ` [FFmpeg-devel] [PATCH 2/6] avformat/dump: print Frame Cropping side data info James Almer
2024-05-29 21:46 ` [FFmpeg-devel] [PATCH 3/6] avformat/matroskadec: export cropping values James Almer
2024-06-01 11:24 ` Kacper Michajlow
2024-07-05 20:51 ` James Almer
2024-05-29 21:46 ` [FFmpeg-devel] [PATCH 4/6] avformat/matroskaenc: support writing " James Almer
2024-05-29 21:46 ` [FFmpeg-devel] [PATCH 5/6] fftools/ffmpeg: support applying container level cropping James Almer
2024-05-30 1:01 ` Lynne via ffmpeg-devel
2024-05-30 1:04 ` James Almer
2024-05-31 1:13 ` Lynne via ffmpeg-devel
2024-05-30 22:57 ` Michael Niedermayer
2024-05-30 23:22 ` [FFmpeg-devel] [PATCH 1/2 v2] " James Almer
2024-06-25 10:25 ` Anton Khirnov
2024-06-25 12:38 ` James Almer
2024-06-25 13:12 ` Anton Khirnov
2024-06-25 13:23 ` Paul B Mahol
2024-06-25 13:54 ` Anton Khirnov
2024-06-25 10:19 ` [FFmpeg-devel] [PATCH 5/6] " Anton Khirnov
2024-07-02 16:49 ` [FFmpeg-devel] [PATCH 5/6 v3] " James Almer
2024-07-02 17:55 ` Anton Khirnov
2024-07-02 18:43 ` James Almer
2024-07-02 19:00 ` Anton Khirnov
2024-05-29 21:46 ` [FFmpeg-devel] [PATCH 6/6] fftools/ffplay: " James Almer
2024-05-30 1:02 ` [FFmpeg-devel] [PATCH 1/6] avcodec/packet: add a decoded frame cropping side data type Lynne via ffmpeg-devel
2024-05-30 1:08 ` James Almer
2024-06-25 18:13 ` Andreas Rheinhardt
2024-06-25 18:17 ` James Almer
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