#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>
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;
} 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")) {
}
/*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);