summary refs log tree commit diff
diff options
context:
space:
mode:
authorTerin Stock <terinjokes@gmail.com>2024-04-22 00:47:58 +0200
committerTerin Stock <terinjokes@gmail.com>2024-04-22 00:47:58 +0200
commit4e55d5d24df95feeb3aabf49263c77cd29a2d877 (patch)
treecc6d193f1834f8bda646644c4aefa23e6ddc0fca
parent6f0690f702adb6bbacb240f72238e7b4fd9dcfa9 (diff)
screen recordings with MagicYUV and Spectacle HEAD trunk
On Windows I use Bandicamp and MagicYUV to record gameplay losslessly
with minimal CPU impact. However, Spectacle only supports encoding with
H264 or WebM, which is neither lossless nor light on the CPU.

This changeset adds support for the MagicYUV 4:4:4 codec to Spectacle
and the underlying kpipewire plumbing.
-rw-r--r--kpipewire/5.27-magicyuv-yuv444.patch51
-rw-r--r--spectacle/23.08-magicyuv-yuv444.patch37
2 files changed, 88 insertions, 0 deletions
diff --git a/kpipewire/5.27-magicyuv-yuv444.patch b/kpipewire/5.27-magicyuv-yuv444.patch
new file mode 100644
index 0000000..c742afc
--- /dev/null
+++ b/kpipewire/5.27-magicyuv-yuv444.patch
@@ -0,0 +1,51 @@
+From e943d0ca542b4e4f4c458165fdcdc8e413c3d2a5 Mon Sep 17 00:00:00 2001
+From: Terin Stock <terinjokes@gmail.com>
+Date: Mon, 22 Apr 2024 00:29:34 +0200
+Subject: [PATCH] Record: support MagicYUV 4:4:4
+
+The two codecs currently supported, H264 and WebM are not suitable for
+recording with minimal CPU overhead and losslessly for farther editing
+or archiving.
+
+This changeset adds support for recording in MagicYUV 4:4:4 in a
+Matroska container. This is suitably fast and satisfies the lossless
+goal, while still having some compression. These can be transcoded to
+FFV1 with no quality loss offline.
+---
+ src/pipewirerecord.cpp | 12 ++++++++----
+ 1 file changed, 8 insertions(+), 4 deletions(-)
+
+diff --git a/src/pipewirerecord.cpp b/src/pipewirerecord.cpp
+index ac8132e..232bbd6 100644
+--- a/src/pipewirerecord.cpp
++++ b/src/pipewirerecord.cpp
+@@ -301,10 +301,14 @@ void PipeWireRecordProduce::setupStream()
+     m_avCodecContext->height = size.height();
+     m_avCodecContext->max_b_frames = 1;
+     m_avCodecContext->gop_size = 100;
+-    if (m_codec->pix_fmts && m_codec->pix_fmts[0] > 0) {
+-        m_avCodecContext->pix_fmt = m_codec->pix_fmts[0];
++    if (QStringLiteral("magicyuv") == QString::fromUtf8(m_encoder)) {
++        m_avCodecContext->pix_fmt = AV_PIX_FMT_YUV444P;
+     } else {
+-        m_avCodecContext->pix_fmt = AV_PIX_FMT_YUV420P;
++        if (m_codec->pix_fmts && m_codec->pix_fmts[0] > 0) {
++            m_avCodecContext->pix_fmt = m_codec->pix_fmts[0];
++        } else {
++            m_avCodecContext->pix_fmt = AV_PIX_FMT_YUV420P;
++        }
+     }
+     m_avCodecContext->time_base = AVRational{1, 1000};
+ 
+@@ -462,7 +466,7 @@ QByteArray PipeWireRecord::encoder() const
+ 
+ QList<QByteArray> PipeWireRecord::suggestedEncoders() const
+ {
+-    QList<QByteArray> ret = {"libvpx", "libx264"};
++    QList<QByteArray> ret = {"libvpx", "libx264", "magicyuv"};
+     std::remove_if(ret.begin(), ret.end(), [](const QByteArray &encoder) {
+         return !avcodec_find_encoder_by_name(encoder.constData());
+     });
+-- 
+2.43.2
+
diff --git a/spectacle/23.08-magicyuv-yuv444.patch b/spectacle/23.08-magicyuv-yuv444.patch
new file mode 100644
index 0000000..1b20487
--- /dev/null
+++ b/spectacle/23.08-magicyuv-yuv444.patch
@@ -0,0 +1,37 @@
+From b71c7ec94e989dae259bd603232d565b3d0e0f29 Mon Sep 17 00:00:00 2001
+From: Terin Stock <terinjokes@gmail.com>
+Date: Mon, 22 Apr 2024 00:39:36 +0200
+Subject: [PATCH] add MagicYUV 4:4:4 support
+
+Allow Spectacle to record with the MagicYUV codec, added in a separate
+patch to kpipewire. As this version of Spectacle makes codec decisions
+based on file extensions, this patch usurps "mkv" to represent this codec.
+---
+ src/Platforms/VideoPlatformWayland.cpp | 4 ++++
+ 1 file changed, 4 insertions(+)
+
+diff --git a/src/Platforms/VideoPlatformWayland.cpp b/src/Platforms/VideoPlatformWayland.cpp
+index 8811b30c..a2cc7fcf 100644
+--- a/src/Platforms/VideoPlatformWayland.cpp
++++ b/src/Platforms/VideoPlatformWayland.cpp
+@@ -83,6 +83,8 @@ QStringList VideoPlatformWayland::suggestedExtensions() const
+             extensions.append(QStringLiteral("webm"));
+         } else if (enc == "libx264") {
+             extensions.append(QStringLiteral("mp4"));
++        } else if (enc == "magicyuv") {
++            extensions.append(QStringLiteral("mkv"));
+         }
+     }
+ #else
+@@ -108,6 +110,8 @@ void VideoPlatformWayland::setExtension(const QString &extension)
+         m_recorder->setEncoder("libvpx");
+     } else if (extension == QStringLiteral("mp4")) {
+         m_recorder->setEncoder("libx264");
++    } else if (extension == QStringLiteral("mkv")) {
++        m_recorder->setEncoder("magicyuv");
+     } else {
+         qWarning() << "Unsupported extension" << extension;
+     }
+-- 
+2.43.2
+