From 3ec2012cec2deeeb9af34d249cfb337e549df9b1 Mon Sep 17 00:00:00 2001 From: "Alex Xu (Hello71)" Date: Sat, 2 Oct 2021 13:19:10 -0400 Subject: [PATCH] mp_image, f_decoder_wrapper: implement AV_FRAME_DATA_DISPLAYMATRIX fixes #9249 (JPEG orientation support) with ffmpeg commit [0]. [0] https://github.com/FFmpeg/FFmpeg/commit/e93c9986027d17917c3b4f533b28ee4a2ce7cd4c --- filters/f_decoder_wrapper.c | 4 +++- video/mp_image.c | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/filters/f_decoder_wrapper.c b/filters/f_decoder_wrapper.c index 9be8743e53..38cb64dcd0 100644 --- a/filters/f_decoder_wrapper.c +++ b/filters/f_decoder_wrapper.c @@ -594,12 +594,14 @@ static void fix_image_params(struct priv *p, if (m.p_w <= 0 || m.p_h <= 0) m.p_w = m.p_h = 1; - m.rotate = p->codec->rotate; m.stereo3d = p->codec->stereo_mode; if (opts->video_rotate < 0) { m.rotate = 0; } else { + // ffmpeg commit 535a835e51 says that frame rotate takes priority + if (!m.rotate) + m.rotate = p->codec->rotate; m.rotate = (m.rotate + opts->video_rotate) % 360; } diff --git a/video/mp_image.c b/video/mp_image.c index 484108c315..91755c3273 100644 --- a/video/mp_image.c +++ b/video/mp_image.c @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -973,6 +974,13 @@ struct mp_image *mp_image_from_av_frame(struct AVFrame *src) dst->params.alpha = p->alpha; } + sd = av_frame_get_side_data(src, AV_FRAME_DATA_DISPLAYMATRIX); + if (sd) { + double r = av_display_rotation_get((int32_t *)(sd->data)); + if (!isnan(r)) + dst->params.rotate = (((int)(-r) % 360) + 360) % 360; + } + sd = av_frame_get_side_data(src, AV_FRAME_DATA_ICC_PROFILE); if (sd) dst->icc_profile = sd->buf;