Modify the way to get the 'rotate' from ffmpeg 88/285788/9 accepted/tizen/unified/20221221.165256
authorjiyong.min <jiyong.min@samsung.com>
Tue, 20 Dec 2022 07:08:51 +0000 (16:08 +0900)
committerjiyong.min <jiyong.min@samsung.com>
Tue, 20 Dec 2022 08:41:50 +0000 (17:41 +0900)
 - The 'rotate' in AVstream.metadata was removed since ffmpeg 5.1.2.

Change-Id: I4ac6cc85786ffd5a507f0a8e68e2fb9cd3019290

formats/ffmpeg/mm_file_format_ffmpeg.c
packaging/libmm-fileinfo.spec

index 4126126..ca4729e 100644 (file)
@@ -25,6 +25,7 @@
 #include <libavformat/avformat.h>
 #include <libavcodec/avcodec.h>
 #include <libavutil/imgutils.h>
+#include <libavutil/display.h>
 #include <libswscale/swscale.h>
 #include <mm_error.h>
 #include <mm_types.h>
@@ -669,6 +670,27 @@ static void __fill_artwork_in_context(AVStream *st, MMFileFormatContext *formatC
        formatContext->artwork = g_memdup2(pkt.data, pkt.size);
 }
 
+static void __fill_rotate_in_context(AVStream *st, MMFileFormatContext *formatContext)
+{
+       uint8_t *matrix = NULL;
+       double rotate = 0.0;
+
+       matrix = av_stream_get_side_data(st, AV_PKT_DATA_DISPLAYMATRIX, NULL);
+       if (!matrix) {
+               debug_log(DEBUG, "matrix is empty");
+               return;
+       }
+
+       // from ffmpeg's code
+       rotate = av_display_rotation_get((int32_t *)matrix);
+       rotate = -rotate;
+       if (rotate < 0) // for backward compatibility
+               rotate += 360;
+       debug_log(RELEASE, "Rotate: %f", rotate);
+       mmfile_free(formatContext->rotate);
+       formatContext->rotate = g_strdup_printf("%g", rotate);
+}
+
 static void __fill_metainfo_in_context(AVDictionary *metainfo, MMFileFormatContext *formatContext)
 {
        AVDictionaryEntry *tag = NULL;
@@ -716,9 +738,6 @@ static void __fill_metainfo_in_context(AVDictionary *metainfo, MMFileFormatConte
                } else if (!g_ascii_strcasecmp(tag->key, "lyrics")) {
                        mmfile_free(formatContext->unsyncLyrics);
                        formatContext->unsyncLyrics = g_strdup(tag->value);
-               } else if (!g_ascii_strcasecmp(tag->key, "rotate")) {   /*can be "90", "180", "270" */
-                       mmfile_free(formatContext->rotate);
-                       formatContext->rotate = g_strdup(tag->value);
                } else if (!g_ascii_strcasecmp(tag->key, "spherical-video")) {
                        ParseSpatialVideoMetadataFromXMLString(tag->value, formatContext);
                } else if (!g_ascii_strcasecmp(tag->key, "metadata_block_picture")) {
@@ -767,8 +786,11 @@ int mmfile_format_read_tag_ffmpg(MMFileFormatContext *formatContext)
                }
 
                /*refer to mov_read_covr() in ffmpeg.*/
-               if (st)
+               if (st) {
                        __fill_artwork_in_context(st, formatContext);
+                       if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
+                               __fill_rotate_in_context(st, formatContext);
+               }
 
                if (metainfo)
                        __fill_metainfo_in_context(metainfo, formatContext);
index af2212a..050a961 100644 (file)
@@ -1,6 +1,6 @@
 Name:      libmm-fileinfo
 Summary:    Media Fileinfo
-Version:    1.0.18
+Version:    1.0.19
 Release:    0
 Group:      System/Libraries
 License:    Apache-2.0