1
0
Fork 0
mirror of https://gitlab.alpinelinux.org/alpine/aports.git synced 2025-07-16 04:35:13 +03:00
aports/community/snapshot/0002-aperture-Support-H264-recorder-encoding.patch
Robert Mader 832f0ae6ff community/snapshot: Use H264 by default
Using openh264 which we already depend on via -bad.

This follows what Gnome-Shell does for a while now and provides
visibly better quality while at the same time having better
performance.

Unfortunately the upstream patch wont make it into Gnome 48,
thus carry it downstream for now - it's worth it.
2025-01-29 21:48:18 +00:00

162 lines
6.2 KiB
Diff

From a3c7eb3bc508f6c1b884f022ee56186ae5221cef Mon Sep 17 00:00:00 2001
From: Robert Mader <robert.mader@posteo.de>
Date: Tue, 23 Jul 2024 15:25:57 +0200
Subject: [PATCH 2/3] aperture: Support H264 recorder encoding
And enable HW-encoding with VA-API by default in order to roughly
follow Gnome-Shell screen recording behavior.
Using H264 improves both performance and image quality compared to VP8
when using SW-encoders, partly because they are more optimized.
With HW-encoders the same applies for an even higher degree.
---
aperture/src/viewfinder.rs | 112 ++++++++++++++++++++++++++++++++-----
1 file changed, 97 insertions(+), 15 deletions(-)
diff --git a/aperture/src/viewfinder.rs b/aperture/src/viewfinder.rs
index ba4df4c..dca15bd 100644
--- a/aperture/src/viewfinder.rs
+++ b/aperture/src/viewfinder.rs
@@ -43,6 +43,10 @@ mod imp {
pub is_recording_video: RefCell<Option<PathBuf>>,
#[property(get, set = Self::set_disable_audio_recording, explicit_notify)]
disable_audio_recording: Cell<bool>,
+ #[property(get, set = Self::set_disable_h264, explicit_notify)]
+ disable_h264: Cell<bool>,
+ #[property(get, set = Self::set_disable_hw_encoding, explicit_notify)]
+ disable_hw_encoding: Cell<bool>,
pub zbar_branch: RefCell<Option<gst::Element>>,
pub devices: OnceCell<crate::DeviceProvider>,
@@ -188,6 +192,48 @@ mod imp {
obj.notify_disable_audio_recording();
}
+
+ fn set_disable_h264(&self, value: bool) {
+ let obj = self.obj();
+
+ if value == self.disable_h264.replace(value) {
+ return;
+ }
+
+ if matches!(
+ self.camerabin().current_state(),
+ gst::State::Playing | gst::State::Paused
+ ) {
+ obj.stop_stream();
+ obj.setup_recording();
+ obj.start_stream();
+ } else {
+ obj.setup_recording();
+ }
+
+ obj.notify_disable_h264();
+ }
+
+ fn set_disable_hw_encoding(&self, value: bool) {
+ let obj = self.obj();
+
+ if value == self.disable_hw_encoding.replace(value) {
+ return;
+ }
+
+ if matches!(
+ self.camerabin().current_state(),
+ gst::State::Playing | gst::State::Paused
+ ) {
+ obj.stop_stream();
+ obj.setup_recording();
+ obj.start_stream();
+ } else {
+ obj.setup_recording();
+ }
+
+ obj.notify_disable_hw_encoding();
+ }
}
#[glib::object_subclass]
@@ -863,28 +909,64 @@ impl Viewfinder {
fn setup_recording(&self) {
use gst_pbutils::encoding_profile::EncodingProfileBuilder;
- let caps = gst::Caps::builder("video/webm").build();
- let mut container_profile = gst_pbutils::EncodingContainerProfile::builder(&caps)
- .name("WebM audio/video")
- .description("Standard WebM/VP8/Vorbis");
+ let profile = if !self.disable_h264() {
+ if !self.disable_hw_encoding() {
+ let registry = gst::Registry::get();
+ if let Some(vah264lpenc) = registry.lookup_feature("vah264lpenc") {
+ vah264lpenc.set_rank(gst::Rank::PRIMARY);
+ } else if let Some(vah264enc) = registry.lookup_feature("vah264enc") {
+ vah264enc.set_rank(gst::Rank::PRIMARY);
+ }
+ }
+
+ let caps = gst::Caps::builder("video/quicktime").build();
+ let mut container_profile = gst_pbutils::EncodingContainerProfile::builder(&caps)
+ .name("MP4 audio/video")
+ .description("Standard MP4/H264/MP3");
+
+ let video_profile = gst_pbutils::EncodingVideoProfile::builder(
+ &gst::Caps::builder("video/x-h264").build(),
+ )
+ .variable_framerate(true)
+ .build();
+ container_profile = container_profile.add_profile(video_profile);
- let video_profile =
- gst_pbutils::EncodingVideoProfile::builder(&gst::Caps::builder("video/x-vp8").build())
- .preset("Profile Realtime")
- .variable_framerate(true)
+ if !self.disable_audio_recording() {
+ let audio_profile = gst_pbutils::EncodingAudioProfile::builder(
+ &gst::Caps::builder("audio/mpeg").build(),
+ )
.build();
- container_profile = container_profile.add_profile(video_profile);
+ container_profile = container_profile.add_profile(audio_profile);
+ }
- if !self.disable_audio_recording() {
- let audio_profile = gst_pbutils::EncodingAudioProfile::builder(
- &gst::Caps::builder("audio/x-vorbis").build(),
+ container_profile.build()
+ } else {
+ let caps = gst::Caps::builder("video/webm").build();
+ let mut container_profile = gst_pbutils::EncodingContainerProfile::builder(&caps)
+ .name("WebM audio/video")
+ .description("Standard WebM/VP8/Vorbis");
+
+ let video_profile = gst_pbutils::EncodingVideoProfile::builder(
+ &gst::Caps::builder("video/x-vp8").build(),
)
+ .preset("Profile Realtime")
+ .variable_framerate(true)
.build();
- container_profile = container_profile.add_profile(audio_profile);
- }
+ container_profile = container_profile.add_profile(video_profile);
+
+ if !self.disable_audio_recording() {
+ let audio_profile = gst_pbutils::EncodingAudioProfile::builder(
+ &gst::Caps::builder("audio/x-vorbis").build(),
+ )
+ .build();
+ container_profile = container_profile.add_profile(audio_profile);
+ }
+
+ container_profile.build()
+ };
let camerabin = self.imp().camerabin();
- camerabin.set_property("video-profile", container_profile.build());
+ camerabin.set_property("video-profile", profile);
}
fn init(&self) {
--
2.48.1