Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
78 changes: 67 additions & 11 deletions src/Main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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 }
Expand All @@ -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
Expand Down Expand Up @@ -410,13 +448,31 @@ 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 - 44)
model: backend.cameras; currentIndex: backend.cameraIndex
enabled: !backend.takeActive && !win.busy
onActivated: index => { backend.selectCamera(index); liveVideo.forceActiveFocus() }
Accessible.name: "Camera"
}
SourceChoice {
id: formatChoice
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 { }
// 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
Expand Down
34 changes: 29 additions & 5 deletions src/backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
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();
QList<media::Format> 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; 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()));
const int chosen=media::chooseFormat(keys,m_settings.value("cameraFormat/"+m_cameraId).toString(),bestKey);
m_cameraFormatIndex=chosen;
m_cameraFormat=m_formatChoices[chosen];
m_fps=media::targetFps(m_cameraFormat.minFrameRate(),m_cameraFormat.maxFrameRate());
m_formatLabel=QString("%1 × %2 · up to %3 fps").arg(m_cameraFormat.resolution().width()).arg(m_cameraFormat.resolution().height()).arg(m_fps,0,'f',m_fps==int(m_fps)?0:2);
m_formatLabel=media::formatLabel(m_cameraFormat.resolution(),m_cameraFormat.minFrameRate(),m_cameraFormat.maxFrameRate(),int(m_cameraFormat.pixelFormat()));
m_camera=new QCamera(selectedCamera,this);
m_camera->setCameraFormat(m_cameraFormat);
m_capture.setCamera(m_camera);
Expand All @@ -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() {
Expand All @@ -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.
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 8 additions & 1 deletion src/backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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; }
Expand All @@ -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();
Expand Down Expand Up @@ -142,6 +147,7 @@ class Backend : public QObject {
QAudioFormat m_audioFormat;
QVideoFrame m_lastFrame;
QCameraFormat m_cameraFormat;
QList<QCameraFormat> m_formatChoices;
QElapsedTimer m_wall;
QTimer m_tick;
QTimer m_finishTimeout;
Expand All @@ -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.
Expand Down
58 changes: 52 additions & 6 deletions src/mediautils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#include <cstring>
#include <limits>
#include <cstdio>
#include <algorithm>
#include <QMetaEnum>
#include <QVideoFrameFormat>

double media::targetFps(double minimum, double maximum) { return std::clamp(30.0, minimum, maximum); }
int media::bestFormat(const QList<Format> &formats) {
Expand All @@ -28,12 +31,55 @@ int media::bestFormat(const QList<Format> &formats) {
}
return best;
}
QCameraFormat media::bestCameraFormat(const QCameraDevice &device) {
const auto formats = device.videoFormats();
QList<Format> 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";
case int(QVideoFrameFormat::Format_YUYV): return "YUYV";
case int(QVideoFrameFormat::Format_NV12): return "NV12";
default: {
const auto meta = QMetaEnum::fromType<QVideoFrameFormat::PixelFormat>();
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) {
// 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")
.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));
}
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<QCameraFormat> 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;
Expand Down
9 changes: 8 additions & 1 deletion src/mediautils.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,15 @@
namespace media {
struct Format { QSize size; double minFps; double maxFps; int pixelFormat; };
int bestFormat(const QList<Format> &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<QCameraFormat> 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);
Expand Down
Loading