[FFmpeg-devel] [PATCH v7 0/2] ffmpeg: Add display_{rotation, hflip, vflip} options

2022-10-15 Thread Thilo Borgmann
Hi,

this is an almost identical rebased version of Jan's patchset discussed in [1], 
now v7...

Should fix #8329 and #6370.

Thanks,
Thilo

[1] https://lists.ffmpeg.org/pipermail/ffmpeg-devel/2022-May/296553.html

Jan Ekström (2):
  ffmpeg: Add display_{rotation, hflip, vflip} options
  ffmpeg: Deprecate display rotation override with a metadata key

 doc/ffmpeg.texi | 26 
 fftools/ffmpeg.c|  2 ++
 fftools/ffmpeg.h| 11 +++
 fftools/ffmpeg_opt.c| 60 +
 tests/fate/filter-video.mak |  2 +-
 5 files changed, 100 insertions(+), 1 deletion(-)

-- 
2.20.1 (Apple Git-117)

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v7 1/2] ffmpeg: Add display_{rotation, hflip, vflip} options

2022-10-15 Thread Thilo Borgmann
From: Jan Ekström 

This enables overriding the rotation as well as horizontal/vertical
flip state of a specific video stream on the input side.

Additionally, switch the singular test that was utilizing the rotation
metadata to instead override the input display rotation, thus leading
to the same result.
---
 doc/ffmpeg.texi | 26 +++
 fftools/ffmpeg.h|  6 +
 fftools/ffmpeg_opt.c| 50 +
 tests/fate/filter-video.mak |  2 +-
 4 files changed, 83 insertions(+), 1 deletion(-)

diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
index e9020b30d5..0367930a3b 100644
--- a/doc/ffmpeg.texi
+++ b/doc/ffmpeg.texi
@@ -912,6 +912,32 @@ If used together with @option{-vcodec copy}, it will 
affect the aspect ratio
 stored at container level, but not the aspect ratio stored in encoded
 frames, if it exists.
 
+@item -display_rotation[:@var{stream_specifier}] @var{rotation} 
(@emph{input,per-stream})
+Set video rotation metadata.
+
+@var{rotation} is a decimal number specifying the amount in degree by
+which the video should be rotated counter-clockwise before being
+displayed.
+
+This option overrides the rotation/display transform metadata stored in
+the file, if any. When the video is being transcoded (rather than
+copied) and @code{-autorotate} is enabled, the video will be rotated at
+the filtering stage. Otherwise, the metadata will be written into the
+output file if the muxer supports it.
+
+If the @code{-display_hflip} and/or @code{-display_vflip} options are
+given, they are applied after the rotation specified by this option.
+
+@item -display_hflip[:@var{stream_specifier}] (@emph{input,per-stream})
+Set whether on display the image should be horizontally flipped.
+
+See the @code{-display_rotation} option for more details.
+
+@item -display_vflip[:@var{stream_specifier}] (@emph{input,per-stream})
+Set whether on display the image should be vertically flipped.
+
+See the @code{-display_rotation} option for more details.
+
 @item -vn (@emph{input/output})
 As an input option, blocks all video streams of a file from being filtered or
 being automatically selected or mapped for any output. See @code{-discard}
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 9c908e7465..684c51e524 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -194,6 +194,12 @@ typedef struct OptionsContext {
 intnb_force_fps;
 SpecifierOpt *frame_aspect_ratios;
 intnb_frame_aspect_ratios;
+SpecifierOpt *display_rotations;
+intnb_display_rotations;
+SpecifierOpt *display_hflips;
+intnb_display_hflips;
+SpecifierOpt *display_vflips;
+intnb_display_vflips;
 SpecifierOpt *rc_overrides;
 intnb_rc_overrides;
 SpecifierOpt *intra_matrices;
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index fbc8638eed..f83900eb60 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -20,6 +20,7 @@
 
 #include "config.h"
 
+#include 
 #include 
 
 #if HAVE_SYS_RESOURCE_H
@@ -45,6 +46,7 @@
 #include "libavutil/avutil.h"
 #include "libavutil/bprint.h"
 #include "libavutil/channel_layout.h"
+#include "libavutil/display.h"
 #include "libavutil/getenv_utf8.h"
 #include "libavutil/intreadwrite.h"
 #include "libavutil/fifo.h"
@@ -86,6 +88,9 @@ static const char *const opt_name_forced_key_frames[] 
= {"forced_key_fra
 static const char *const opt_name_fps_mode[]  = {"fps_mode", 
NULL};
 static const char *const opt_name_force_fps[] = {"force_fps", 
NULL};
 static const char *const opt_name_frame_aspect_ratios[]   = {"aspect", 
NULL};
+static const char *const opt_name_display_rotations[] = 
{"display_rotation", NULL};
+static const char *const opt_name_display_hflips[]= 
{"display_hflip", NULL};
+static const char *const opt_name_display_vflips[]= 
{"display_vflip", NULL};
 static const char *const opt_name_rc_overrides[]  = 
{"rc_override", NULL};
 static const char *const opt_name_intra_matrices[]= 
{"intra_matrix", NULL};
 static const char *const opt_name_inter_matrices[]= 
{"inter_matrix", NULL};
@@ -800,6 +805,39 @@ static int opt_recording_timestamp(void *optctx, const 
char *opt, const char *ar
 return 0;
 }
 
+static void add_display_matrix_to_stream(OptionsContext *o,
+ AVFormatContext *ctx, AVStream *st)
+{
+double rotation = DBL_MAX;
+int hflip = -1, vflip = -1;
+int hflip_set = 0, vflip_set = 0, rotation_set = 0;
+uint8_t *buf = NULL;
+
+MATCH_PER_STREAM_OPT(display_rotations, dbl, rotation, ctx, st);
+MATCH_PER_STREAM_OPT(display_hflips,i,   hflip,ctx, st);
+MATCH_PER_STREAM_OPT(display_vflips,i,   vflip,ctx, st);
+
+rotation_set = rotation != DBL_MAX;
+hflip_set= hflip != -1;
+vflip_set= vflip != -1;
+
+if (!rotation_set && !hflip_set &

[FFmpeg-devel] [PATCH v7 2/2] ffmpeg: Deprecate display rotation override with a metadata key

2022-10-15 Thread Thilo Borgmann
From: Jan Ekström 

Now that we have proper options for defining display matrix
overrides, this should no longer be required.

fftools does not have its own versioning, so for now the define is
just set to 1 and disables the functionality if set to zero.
---
 fftools/ffmpeg.c |  2 ++
 fftools/ffmpeg.h |  5 +
 fftools/ffmpeg_opt.c | 10 ++
 3 files changed, 17 insertions(+)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 754172e568..7722719fb9 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -2834,12 +2834,14 @@ static int init_output_stream_streamcopy(OutputStream 
*ost)
 }
 }
 
+#if FFMPEG_ROTATION_METADATA
 if (ost->rotate_overridden) {
 uint8_t *sd = av_stream_new_side_data(ost->st, 
AV_PKT_DATA_DISPLAYMATRIX,
   sizeof(int32_t) * 9);
 if (sd)
 av_display_rotation_set((int32_t *)sd, 
-ost->rotate_override_value);
 }
+#endif
 
 switch (par->codec_type) {
 case AVMEDIA_TYPE_AUDIO:
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 684c51e524..4b7bcaa0e9 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -53,6 +53,7 @@
 #define FFMPEG_OPT_PSNR 1
 #define FFMPEG_OPT_MAP_CHANNEL 1
 #define FFMPEG_OPT_MAP_SYNC 1
+#define FFMPEG_ROTATION_METADATA 1
 
 enum VideoSyncMethod {
 VSYNC_AUTO = -1,
@@ -534,11 +535,15 @@ typedef struct OutputStream {
 int is_cfr;
 int force_fps;
 int top_field_first;
+#if FFMPEG_ROTATION_METADATA
 int rotate_overridden;
+#endif
 int autoscale;
 int bitexact;
 int bits_per_raw_sample;
+#if FFMPEG_ROTATION_METADATA
 double rotate_override_value;
+#endif
 
 AVRational frame_aspect_ratio;
 
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index f83900eb60..ee43fdeca9 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -2858,6 +2858,7 @@ static void of_add_metadata(AVFormatContext *oc, const 
OptionsContext *o)
 for (int j = 0; j < oc->nb_streams; j++) {
 OutputStream *ost = output_streams[nb_output_streams - 
oc->nb_streams + j];
 if ((ret = check_stream_specifier(oc, oc->streams[j], 
stream_spec)) > 0) {
+#if FFMPEG_ROTATION_METADATA
 if (!strcmp(o->metadata[i].u.str, "rotate")) {
 char *tail;
 double theta = av_strtod(val, &tail);
@@ -2865,9 +2866,18 @@ static void of_add_metadata(AVFormatContext *oc, const 
OptionsContext *o)
 ost->rotate_overridden = 1;
 ost->rotate_override_value = theta;
 }
+
+av_log(NULL, AV_LOG_WARNING,
+   "Conversion of a 'rotate' metadata key to a "
+   "proper display matrix rotation is deprecated. "
+   "See -display_rotation for setting rotation "
+   "instead.");
 } else {
+#endif
 av_dict_set(&oc->streams[j]->metadata, 
o->metadata[i].u.str, *val ? val : NULL, 0);
+#if FFMPEG_ROTATION_METADATA
 }
+#endif
 } else if (ret < 0)
 exit_program(1);
 }
-- 
2.20.1 (Apple Git-117)

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v6 1/2] ffmpeg: Add display_{rotation, hflip, vflip} options

2022-10-15 Thread Thilo Borgmann

Am 04.10.22 um 10:44 schrieb Anton Khirnov:

Quoting Thilo Borgmann (2022-09-26 07:57:52)

From: Jan Ekström 

This enables overriding the rotation as well as horizontal/vertical
flip state of a specific video stream on the input side.

Additionally, switch the singular test that was utilizing the rotation
metadata to instead override the input display rotation, thus leading
to the same result.
---
  doc/ffmpeg.texi | 29 +
  fftools/ffmpeg.h|  6 +
  fftools/ffmpeg_opt.c| 50 +
  tests/fate/filter-video.mak |  2 +-
  4 files changed, 86 insertions(+), 1 deletion(-)

diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
index 42440d93b4..6016b43892 100644
--- a/doc/ffmpeg.texi
+++ b/doc/ffmpeg.texi
@@ -912,6 +912,35 @@ If used together with @option{-vcodec copy}, it will 
affect the aspect ratio
  stored at container level, but not the aspect ratio stored in encoded
  frames, if it exists.
  
+@item -display_rotation[:@var{stream_specifier}] @var{rotation} (@emph{input,per-stream})

+Set the video display rotation in degrees specified by @var{rotation}.
+
+@var{rotation} is a floating point number that describes a pure
+counter-clockwise rotation in degrees.
+When setting this, @code{-autorotate} logic will be affected.
+For additional parameters affecting display matrix side data into which this
+information is saved, see @code{-display_hflip}, @code{-display_vflip}.
+
+These options work as a unit, so if only one of them is set, then the display
+matrix will be overridden to that specific value with the rest being set to
+default values.
+
+If unset, the default value if a display matrix is being defined is a rotation
+of zero degrees.
+
+@item -display_hflip[:@var{stream_specifier}] (@emph{input,per-stream})
+Set whether on display the image should be horizontally flipped.
+
+If unset, the default value if a display matrix is being defined is that there
+is no additional horizontal flip. See @code{-display_rotation}.
+
+@item -display_vflip[:@var{stream_specifier}] (@emph{input,per-stream})
+Set whether on display the image should be vertically flipped.
+
+If unset, the default value if a display matrix is being defined is that there
+is no additional vertical flip. See @code{-display_rotation}.


@item -display_rotation[:@var{stream_specifier}] @var{rotation} 
(@emph{input,per-stream})
Set video rotation metadata.

@var{rotation} is a decimal number specifying the amount in degree by
which the video should be rotated counter-clockwise before being
displayed.

This option overrides the rotation/display transform metadata stored in
the file, if any. When the video is being transcoded (rather than
copied) and @code{-autorotate} is enabled, the video will be rotated at
the filtering stage. Otherwise, the metadata will be written into the
output file if the muxer supports it.

If the @code{-display_hflip} and/or @code{-display_vflip} options are
given, they are applied after the rotation specified by this option.

@item -display_hflip[:@var{stream_specifier}] (@emph{input,per-stream})
Set whether on display the image should be horizontally flipped.

See the @code{-display_rotation} option for more details.

@item -display_vflip[:@var{stream_specifier}] (@emph{input,per-stream})
Set whether on display the image should be vertically flipped.

See the @code{-display_rotation} option for more details.


+static void add_display_matrix_to_stream(OptionsContext *o,
+ AVFormatContext *ctx, AVStream *st)
+{
+double rotation = DBL_MAX;
+int hflip = -1, vflip = -1;
+int hflip_set = 0, vflip_set = 0, rotation_set = 0;
+uint8_t *buf = NULL;


should be int32_t*


av_stream_new_side_data() returns uint8_t*.

So it is either add a cast to if(...) or two casts to av_display_...().

All else in v7.

Thanks,
Thilo


___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".