From 9f75564dc73b14cfa07021456209aaf7183a0c6e Mon Sep 17 00:00:00 2001 From: Igor Divjak Date: Tue, 20 Oct 2026 10:17:29 +1300 Subject: [PATCH 1/4] Add a per-camera video format picker Monologue always records at the camera's largest advertised resolution, so a camera whose top mode is slow (a Logitech C920's 2560x1472 YUYV mode delivers 2 fps) cannot be recorded at a usable frame rate, and there is no way to choose otherwise. A Format control beside the camera lists every format the camera advertises, largest first, with resolution, pixel format, and frame rate, and marks the active one. The choice is stored per camera and survives restarts, falling back to the existing maximum-resolution default when the camera no longer offers it. --- README.md | 2 +- src/Main.qml | 76 +++++++++++++++++++++++++++++++++++------ src/backend.cpp | 34 +++++++++++++++--- src/backend.h | 9 ++++- src/mediautils.cpp | 45 ++++++++++++++++++++++++ src/mediautils.h | 5 +++ tests/backend_tests.cpp | 8 +++++ tests/ui_tests.cpp | 3 ++ 8 files changed, 164 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 1168e5c..f84380b 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ A simple webcam recorder for Omarchy. Choose your camera and microphone once, then press **Space** to record. Press again to pause or resume the same take. Stop the take and it opens right away in a built-in editor: trim either end, cut ranges out of the middle, then **Save**. - Remembers camera and microphone by device ID; missing inputs never silently switch. -- Automatically selects the camera's maximum advertised video resolution, preferring 30 fps at that resolution. Preview preserves the whole frame. +- Automatically selects the camera's maximum advertised video resolution, preferring 30 fps at that resolution, and lists every advertised format in a dropdown so a different resolution, frame rate, or pixel format stays selected across sessions. Preview preserves the whole frame. - Live microphone meter with peak hold and clipping indication, including while paused. No microphone playback through your speakers. - Explicit No audio option for silent recordings. - Live Omarchy accent syncing, including theme symlink switches. Controls and dialogs follow Hyprland's active corner rounding, including personal overrides. Dark chrome and a yellow fallback follow Omacut; button foregrounds adapt for contrast. diff --git a/src/Main.qml b/src/Main.qml index 972c8b5..1b09fcb 100644 --- a/src/Main.qml +++ b/src/Main.qml @@ -121,7 +121,7 @@ ApplicationWindow { readonly property bool controlFocused: activeFocusItem && (activeFocusItem instanceof AbstractButton || activeFocusItem instanceof ComboBox || activeFocusItem instanceof Slider || activeFocusItem instanceof TextInput) Shortcut { sequence: "Space"; context: Qt.WindowShortcut; autoRepeat: false - enabled: !win.overlayOpen && !cameraChoice.popup.visible && !microphoneChoice.popup.visible && !win.controlFocused && !win.busy + enabled: !win.overlayOpen && !cameraChoice.popup.visible && !microphoneChoice.popup.visible && !formatChoice.popup.visible && !win.controlFocused && !win.busy onActivated: win.space() } // Stopping ends the take and opens it for editing. @@ -130,7 +130,7 @@ ApplicationWindow { Shortcut { sequence: "Ctrl+S"; context: Qt.WindowShortcut; autoRepeat: false; enabled: win.finished && !win.busy && !win.overlayOpen; onActivated: { player.pause(); backend.save() } } Shortcut { sequence: "Escape"; context: Qt.WindowShortcut; autoRepeat: false - enabled: (backend.takeActive || win.finished) && !win.busy && !win.overlayOpen && !cameraChoice.popup.visible && !microphoneChoice.popup.visible + enabled: (backend.takeActive || win.finished) && !win.busy && !win.overlayOpen && !cameraChoice.popup.visible && !microphoneChoice.popup.visible && !formatChoice.popup.visible onActivated: { player.pause(); restartDialog.open() } } // Editing the finished clip. @@ -246,6 +246,8 @@ ApplicationWindow { id: choice property string iconPath property string detail: "" + // Shows this fixed text instead of the selected row's label. + property string textOverride: "" property real maximumTextWidth: 260 textRole: "label" focusPolicy: Qt.TabFocus @@ -257,10 +259,10 @@ ApplicationWindow { background: Item { } contentItem: RowLayout { spacing: 8 - Icon { path: choice.iconPath; color: win.dimColor } + Icon { visible: choice.iconPath !== ""; path: choice.iconPath; color: win.dimColor } Label { Layout.maximumWidth: choice.maximumTextWidth; elide: Text.ElideRight; font: choice.font - text: choice.displayText + text: choice.textOverride !== "" ? choice.textOverride : choice.displayText color: choice.activeFocus ? win.accent : choice.enabled ? (choice.hovered ? "#ffffff" : win.textColor) : win.dimColor } Icon { visible: choice.enabled; path: win.icons.chevron; implicitWidth: 12; implicitHeight: 12; color: win.dimColor } @@ -274,6 +276,42 @@ ApplicationWindow { } HoverHandler { cursorShape: choice.enabled ? Qt.PointingHandCursor : Qt.ArrowCursor } } + // A tight popup row for long lists like camera formats. + component CompactRow: ItemDelegate { + id: row + required property int index + required property var modelData + readonly property bool selected: formatChoice.currentIndex === index + width: ListView.view.width + height: 24 + highlighted: formatChoice.highlightedIndex === index + contentItem: RowLayout { + spacing: 8 + Label { + id: rowLabel + Layout.fillWidth: true + text: modelData.label + font.pixelSize: 11 + color: row.highlighted ? win.accent : win.textColor + verticalAlignment: Text.AlignVCenter + elide: Text.ElideRight + } + Icon { + visible: row.selected; color: win.accent + implicitWidth: 12; implicitHeight: 12 + path: "M4 12.5l5 5 11-13" + } + } + background: Rectangle { + radius: Math.min(4, win.cornerRadius) + color: row.highlighted ? "#2c2c2f" : "transparent" + } + ToolTip { + visible: row.hovered && rowLabel.truncated + text: modelData.label + background: Rectangle { color: "#303037"; radius: win.cornerRadius } + } + } component ShortcutList: GridLayout { id: list property string heading @@ -410,13 +448,29 @@ ApplicationWindow { id: sources; visible: !win.finished; spacing: 2 anchors.left: parent.left; anchors.verticalCenter: parent.verticalCenter width: parent.width - SourceChoice { - id: cameraChoice; iconPath: win.icons.camera; detail: backend.formatLabel - maximumTextWidth: Math.min(260, sources.width - 44) - model: backend.cameras; currentIndex: backend.cameraIndex - enabled: !backend.takeActive && !win.busy - onActivated: index => { backend.selectCamera(index); liveVideo.forceActiveFocus() } - Accessible.name: "Camera" + RowLayout { + Layout.fillWidth: true; spacing: 8 + SourceChoice { + id: cameraChoice; iconPath: win.icons.camera; detail: backend.formatLabel + Layout.fillWidth: true + maximumTextWidth: Math.min(260, sources.width - 120) + model: backend.cameras; currentIndex: backend.cameraIndex + enabled: !backend.takeActive && !win.busy + onActivated: index => { backend.selectCamera(index); liveVideo.forceActiveFocus() } + Accessible.name: "Camera" + } + SourceChoice { + id: formatChoice; textOverride: "Format" + font.pixelSize: 11 + model: backend.cameraFormats; currentIndex: backend.cameraFormatIndex + enabled: !backend.takeActive && !win.busy && backend.cameraFormats.length > 0 + delegate: CompactRow { } + // The dropdown rewrites currentIndex itself; re-bind it to the backend's + // chosen format whenever the list or the selection changes. + onActivated: index => { backend.selectCameraFormat(index); formatChoice.currentIndex = Qt.binding(() => backend.cameraFormatIndex); liveVideo.forceActiveFocus() } + onModelChanged: formatChoice.currentIndex = Qt.binding(() => backend.cameraFormatIndex) + Accessible.name: "Camera format" + } } SourceChoice { id: microphoneChoice; iconPath: win.icons.microphone diff --git a/src/backend.cpp b/src/backend.cpp index 9c50603..25e4ce9 100644 --- a/src/backend.cpp +++ b/src/backend.cpp @@ -117,18 +117,35 @@ void Backend::activateSources() { if(m_writer || m_state=="saving" || m_probing) return; if(!m_activateHardware) { m_state="unavailable"; emit changed(); return; } releaseSources(); - m_state="starting"; m_message.clear(); m_formatLabel.clear(); m_activatedAt=now(); + m_state="starting"; m_message.clear(); m_formatLabel.clear(); m_cameraFormats.clear(); m_cameraFormatIndex=-1; m_activatedAt=now(); QCameraDevice selectedCamera; for(const auto &d:QMediaDevices::videoInputs()) if(deviceId(d.id())==m_cameraId) selectedCamera=d; QAudioDevice selectedAudio; for(const auto &d:QMediaDevices::audioInputs()) if(deviceId(d.id())==m_audioId) selectedAudio=d; if(selectedCamera.isNull()) { m_state="unavailable"; m_message="Connect a camera or choose an available video source."; } else { - m_cameraFormat=media::bestCameraFormat(selectedCamera); - if(m_cameraFormat.isNull()) { m_state="unavailable"; m_message="This camera advertises no supported video formats."; } + m_formatChoices=media::sortedFormats(selectedCamera); + for(const auto &f:m_formatChoices) + m_cameraFormats.append(QVariantMap{{"label",media::formatLabel(f.resolution(),f.minFrameRate(),f.maxFrameRate(),int(f.pixelFormat()))}}); + // bestFormat ranks the device's own order, so match its pick by identity + // instead of reusing the index against the sorted list. + const auto advertised=selectedCamera.videoFormats(); + QList choices; + for(const auto &f:advertised) choices.append({f.resolution(),f.minFrameRate(),f.maxFrameRate(),int(f.pixelFormat())}); + const int best=media::bestFormat(choices); + if(best<0) { m_state="unavailable"; m_message="This camera advertises no supported video formats."; } else { + // A format picked for this camera before wins, so a deliberate choice survives restarts. + const auto bestKey=media::formatKey(advertised[best].resolution(),advertised[best].minFrameRate(),advertised[best].maxFrameRate(),int(advertised[best].pixelFormat())); + int chosen=0; + const auto saved=m_settings.value("cameraFormat/"+m_cameraId).toString(); + const auto wanted=saved.isEmpty()?bestKey:saved; + for(int i=0;isetCameraFormat(m_cameraFormat); m_capture.setCamera(m_camera); @@ -149,6 +166,7 @@ void Backend::activateSources() { } else { m_settings.setValue("microphone/id","none"); m_settings.setValue("microphone/label","No audio"); } if(QStandardPaths::findExecutable("ffprobe").isEmpty() || QStandardPaths::findExecutable("ffmpeg").isEmpty()) { m_state="unavailable"; m_message="Install ffmpeg (including ffprobe) to record and inspect clips."; } else if(!Writer::supported(audioEnabled())) { m_state="unavailable"; m_message="This Qt multimedia backend cannot encode H.264 MP4 with the selected audio mode."; } + emit devicesChanged(); emit changed(); } void Backend::updateReady() { @@ -160,7 +178,7 @@ void Backend::receiveVideo(const QVideoFrame &frame) { if(!m_camera || !frame.isValid()) return; m_lastVideoAt=now(); if(frame.size()!=m_cameraFormat.resolution()) { - sourceFailed("The camera did not provide its maximum resolution. Choose another source or Retry."); return; + sourceFailed("The camera did not provide the selected resolution. Choose another format or Retry."); return; } m_lastFrame=frame; // Once stopped, the preview holds the take's final frame while it finalizes. @@ -230,6 +248,12 @@ void Backend::selectMicrophone(int index) { if(m_writer || index<0 || index>=m_microphones.size() || m_state=="saving" || m_probing) return; m_audioId=m_microphones[index].toMap()["id"].toString(); activateSources(); } +void Backend::selectCameraFormat(int index) { + if(m_writer || index<0 || index>=m_formatChoices.size() || m_state=="saving" || m_probing) return; + const auto &f=m_formatChoices[index]; + m_settings.setValue("cameraFormat/"+m_cameraId,media::formatKey(f.resolution(),f.minFrameRate(),f.maxFrameRate(),int(f.pixelFormat()))); + activateSources(); +} void Backend::retry() { if(!m_writer && m_state!="finished") activateSources(); } void Backend::toggleRecording() { if(m_dialogOpen) return; diff --git a/src/backend.h b/src/backend.h index e8eaceb..9458fce 100644 --- a/src/backend.h +++ b/src/backend.h @@ -27,6 +27,8 @@ class Backend : public QObject { Q_PROPERTY(QVariantList microphones READ microphones NOTIFY devicesChanged) Q_PROPERTY(int cameraIndex READ cameraIndex NOTIFY devicesChanged) Q_PROPERTY(int microphoneIndex READ microphoneIndex NOTIFY devicesChanged) + Q_PROPERTY(QVariantList cameraFormats READ cameraFormats NOTIFY devicesChanged) + Q_PROPERTY(int cameraFormatIndex READ cameraFormatIndex NOTIFY devicesChanged) Q_PROPERTY(bool ready READ ready NOTIFY changed) Q_PROPERTY(bool audioEnabled READ audioEnabled NOTIFY changed) Q_PROPERTY(bool takeActive READ takeActive NOTIFY changed) @@ -55,8 +57,10 @@ class Backend : public QObject { QString formatLabel() const { return m_formatLabel; } QVariantList cameras() const { return m_cameras; } QVariantList microphones() const { return m_microphones; } + QVariantList cameraFormats() const { return m_cameraFormats; } int cameraIndex() const; int microphoneIndex() const; + int cameraFormatIndex() const { return m_cameraFormatIndex; } bool ready() const; bool audioEnabled() const { return m_audioId != "none"; } bool takeActive() const { return m_writer != nullptr; } @@ -79,6 +83,7 @@ class Backend : public QObject { Q_INVOKABLE void setPreview(QObject *sink); Q_INVOKABLE void selectCamera(int index); Q_INVOKABLE void selectMicrophone(int index); + Q_INVOKABLE void selectCameraFormat(int index); Q_INVOKABLE void retry(); Q_INVOKABLE void toggleRecording(); Q_INVOKABLE void finish(); @@ -142,6 +147,7 @@ class Backend : public QObject { QAudioFormat m_audioFormat; QVideoFrame m_lastFrame; QCameraFormat m_cameraFormat; + QList m_formatChoices; QElapsedTimer m_wall; QTimer m_tick; QTimer m_finishTimeout; @@ -150,8 +156,9 @@ class Backend : public QObject { bool m_activateHardware; QString m_pendingDestination; Writer *m_writer = nullptr; - QVariantList m_cameras, m_microphones; + QVariantList m_cameras, m_microphones, m_cameraFormats; QString m_cameraId, m_audioId, m_state = "starting", m_message, m_formatLabel; + int m_cameraFormatIndex = -1; QString m_root, m_takeId, m_clipPath, m_clipFileName; QString m_interruption; // Held while a take is in use, so another Monologue never mistakes it for an interrupted one. diff --git a/src/mediautils.cpp b/src/mediautils.cpp index 190212f..b8737d1 100644 --- a/src/mediautils.cpp +++ b/src/mediautils.cpp @@ -9,6 +9,9 @@ #include #include #include +#include +#include +#include double media::targetFps(double minimum, double maximum) { return std::clamp(30.0, minimum, maximum); } int media::bestFormat(const QList &formats) { @@ -35,6 +38,48 @@ QCameraFormat media::bestCameraFormat(const QCameraDevice &device) { const int index = bestFormat(choices); return index < 0 ? QCameraFormat() : formats[index]; } +static QString pixelName(int format) { + switch (format) { + case int(QVideoFrameFormat::Format_Jpeg): return "MJPEG"; + case int(QVideoFrameFormat::Format_YUYV): return "YUYV"; + case int(QVideoFrameFormat::Format_NV12): return "NV12"; + default: { + const auto meta = QMetaEnum::fromType(); + const char *key = meta.valueToKey(format); + QString name = key ? QString::fromLatin1(key) : QString::number(format); + if (name.startsWith("Format_")) name.remove(0, 7); + return name; + }} +} +static QString fpsLabel(double minimum, double maximum) { + const auto digits = [](double v) { return v == int(v) ? 0 : 1; }; + return minimum == maximum + ? QString("%1 fps").arg(maximum, 0, 'f', digits(maximum)) + : QString("%1–%2 fps").arg(minimum, 0, 'f', digits(minimum)).arg(maximum, 0, 'f', digits(maximum)); +} +QString media::formatKey(const QSize &size, double minFps, double maxFps, int pixelFormat) { + return QString("%1x%2:%3-%4:%5") + .arg(size.width()).arg(size.height()) + .arg(minFps, 0, 'f', 2).arg(maxFps, 0, 'f', 2) + .arg(pixelFormat); +} +QString media::formatLabel(const QSize &size, double minFps, double maxFps, int pixelFormat) { + return QString("%1 × %2 · %3 · %4") + .arg(size.width()).arg(size.height()) + .arg(pixelName(pixelFormat)).arg(fpsLabel(minFps, maxFps)); +} +QList media::sortedFormats(const QCameraDevice &device) { + auto formats = device.videoFormats(); + std::sort(formats.begin(), formats.end(), [](const QCameraFormat &a, const QCameraFormat &b) { + const qint64 areaA = qint64(a.resolution().width()) * a.resolution().height(); + const qint64 areaB = qint64(b.resolution().width()) * b.resolution().height(); + if (areaA != areaB) return areaA > areaB; + if (a.maxFrameRate() != b.maxFrameRate()) return a.maxFrameRate() > b.maxFrameRate(); + if (a.minFrameRate() != b.minFrameRate()) return a.minFrameRate() > b.minFrameRate(); + return int(a.pixelFormat()) < int(b.pixelFormat()); + }); + return formats; +} double media::peak(const QByteArray &data, const QAudioFormat &format) { double result = 0; const int bytes = format.bytesPerSample(); diff --git a/src/mediautils.h b/src/mediautils.h index 17645d3..5b5c924 100644 --- a/src/mediautils.h +++ b/src/mediautils.h @@ -12,6 +12,11 @@ struct Format { QSize size; double minFps; double maxFps; int pixelFormat; }; int bestFormat(const QList &formats); QCameraFormat bestCameraFormat(const QCameraDevice &device); double targetFps(double minimum, double maximum); +// Stable identity and display text for one advertised camera format. +QString formatKey(const QSize &size, double minFps, double maxFps, int pixelFormat); +QString formatLabel(const QSize &size, double minFps, double maxFps, int pixelFormat); +// The device's formats, biggest first, so the picker reads naturally. +QList sortedFormats(const QCameraDevice &device); double peak(const QByteArray &data, const QAudioFormat &format); QString copyAtomically(const QString &source, const QString &destination); QString normalizeMp4(const QString &path, double fps); diff --git a/tests/backend_tests.cpp b/tests/backend_tests.cpp index 19745fe..5df7735 100644 --- a/tests/backend_tests.cpp +++ b/tests/backend_tests.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include "mediautils.h" #include "theme.h" @@ -43,6 +44,13 @@ private slots: QCOMPARE(media::bestFormat({}),-1); QCOMPARE(media::targetFps(15,15),15.0); } + void formatKeys() { + QCOMPARE(media::formatLabel({1920,1080},30,30,int(QVideoFrameFormat::Format_Jpeg)),QString("1920 × 1080 · MJPEG · 30 fps")); + QCOMPARE(media::formatLabel({640,480},15,30,int(QVideoFrameFormat::Format_YUYV)),QString("640 × 480 · YUYV · 15–30 fps")); + QVERIFY(media::formatKey({1920,1080},30,30,1)!=media::formatKey({1920,1080},30,60,1)); + QVERIFY(media::formatKey({1920,1080},30,30,1)!=media::formatKey({1920,1080},30,30,2)); + QCOMPARE(media::formatKey({1920,1080},30,30,1),media::formatKey({1920,1080},30,30,1)); + } void clockExcludesPauses() { TakeClock c; c.start(1000000); QVERIFY(!c.position(999999)); diff --git a/tests/ui_tests.cpp b/tests/ui_tests.cpp index 85371be..e590afa 100644 --- a/tests/ui_tests.cpp +++ b/tests/ui_tests.cpp @@ -26,6 +26,8 @@ QtObject { property string message: "" property string formatLabel: "3840 × 2160 · 30 fps recording" property var cameras: [{label: "Test camera"}] + property var cameraFormats: [{label: "1920 × 1080 · MJPEG · 30 fps"}] + property int cameraFormatIndex: 0 property var microphones: [{label: "Test microphone"}] property int cameraIndex: 0 property int microphoneIndex: 0 @@ -63,6 +65,7 @@ QtObject { function toggleRecording() { toggles++; state = state === "ready" || state === "paused" ? "recording" : "paused"; changed() } function finish() { state = "finished"; changed() } function selectCamera(i) {} + function selectCameraFormat(i) {} function selectMicrophone(i) {} function newRecording() { newRecordings++; state = "ready"; changed() } function closeTake() {} From 945354f44a4adf625f8c7b86059a28be19865adf Mon Sep 17 00:00:00 2001 From: Igor Divjak Date: Tue, 20 Oct 2026 10:47:20 +1300 Subject: [PATCH 2/4] Show the target frame rate in the format picker, not the camera's range MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The picker listed each format's full advertised range ("5–30 fps"), which says nothing about the rate the recording will actually use. Show the rate the app requests instead, so a 2 fps mode is obviously the one to avoid and every other row reads as a single rate. Show the selected format itself beside the camera rather than the word "Format". --- src/Main.qml | 6 ++++-- src/mediautils.cpp | 8 ++++---- tests/backend_tests.cpp | 3 ++- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Main.qml b/src/Main.qml index 1b09fcb..6b12a3d 100644 --- a/src/Main.qml +++ b/src/Main.qml @@ -88,7 +88,7 @@ ApplicationWindow { } player.pause(); seekTo(target) } - function space() { if (finished) togglePlayback(); else backend.toggleRecording() } + function space() { if (backend.takeActive || !finished) backend.toggleRecording(); else togglePlayback() } // Leaving the editor deletes the take, so ask first unless it's been saved as it stands. function leaveTake(action) { if (backend.unsaved) { player.pause(); unsavedDialog.action = action; unsavedDialog.open() } @@ -460,8 +460,10 @@ ApplicationWindow { Accessible.name: "Camera" } SourceChoice { - id: formatChoice; textOverride: "Format" + id: formatChoice font.pixelSize: 11 + Layout.maximumWidth: 160 + maximumTextWidth: 130 model: backend.cameraFormats; currentIndex: backend.cameraFormatIndex enabled: !backend.takeActive && !win.busy && backend.cameraFormats.length > 0 delegate: CompactRow { } diff --git a/src/mediautils.cpp b/src/mediautils.cpp index b8737d1..7b062c2 100644 --- a/src/mediautils.cpp +++ b/src/mediautils.cpp @@ -52,10 +52,10 @@ static QString pixelName(int format) { }} } static QString fpsLabel(double minimum, double maximum) { - const auto digits = [](double v) { return v == int(v) ? 0 : 1; }; - return minimum == maximum - ? QString("%1 fps").arg(maximum, 0, 'f', digits(maximum)) - : QString("%1–%2 fps").arg(minimum, 0, 'f', digits(minimum)).arg(maximum, 0, 'f', digits(maximum)); + // The app requests 30 fps clamped to what the format supports, so show that + // rate rather than the camera's full advertised range. + const double rate = media::targetFps(minimum, maximum); + return QString("%1 fps").arg(rate, 0, 'f', rate == int(rate) ? 0 : 1); } QString media::formatKey(const QSize &size, double minFps, double maxFps, int pixelFormat) { return QString("%1x%2:%3-%4:%5") diff --git a/tests/backend_tests.cpp b/tests/backend_tests.cpp index 5df7735..82cba86 100644 --- a/tests/backend_tests.cpp +++ b/tests/backend_tests.cpp @@ -46,7 +46,8 @@ private slots: } void formatKeys() { QCOMPARE(media::formatLabel({1920,1080},30,30,int(QVideoFrameFormat::Format_Jpeg)),QString("1920 × 1080 · MJPEG · 30 fps")); - QCOMPARE(media::formatLabel({640,480},15,30,int(QVideoFrameFormat::Format_YUYV)),QString("640 × 480 · YUYV · 15–30 fps")); + QCOMPARE(media::formatLabel({640,480},15,30,int(QVideoFrameFormat::Format_YUYV)),QString("640 × 480 · YUYV · 30 fps")); + QCOMPARE(media::formatLabel({2560,1472},2,2,int(QVideoFrameFormat::Format_YUYV)),QString("2560 × 1472 · YUYV · 2 fps")); QVERIFY(media::formatKey({1920,1080},30,30,1)!=media::formatKey({1920,1080},30,60,1)); QVERIFY(media::formatKey({1920,1080},30,30,1)!=media::formatKey({1920,1080},30,30,2)); QCOMPARE(media::formatKey({1920,1080},30,30,1),media::formatKey({1920,1080},30,30,1)); From 378f9edc5a2118afeed0d6ec85d2b88dac40d4d4 Mon Sep 17 00:00:00 2001 From: Igor Divjak Date: Tue, 20 Oct 2026 13:34:55 +1300 Subject: [PATCH 3/4] Fall back to the default format when a saved one is no longer offered A saved format that the camera stopped advertising matched nothing, so the picker landed on the first (largest) entry instead of the default pick. Choose the saved format, then the default, then the first, in one small tested function, and remove bestCameraFormat, which the picker made unused. --- src/backend.cpp | 14 +++++++------- src/mediautils.cpp | 15 ++++++++------- src/mediautils.h | 4 +++- tests/backend_tests.cpp | 9 ++++++++- 4 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/backend.cpp b/src/backend.cpp index 25e4ce9..2d2e2c3 100644 --- a/src/backend.cpp +++ b/src/backend.cpp @@ -125,8 +125,11 @@ void Backend::activateSources() { if(selectedCamera.isNull()) { m_state="unavailable"; m_message="Connect a camera or choose an available video source."; } else { m_formatChoices=media::sortedFormats(selectedCamera); - for(const auto &f:m_formatChoices) + QStringList keys; + for(const auto &f:m_formatChoices) { + keys.append(media::formatKey(f.resolution(),f.minFrameRate(),f.maxFrameRate(),int(f.pixelFormat()))); m_cameraFormats.append(QVariantMap{{"label",media::formatLabel(f.resolution(),f.minFrameRate(),f.maxFrameRate(),int(f.pixelFormat()))}}); + } // bestFormat ranks the device's own order, so match its pick by identity // instead of reusing the index against the sorted list. const auto advertised=selectedCamera.videoFormats(); @@ -135,13 +138,10 @@ void Backend::activateSources() { const int best=media::bestFormat(choices); if(best<0) { m_state="unavailable"; m_message="This camera advertises no supported video formats."; } else { - // A format picked for this camera before wins, so a deliberate choice survives restarts. + // A format picked for this camera before wins, so a deliberate choice survives + // restarts; if the camera no longer offers it, fall back to the default pick. const auto bestKey=media::formatKey(advertised[best].resolution(),advertised[best].minFrameRate(),advertised[best].maxFrameRate(),int(advertised[best].pixelFormat())); - int chosen=0; - const auto saved=m_settings.value("cameraFormat/"+m_cameraId).toString(); - const auto wanted=saved.isEmpty()?bestKey:saved; - for(int i=0;i &formats) { } return best; } -QCameraFormat media::bestCameraFormat(const QCameraDevice &device) { - const auto formats = device.videoFormats(); - QList choices; - for (const auto &f : formats) choices.append({f.resolution(), f.minFrameRate(), f.maxFrameRate(), int(f.pixelFormat())}); - const int index = bestFormat(choices); - return index < 0 ? QCameraFormat() : formats[index]; -} static QString pixelName(int format) { switch (format) { case int(QVideoFrameFormat::Format_Jpeg): return "MJPEG"; @@ -68,6 +61,14 @@ QString media::formatLabel(const QSize &size, double minFps, double maxFps, int .arg(size.width()).arg(size.height()) .arg(pixelName(pixelFormat)).arg(fpsLabel(minFps, maxFps)); } +int media::chooseFormat(const QStringList &keys, const QString &saved, const QString &best) { + for (const auto &wanted : {saved, best}) { + if (wanted.isEmpty()) continue; + const int index = keys.indexOf(wanted); + if (index >= 0) return index; + } + return keys.isEmpty() ? -1 : 0; +} QList media::sortedFormats(const QCameraDevice &device) { auto formats = device.videoFormats(); std::sort(formats.begin(), formats.end(), [](const QCameraFormat &a, const QCameraFormat &b) { diff --git a/src/mediautils.h b/src/mediautils.h index 5b5c924..7ac5568 100644 --- a/src/mediautils.h +++ b/src/mediautils.h @@ -10,13 +10,15 @@ namespace media { struct Format { QSize size; double minFps; double maxFps; int pixelFormat; }; int bestFormat(const QList &formats); -QCameraFormat bestCameraFormat(const QCameraDevice &device); double targetFps(double minimum, double maximum); // Stable identity and display text for one advertised camera format. QString formatKey(const QSize &size, double minFps, double maxFps, int pixelFormat); QString formatLabel(const QSize &size, double minFps, double maxFps, int pixelFormat); // The device's formats, biggest first, so the picker reads naturally. QList sortedFormats(const QCameraDevice &device); +// Index into keys of the format to open: the one saved for this camera if it is +// still offered, otherwise the default pick, otherwise the first. -1 if there are none. +int chooseFormat(const QStringList &keys, const QString &saved, const QString &best); double peak(const QByteArray &data, const QAudioFormat &format); QString copyAtomically(const QString &source, const QString &destination); QString normalizeMp4(const QString &path, double fps); diff --git a/tests/backend_tests.cpp b/tests/backend_tests.cpp index 82cba86..39eb4b2 100644 --- a/tests/backend_tests.cpp +++ b/tests/backend_tests.cpp @@ -50,7 +50,14 @@ private slots: QCOMPARE(media::formatLabel({2560,1472},2,2,int(QVideoFrameFormat::Format_YUYV)),QString("2560 × 1472 · YUYV · 2 fps")); QVERIFY(media::formatKey({1920,1080},30,30,1)!=media::formatKey({1920,1080},30,60,1)); QVERIFY(media::formatKey({1920,1080},30,30,1)!=media::formatKey({1920,1080},30,30,2)); - QCOMPARE(media::formatKey({1920,1080},30,30,1),media::formatKey({1920,1080},30,30,1)); + QCOMPARE(media::formatKey({1920,1080},30,30,1),media::formatKey({1920,1080},30,30,1)); } + void formatChoice() { + const QStringList keys{"a","b","c"}; + QCOMPARE(media::chooseFormat(keys,"c","a"),2); // a saved choice wins + QCOMPARE(media::chooseFormat(keys,"","b"),1); // nothing saved: the default + QCOMPARE(media::chooseFormat(keys,"gone","b"),1);// saved format no longer offered: the default, not the first + QCOMPARE(media::chooseFormat(keys,"gone","also gone"),0); + QCOMPARE(media::chooseFormat({},"a","b"),-1); } void clockExcludesPauses() { TakeClock c; c.start(1000000); From df9eaa4bd679a0e0603ee19fe6671b0c50ee5e3c Mon Sep 17 00:00:00 2001 From: Igor Divjak Date: Tue, 20 Oct 2026 13:34:55 +1300 Subject: [PATCH 4/4] Tighten the format control beside the camera Give the camera name its full width back and show the selected format in a small, capped label so the two no longer overlap. Restore the original Space handler: the earlier edit was equivalent, because a take's writer is gone before the editor state is entered. --- src/Main.qml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Main.qml b/src/Main.qml index 6b12a3d..a0af4c0 100644 --- a/src/Main.qml +++ b/src/Main.qml @@ -88,7 +88,7 @@ ApplicationWindow { } player.pause(); seekTo(target) } - function space() { if (backend.takeActive || !finished) backend.toggleRecording(); else togglePlayback() } + function space() { if (finished) togglePlayback(); else backend.toggleRecording() } // Leaving the editor deletes the take, so ask first unless it's been saved as it stands. function leaveTake(action) { if (backend.unsaved) { player.pause(); unsavedDialog.action = action; unsavedDialog.open() } @@ -453,7 +453,7 @@ ApplicationWindow { SourceChoice { id: cameraChoice; iconPath: win.icons.camera; detail: backend.formatLabel Layout.fillWidth: true - maximumTextWidth: Math.min(260, sources.width - 120) + maximumTextWidth: Math.min(260, sources.width - 44) model: backend.cameras; currentIndex: backend.cameraIndex enabled: !backend.takeActive && !win.busy onActivated: index => { backend.selectCamera(index); liveVideo.forceActiveFocus() } @@ -461,9 +461,9 @@ ApplicationWindow { } SourceChoice { id: formatChoice - font.pixelSize: 11 - Layout.maximumWidth: 160 - maximumTextWidth: 130 + font.pixelSize: 9 + Layout.maximumWidth: 90 + maximumTextWidth: 70 model: backend.cameraFormats; currentIndex: backend.cameraFormatIndex enabled: !backend.takeActive && !win.busy && backend.cameraFormats.length > 0 delegate: CompactRow { }