Skip to content

Commit

Permalink
#3964 multiple options per encoding
Browse files Browse the repository at this point in the history
ie: both openh264enc and x264enc can encode h264
  • Loading branch information
totaam committed Mar 26, 2024
1 parent d8ae699 commit f024726
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions xpra/codecs/gstreamer/capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from xpra.os_util import gi_import
from xpra.util.env import envbool
from xpra.util.str_fn import csv
from xpra.util.objects import typedict, AtomicInteger
from xpra.gstreamer.common import (
import_gst, GST_FLOW_OK, get_element_str,
Expand Down Expand Up @@ -139,22 +140,29 @@ def get_type(self) -> str:


ENCODER_ELEMENTS: dict[str, str] = {
"jpeg": "jpegenc",
"h264": "x264enc",
"vp8": "vp8enc",
"vp9": "vp9enc",
"av1": "av1enc",
"jpeg": ("jpegenc", ),
"h264": ("openh264enc", "x264enc"),
"vp8": ("vp8enc", ),
"vp9": ("vp9enc", ),
"av1": ("av1enc", ),
}


def choose_encoder(plugins: Iterable[str]) -> str:
# for now, just use the first one available:
for plugin in plugins:
if plugin in get_all_plugin_names():
return plugin
return ""


def choose_video_encoder(encodings: Iterable[str]) -> str:
log(f"choose_video_encoder({encodings})")
for encoding in encodings:
element = ENCODER_ELEMENTS.get(encoding, "")
plugins = ENCODER_ELEMENTS.get(encoding, ())
element = choose_encoder(plugins)
if not element:
continue
if element not in get_all_plugin_names():
log(f"skipped {encoding!r} due to missing {element!r}")
log(f"skipped {encoding!r} due to missing: {csv(plugins)}")
continue
log(f"selected {encoding!r}")
return encoding
Expand All @@ -170,11 +178,12 @@ class CaptureAndEncode(Capture):
def create_pipeline(self, capture_element: str = "ximagesrc") -> None:
# we are overloading "pixel_format" as "encoding":
encoding = self.pixel_format
encoder = ENCODER_ELEMENTS.get(encoding)
elements = ENCODER_ELEMENTS.get(encoding)
if not elements:
raise ValueError(f"no encoders defined for {encoding!r}")
encoder = choose_encoder(elements)
if not encoder:
raise ValueError(f"no encoder defined for {encoding}")
if encoder not in get_all_plugin_names():
raise RuntimeError(f"encoder {encoder} is not available")
raise RuntimeError(f"no encoders found for {encoding!r}")
options = typedict({
"speed": 100,
"quality": 100,
Expand Down

0 comments on commit f024726

Please sign in to comment.