PR #25361 opened by Forgejo_Fairy
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25361
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25361.patch
Hardware-frame transcoding with default autorotation can produce unrotated
pixels without their display matrix. `configure_input_video_filter()` skips
autorotation for hardware pixel formats, but `ifilter_parameters_from_frame()`
removes the global matrix solely because autorotation is enabled.
Apply the same hardware-format condition when removing the global display
matrix. This preserves orientation metadata when the pixels remain unrotated.
Automatic insertion of hardware rotation filters remains unimplemented; this
addresses the metadata-loss portion of #25089.
The regression was verified with the attached sample and CUDA decoding: parent
7ac1b410e12f preserves the −180° matrix, while 7b18beb477f1 drops it. The later
fix 631ac6d055b27 restores propagation with `-noautorotate`, but leaves default
autorotation with hardware frames affected.
Reproduction on unpatched master 303510f9d1fe:
ffmpeg -hwaccel cuda -hwaccel_output_format cuda -i input.mov -an -c:v
hevc_nvenc output.mp4
ffprobe -v error -select_streams v:0 -show_entries
stream=width,height:stream_side_data=rotation output.mp4
Before this change, the output has unrotated 640×480 pixels and no display
matrix. Afterward, it retains the input's −180° matrix.
Validation on Linux x86-64 with an NVIDIA RTX 5090 and driver 595.84:
- CUDA decoding and HEVC NVENC encoding with input display rotations of 0°,
90°, 180° and 270°, both with default autorotation and `-noautorotate`.
- Corresponding software-decoding controls: default autorotation still rotates
pixels and removes the matrix; `-noautorotate` preserves it.
- Full transcode of the attached sample preserves its original matrix.
- `make fate-autorotate SAMPLES=/opt/fate-suite` passes.
- `git diff --check` passes.
QSV and D3D11VA were not runtime-tested; the changed condition is in their
shared hardware-frame filtering path. Correct presentation still depends on the
output format and player supporting display matrices.
From 849cbad750586b1f92c493d8836af8f82c3e308f Mon Sep 17 00:00:00 2001
From: Michael Niedermayer <[email protected]>
Date: Thu, 22 Oct 2026 16:06:38 +0000
Subject: [PATCH] fftools/ffmpeg_filter: preserve display matrix when hardware
autorotation is skipped
configure_input_video_filter() does not apply autorotation to hardware
pixel formats. Match that condition when deciding whether to remove the
global display matrix in ifilter_parameters_from_frame(), so transcoding
hardware frames does not discard their unapplied orientation.
The matrix was preserved before 7b18beb477f1716b8abac15df91410dc967be2e9.
631ac6d055b273c87feceb0c19ed62f211e8ef3b restored propagation with
-noautorotate, but left hardware inputs using the default setting affected.
Related to issue #25089. This preserves orientation metadata; automatic
insertion of hardware rotation filters remains unimplemented.
Tested with CUDA decoding and HEVC NVENC encoding at 0, 90, 180 and 270
degrees, with software decoding and with -noautorotate. fate-autorotate
also passes.
Assisted-by: Fairy
---
fftools/ffmpeg_filter.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 1b9befe0463..232ffbfff41 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -2393,7 +2393,8 @@ static int ifilter_parameters_from_frame(InputFilter
*ifilter, const AVFrame *fr
sd = av_frame_get_side_data(frame, AV_FRAME_DATA_DISPLAYMATRIX);
if (sd) {
memcpy(ifp->displaymatrix, sd->data, sizeof(ifp->displaymatrix));
- if (ifp->opts.flags & IFILTER_FLAG_AUTOROTATE)
+ if ((ifp->opts.flags & IFILTER_FLAG_AUTOROTATE) &&
+ !(av_pix_fmt_desc_get(ifp->format)->flags &
AV_PIX_FMT_FLAG_HWACCEL))
av_frame_side_data_remove(&ifp->side_data, &ifp->nb_side_data,
AV_FRAME_DATA_DISPLAYMATRIX);
}
ifp->displaymatrix_present = !!sd;
--
2.54.0
_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]