From 3f2e2fa9b9d509e3443c1b9604430259aa29f6ab Mon Sep 17 00:00:00 2001
From: Gilles Vieira <gilles.vieira@dailymotion.com>
Date: Sat, 13 Oct 2018 08:15:56 +0200
Subject: [PATCH] Fix rotation metadata override when transcoding

Fixes: Ticket4560
---
 fftools/ffmpeg.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index aa495b5d9e..d69c1d1652 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -3591,6 +3591,15 @@ static int init_output_stream(OutputStream *ost, char *error, int error_len)
             ost->st->duration = av_rescale_q(ist->st->duration, ist->st->time_base, ost->st->time_base);
 
         ost->st->codec->codec= ost->enc_ctx->codec;
+
+        // Also set the rotation override when transcoding
+        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);
+       }
     } else if (ost->stream_copy) {
         ret = init_output_stream_streamcopy(ost);
         if (ret < 0)
-- 
2.17.0

