Skip to content
Merged
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
23 changes: 16 additions & 7 deletions apps/desktop/src/utils/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
useQuery,
} from "@tanstack/solid-query";
import { getCurrentWindow } from "@tauri-apps/api/window";
import { createEffect, createMemo, onCleanup } from "solid-js";
import { batch, createEffect, createMemo, onCleanup } from "solid-js";
import { createStore, reconcile } from "solid-js/store";
import { useRecordingOptions } from "~/routes/(window-chrome)/OptionsContext";
import {
Expand Down Expand Up @@ -170,20 +170,29 @@ export function createOptionsQuery() {
if (e.key === PERSIST_KEY) _setState(JSON.parse(e.newValue ?? "{}"));
});

let initialized = false;

recordingSettingsStore.get().then((data) => {
batch(() => {
if (data?.mode && data.mode !== _state.mode) {
_setState("mode", data.mode);
}
initialized = true;
});
});

createEffect(() => {
recordingSettingsStore.set({
const settings = {
target: _state.captureTarget,
micName: _state.micName,
cameraId: _state.cameraID,
mode: _state.mode,
systemAudio: _state.captureSystemAudio,
organizationId: _state.organizationId,
});
});
};

recordingSettingsStore.get().then((data) => {
if (data?.mode && data.mode !== _state.mode) {
_setState("mode", data.mode);
if (initialized) {
recordingSettingsStore.set(settings);
}
});

Expand Down
20 changes: 13 additions & 7 deletions crates/enc-ffmpeg/src/video/h264.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{thread, time::Duration};

use cap_media_info::{Pixel, VideoInfo};
use cap_media_info::{Pixel, VideoInfo, ensure_even};
use ffmpeg::{
Dictionary,
codec::{codec::Codec, context, encoder},
Expand Down Expand Up @@ -90,15 +90,21 @@ impl H264EncoderBuilder {
output: &mut format::context::Output,
) -> Result<H264Encoder, H264EncoderError> {
let input_config = self.input_config;
let (output_width, output_height) = self
let (raw_width, raw_height) = self
.output_size
.unwrap_or((input_config.width, input_config.height));

if output_width == 0 || output_height == 0 {
return Err(H264EncoderError::InvalidOutputDimensions {
width: output_width,
height: output_height,
});
let output_width = ensure_even(raw_width);
let output_height = ensure_even(raw_height);

if raw_width != output_width || raw_height != output_height {
warn!(
raw_width,
raw_height,
output_width,
output_height,
"Auto-adjusted odd dimensions to even for H264 encoding"
);
}

let candidates = get_codec_and_options(&input_config, self.preset);
Expand Down
22 changes: 14 additions & 8 deletions crates/enc-ffmpeg/src/video/hevc.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{thread, time::Duration};

use cap_media_info::{Pixel, VideoInfo};
use cap_media_info::{Pixel, VideoInfo, ensure_even};
use ffmpeg::{
Dictionary,
codec::{codec::Codec, context, encoder},
Expand All @@ -9,7 +9,7 @@ use ffmpeg::{
frame,
threading::Config,
};
use tracing::{debug, error, trace};
use tracing::{debug, error, trace, warn};

use crate::base::EncoderBase;

Expand Down Expand Up @@ -89,15 +89,21 @@ impl HevcEncoderBuilder {
output: &mut format::context::Output,
) -> Result<HevcEncoder, HevcEncoderError> {
let input_config = self.input_config;
let (output_width, output_height) = self
let (raw_width, raw_height) = self
.output_size
.unwrap_or((input_config.width, input_config.height));

if output_width == 0 || output_height == 0 {
return Err(HevcEncoderError::InvalidOutputDimensions {
width: output_width,
height: output_height,
});
let output_width = ensure_even(raw_width);
let output_height = ensure_even(raw_height);

if raw_width != output_width || raw_height != output_height {
warn!(
raw_width,
raw_height,
output_width,
output_height,
"Auto-adjusted odd dimensions to even for HEVC encoding"
);
}

let candidates = get_codec_and_options(&input_config, self.preset);
Expand Down
5 changes: 5 additions & 0 deletions crates/media-info/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,11 @@ impl VideoInfo {
}
}

pub fn ensure_even(value: u32) -> u32 {
let adjusted = value - (value % 2);
if adjusted == 0 { 2 } else { adjusted }
}

pub fn ffmpeg_sample_format_for(sample_format: SampleFormat) -> Option<Sample> {
match sample_format {
SampleFormat::U8 => Some(Sample::U8(Type::Planar)),
Expand Down
13 changes: 7 additions & 6 deletions crates/recording/src/instant_recording.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::{
},
feeds::microphone::MicrophoneFeedLock,
output_pipeline::{self, OutputPipeline},
resolution_limits::ensure_even,
sources::screen_capture::{ScreenCaptureConfig, ScreenCaptureTarget},
};
use anyhow::Context as _;
Expand Down Expand Up @@ -227,7 +228,12 @@ async fn create_pipeline(
),
)
})
.unwrap_or((screen_info.width, screen_info.height));
.unwrap_or_else(|| {
(
ensure_even(screen_info.width),
ensure_even(screen_info.height),
)
});

let (screen_capture, system_audio) = screen_source.to_sources().await?;

Expand Down Expand Up @@ -413,11 +419,6 @@ fn current_time_f64() -> f64 {
.as_secs_f64()
}

fn ensure_even(value: u32) -> u32 {
let adjusted = value - (value % 2);
if adjusted == 0 { 2 } else { adjusted }
}

fn clamp_size(input: (u32, u32), max: (u32, u32)) -> (u32, u32) {
// 16/9-ish
if input.0 >= input.1 && (input.0 as f64 / input.1 as f64) <= 16.0 / 9.0 {
Expand Down
Loading