Skip to content
Snippets Groups Projects
Commit 339a85fe authored by Robert Mader's avatar Robert Mader Committed by Bart Ribbers
Browse files

community/gst-plugins-good: Backport mp4 rotation-tag support patch

Backport of
https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/8371
in order to fix video recording on phones.
parent 8147d5ce
No related branches found
No related tags found
2 merge requests!79570community/firefox-esr: upgrade to 128.7.0,!79110community/[gst-plugins-good|gtk4.0]: Backport rotation support patches
From 2bc22fef97f925a5065cb574f27770cf589f3338 Mon Sep 17 00:00:00 2001
From: Robert Mader <robert.mader@collabora.com>
Date: Sun, 19 Jan 2025 18:49:57 +0100
Subject: [PATCH] qtmux: Implement rotation tag support
Mirroring the demux element and isomp4mux from gst-plugins-rs.
Tested against other Gst elements and MPV. Note that the later
apparently does not show correct results for flipped values.
Can be tested with:
```
gst-launch-1.0 \
videotestsrc num-buffers=90 ! \
taginject tags="image-orientation=rotate-90" ! \
capsfilter caps=video/x-raw,width=640,height=480,max-framerate=30/1 ! \
videoconvert ! \
queue ! \
openh264enc ! \
queue ! \
h264parse ! \
mp4mux ! \
filesink location=./test.mp4
```
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/8371>
(cherry picked from commit 1fc6f0d349d31f3e3783d46da39ffa93f37bb87a)
---
.../gst-plugins-good/gst/isomp4/gstqtmux.c | 69 +++++++++++++++++++
1 file changed, 69 insertions(+)
diff --git a/gst/isomp4/gstqtmux.c b/gst/isomp4/gstqtmux.c
index 29250c70f2..943d4ec389 100644
--- a/gst/isomp4/gstqtmux.c
+++ b/gst/isomp4/gstqtmux.c
@@ -1817,6 +1817,62 @@ gst_qt_mux_add_metadata_tags (GstQTMux * qtmux, const GstTagList * list,
return;
}
+static void
+gst_qt_mux_set_matrix_from_tags (guint32 * matrix, const GstTagList * tags)
+{
+ gchar *orientation;
+
+ if (!tags ||
+ !gst_tag_list_get_string (tags, "image-orientation", &orientation))
+ return;
+
+ if (!g_strcmp0 ("rotate-0", orientation)) {
+ matrix[0] = 1 << 16;
+ matrix[1] = 0;
+ matrix[3] = 0;
+ matrix[4] = 1 << 16;
+ } else if (!g_strcmp0 ("rotate-90", orientation)) {
+ matrix[0] = 0;
+ matrix[1] = 1 << 16;
+ matrix[3] = G_MAXUINT16 << 16;
+ matrix[4] = 0;
+ } else if (!g_strcmp0 ("rotate-180", orientation)) {
+ matrix[0] = G_MAXUINT16 << 16;
+ matrix[1] = 0;
+ matrix[3] = 0;
+ matrix[4] = G_MAXUINT16 << 16;
+ } else if (!g_strcmp0 ("rotate-270", orientation)) {
+ matrix[0] = 0;
+ matrix[1] = G_MAXUINT16 << 16;
+ matrix[3] = 1 << 16;
+ matrix[4] = 0;
+ } else if (!g_strcmp0 ("flip-rotate-0", orientation)) {
+ matrix[0] = G_MAXUINT16 << 16;
+ matrix[1] = 0;
+ matrix[3] = 0;
+ matrix[4] = 1 << 16;
+ } else if (!g_strcmp0 ("flip-rotate-90", orientation)) {
+ matrix[0] = 0;
+ matrix[1] = G_MAXUINT16 << 16;
+ matrix[3] = G_MAXUINT16 << 16;
+ matrix[4] = 0;
+ } else if (!g_strcmp0 ("flip-rotate-180", orientation)) {
+ matrix[0] = 1 << 16;
+ matrix[1] = 0;
+ matrix[3] = 0;
+ matrix[4] = G_MAXUINT16 << 16;
+ } else if (!g_strcmp0 ("flip-rotate-270", orientation)) {
+ matrix[0] = 0;
+ matrix[1] = 1 << 16;
+ matrix[3] = 1 << 16;
+ matrix[4] = 0;
+ } else {
+ GST_WARNING ("Unsupported orientation %s", orientation);
+ }
+
+ g_free (orientation);
+}
+
/*
* Gets the tagsetter iface taglist and puts the known tags
* into the output stream
@@ -1825,6 +1881,7 @@ static void
gst_qt_mux_setup_metadata (GstQTMux * qtmux)
{
const GstTagList *tags = NULL;
+ guint32 transform_matrix[9] = { 0 };
GList *l;
GST_OBJECT_LOCK (qtmux);
@@ -1852,6 +1909,12 @@ gst_qt_mux_setup_metadata (GstQTMux * qtmux)
GST_DEBUG_OBJECT (qtmux, "No new tags received");
}
+ /* Initialize to identity */
+ transform_matrix[0] = 1 << 16;
+ transform_matrix[4] = 1 << 16;
+ transform_matrix[8] = 1 << 30;
+ gst_qt_mux_set_matrix_from_tags (transform_matrix, tags);
+
GST_OBJECT_LOCK (qtmux);
for (l = GST_ELEMENT (qtmux)->sinkpads; l; l = l->next) {
GstQTMuxPad *qpad = GST_QT_MUX_PAD (l->data);
@@ -1860,6 +1923,12 @@ gst_qt_mux_setup_metadata (GstQTMux * qtmux)
GST_DEBUG_OBJECT (qpad, "Adding tags");
gst_tag_list_remove_tag (qpad->tags, GST_TAG_CONTAINER_FORMAT);
gst_qt_mux_add_metadata_tags (qtmux, qpad->tags, &qpad->trak->udta);
+
+ /* Use the matrix from the stream tags if available, otherwise fall back
+ * to global tags or identity. */
+ memcpy (qpad->trak->tkhd.matrix, transform_matrix, sizeof (guint32) * 9);
+ gst_qt_mux_set_matrix_from_tags (qpad->trak->tkhd.matrix, qpad->tags);
+
qpad->tags_changed = FALSE;
GST_DEBUG_OBJECT (qpad, "Tags added");
} else {
--
2.48.1
maintainer="Krassy Boykinov <kboykinov@teamcentrixx.com>"
pkgname=gst-plugins-good
pkgver=1.24.11
pkgrel=1
pkgrel=2
pkgdesc="GStreamer streaming media framework good plugins"
url="https://gstreamer.freedesktop.org"
arch="all"
......@@ -79,6 +79,7 @@ esac
ldpath="/usr/lib/gstreamer-1.0"
source="https://gstreamer.freedesktop.org/src/gst-plugins-good/gst-plugins-good-$pkgver.tar.xz
flaky-test.patch
0001-qtmux-Implement-rotation-tag-support.patch
"
# secfixes:
......@@ -201,4 +202,5 @@ gtk() {
sha512sums="
7b15baf2aa0aa72f469d0c44cc13a892b85e7d4e08d04c44bfeb0ff475aa274474adcf652ed4fb9bca22155d04afa47898a423d3b5844a9b597337a3ab46faed gst-plugins-good-1.24.11.tar.xz
e471a892c511c501fdd336cd1729df4e955e266a395260db50665b4ee717d881a007ae84873c57e386931c042ce08ee8f3ab8e102ba251632f724e167b5af913 flaky-test.patch
7a0b8b236650d20b5af3a520797ea25387bf84ed18628121ac79a4970f45533b48fc16025a0f56a4536b83f8bdded3a80778ef7c7435cf613e952aca6fd462ef 0001-qtmux-Implement-rotation-tag-support.patch
"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment