Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
coderabbit bits
Richie McIlroyd7edd423c045
diff --git a/.claude/settings.local.json b/.claude/settings.local.jsonindex f2037c92c..f0e207bf2 100644--- a/.claude/settings.local.json+++ b/.claude/settings.local.json@@ -52,7 +52,9 @@"Bash(RUST_LOG=info,cap_recording=debug ./target/release/examples/memory-leak-detector:*)","Bash(git rm:*)","Bash(./target/release/examples/decode-benchmark:*)",- "Bash(RUST_LOG=warn ./target/release/examples/decode-benchmark:*)"+ "Bash(RUST_LOG=warn ./target/release/examples/decode-benchmark:*)",+ "Bash(git mv:*)",+ "Bash(xargs cat:*)"],"deny": [],"ask": []diff --git a/apps/desktop/src-tauri/src/lib.rs b/apps/desktop/src-tauri/src/lib.rsindex b27e255f8..2bc1daa89 100644--- a/apps/desktop/src-tauri/src/lib.rs+++ b/apps/desktop/src-tauri/src/lib.rs@@ -3225,15 +3225,15 @@ async fn wait_for_recording_ready(app: &AppHandle, path: &Path) -> Result<(), St}};- if let Some(studio_meta) = meta.studio_meta() {- if recording::needs_fragment_remux(path, studio_meta) {- info!("Recording needs remux (crash recovery), starting remux...");- let path = path.to_path_buf();- tokio::task::spawn_blocking(move || recording::remux_fragmented_recording(&path))- .await- .map_err(|e| format!("Remux task panicked: {e}"))??;- info!("Crash recovery remux completed");- }+ if let Some(studio_meta) = meta.studio_meta()+ && recording::needs_fragment_remux(path, studio_meta)+ {+ info!("Recording needs remux (crash recovery), starting remux...");+ let path = path.to_path_buf();+ tokio::task::spawn_blocking(move || recording::remux_fragmented_recording(&path))+ .await+ .map_err(|e| format!("Remux task panicked: {e}"))??;+ info!("Crash recovery remux completed");}Ok(())diff --git a/apps/desktop/src/routes/editor/Editor.tsx b/apps/desktop/src/routes/editor/Editor.tsxindex adf226071..dd2bba442 100644--- a/apps/desktop/src/routes/editor/Editor.tsx+++ b/apps/desktop/src/routes/editor/Editor.tsx@@ -14,6 +14,7 @@ import {createSignal,Match,on,+ onCleanup,Show,Switch,} from "solid-js";@@ -428,7 +429,7 @@ function Dialogs() {const [crop, setCrop] = createSignal(CROP_ZERO);const [aspect, setAspect] = createSignal<Ratio | null>(null);- const [frameDataUrl, setFrameDataUrl] = createSignal<+ const [frameBlobUrl, setFrameBlobUrl] = createSignal<string | null>(null);@@ -436,13 +437,21 @@ function Dialogs() {"canvas",) as HTMLCanvasElement | null;if (playerCanvas) {- try {- setFrameDataUrl(playerCanvas.toDataURL("image/png"));- } catch {- setFrameDataUrl(null);- }+ playerCanvas.toBlob((blob) => {+ if (blob) {+ const url = URL.createObjectURL(blob);+ setFrameBlobUrl(url);+ }+ }, "image/png");}+ onCleanup(() => {+ const url = frameBlobUrl();+ if (url) {+ URL.revokeObjectURL(url);+ }+ });+const initialBounds = {x: dialog().position.x,y: dialog().position.y,@@ -607,7 +616,7 @@ function Dialogs() {class="shadow pointer-events-none max-h-[70vh]"alt="Current frame"src={- frameDataUrl() ??+ frameBlobUrl() ??convertFileSrc(`${editorInstance.path}/screenshots/display.jpg`,)diff --git a/apps/desktop/src/routes/editor/ExportPage.tsx b/apps/desktop/src/routes/editor/ExportPage.tsxindex f77f46ce5..b08240a81 100644--- a/apps/desktop/src/routes/editor/ExportPage.tsx+++ b/apps/desktop/src/routes/editor/ExportPage.tsx@@ -56,11 +56,11 @@ export const COMPRESSION_OPTIONS: Array<{{ label: "Potato", value: "Potato", bpp: 0.04 },];-const BPP_TO_COMPRESSION: Record<number, ExportCompression> = {- 0.3: "Minimal",- 0.15: "Social",- 0.08: "Web",- 0.04: "Potato",+const BPP_TO_COMPRESSION: Record<string, ExportCompression> = {+ "0.3": "Minimal",+ "0.15": "Social",+ "0.08": "Web",+ "0.04": "Potato",};const COMPRESSION_TO_BPP: Record<ExportCompression, number> = {@@ -286,10 +286,10 @@ export function ExportPage() {createEffect(on([- () => _settings.format,- () => _settings.fps,- () => _settings.resolution.width,- () => _settings.resolution.height,+ () => settings.format,+ () => settings.fps,+ () => settings.resolution.width,+ () => settings.resolution.height,compressionBpp,],() => {@@ -918,11 +918,7 @@ export function ExportPage() {<div class="flex gap-2"><Foreach={- settings.format === "Gif"- ? GIF_FPS_OPTIONS.filter((o) =>- [10, 15, 20, 30].includes(o.value),- )- : FPS_OPTIONS+ settings.format === "Gif" ? GIF_FPS_OPTIONS : FPS_OPTIONS}>{(option) => (@@ -1301,35 +1297,39 @@ export function ExportPage() {exportState.type === "done"}>- <div class="relative">- <a- href={meta().sharing?.link}- target="_blank"- rel="noreferrer"- class="block"- >- <Button- onClick={() => {- setCopyPressed(true);- setTimeout(() => {- setCopyPressed(false);- }, 2000);- navigator.clipboard.writeText(- meta().sharing?.link!,- );- }}- variant="dark"- class="flex gap-2 justify-center items-center"- >- {!copyPressed() ? (- <IconCapCopy class="transition-colors duration-200 text-gray-1 size-4 group-hover:text-gray-12" />- ) : (- <IconLucideCheck class="transition-colors duration-200 text-gray-1 size-4 svgpathanimation group-hover:text-gray-12" />- )}- <p>Open Link</p>- </Button>- </a>- </div>+ <Show when={meta().sharing?.link}>+ {(link) => (+ <div class="flex gap-2">+ <Button+ onClick={() => {+ setCopyPressed(true);+ setTimeout(() => {+ setCopyPressed(false);+ }, 2000);+ navigator.clipboard.writeText(link());+ }}+ variant="dark"+ class="flex gap-2 justify-center items-center"+ >+ {!copyPressed() ? (+ <IconCapCopy class="transition-colors duration-200 text-gray-1 size-4 group-hover:text-gray-12" />+ ) : (+ <IconLucideCheck class="transition-colors duration-200 text-gray-1 size-4 svgpathanimation group-hover:text-gray-12" />+ )}+ <p>Copy Link</p>+ </Button>+ <a href={link()} target="_blank" rel="noreferrer">+ <Button+ variant="dark"+ class="flex gap-2 justify-center items-center"+ >+ <IconCapLink class="transition-colors duration-200 text-gray-1 size-4 group-hover:text-gray-12" />+ <p>Open Link</p>+ </Button>+ </a>+ </div>+ )}+ </Show></Show><Showdiff --git a/apps/desktop/src/routes/editor/EditorSkeleton.tsx b/apps/desktop/src/routes/editor/editor-skeleton.tsxsimilarity index 100%rename from apps/desktop/src/routes/editor/EditorSkeleton.tsxrename to apps/desktop/src/routes/editor/editor-skeleton.tsxdiff --git a/apps/desktop/src/routes/editor/index.tsx b/apps/desktop/src/routes/editor/index.tsxindex ecfb44763..ca0bfdf6f 100644--- a/apps/desktop/src/routes/editor/index.tsx+++ b/apps/desktop/src/routes/editor/index.tsx@@ -5,7 +5,7 @@ import { createEffect, Suspense } from "solid-js";import { generalSettingsStore } from "~/store";import { commands } from "~/utils/tauri";import { Editor } from "./Editor";-import { EditorSkeleton } from "./EditorSkeleton";+import { EditorSkeleton } from "./editor-skeleton";export default function () {const generalSettings = generalSettingsStore.createQuery();diff --git a/crates/editor/examples/decode-benchmark.rs b/crates/editor/examples/decode-benchmark.rsindex a42a3f9a6..c71c18b6b 100644--- a/crates/editor/examples/decode-benchmark.rs+++ b/crates/editor/examples/decode-benchmark.rs@@ -124,12 +124,12 @@ impl BenchmarkResults {let min = self.random_access_times_ms.iter()- .cloned()+ .copied().fold(f64::INFINITY, f64::min);let max = self.random_access_times_ms.iter()- .cloned()+ .copied().fold(f64::NEG_INFINITY, f64::max);println!(" Samples: {}", self.random_access_times_ms.len());if self.random_access_failures > 0 {diff --git a/crates/editor/src/playback.rs b/crates/editor/src/playback.rsindex a5ddeab9c..4096abfb1 100644--- a/crates/editor/src/playback.rs+++ b/crates/editor/src/playback.rs@@ -631,7 +631,12 @@ impl Playback {frame_number = frame_number.saturating_add(1);let _ = playback_position_tx.send(frame_number);- let _ = audio_playhead_tx.send(frame_number as f64 / fps_f64);+ if audio_playhead_tx+ .send(frame_number as f64 / fps_f64)+ .is_err()+ {+ break 'playback;+ }let expected_frame = self.start_frame_number+ (start.elapsed().as_secs_f64() * fps_f64).floor() as u32;@@ -651,7 +656,12 @@ impl Playback {prefetch_buffer.retain(|p| p.frame_number >= frame_number);let _ = frame_request_tx.send(frame_number);let _ = playback_position_tx.send(frame_number);- let _ = audio_playhead_tx.send(frame_number as f64 / fps_f64);+ if audio_playhead_tx+ .send(frame_number as f64 / fps_f64)+ .is_err()+ {+ break 'playback;+ }}}}diff --git a/crates/recording/src/output_pipeline/core.rs b/crates/recording/src/output_pipeline/core.rsindex 13aca3ce2..d4f5f6204 100644--- a/crates/recording/src/output_pipeline/core.rs+++ b/crates/recording/src/output_pipeline/core.rs@@ -553,12 +553,13 @@ fn spawn_video_encoder<TMutex: VideoMuxer<VideoFrame = TVideo::Frame>, TVideo: Vlet mut drained = 0u64;let mut skipped = 0u64;+ let mut hit_limit = false;while let Some(frame) = video_rx.next().await {frame_count += 1;if drain_start.elapsed() > drain_timeout || drained >= max_drain_frames {- skipped += 1;- continue;+ hit_limit = true;+ break;}drained += 1;@@ -581,11 +582,13 @@ fn spawn_video_encoder<TMutex: VideoMuxer<VideoFrame = TVideo::Frame>, TVideo: V}}}- if drained > 0 || skipped > 0 {++ if drained > 0 || skipped > 0 || hit_limit {info!(- "mux-video drain complete: {} frames processed, {} skipped in {:?}",+ "mux-video drain complete: {} frames processed, {} errors (limit hit: {}) in {:?}",drained,skipped,+ hit_limit,drain_start.elapsed());}diff --git a/crates/rendering/src/decoder/avassetreader.rs b/crates/rendering/src/decoder/avassetreader.rsindex 8acf438ac..abd8d6f80 100644--- a/crates/rendering/src/decoder/avassetreader.rs+++ b/crates/rendering/src/decoder/avassetreader.rs@@ -21,22 +21,11 @@ use super::frame_converter::{copy_bgra_to_rgba, copy_rgba_plane};use super::multi_position::{DecoderPoolManager, MultiPositionDecoderConfig, ScrubDetector};use super::{DecoderInitResult, DecoderType, FRAME_CACHE_SIZE, VideoDecoderMessage, pts_to_frame};-struct SendableImageBuf(R<cv::ImageBuf>);-unsafe impl Send for SendableImageBuf {}-unsafe impl Sync for SendableImageBuf {}--impl Clone for SendableImageBuf {- fn clone(&self) -> Self {- Self(self.0.retained())- }-}-#[derive(Clone)]struct FrameData {data: Arc<Vec<u8>>,y_stride: u32,uv_stride: u32,- image_buf: Option<Arc<SendableImageBuf>>,}#[derive(Clone)]@@ -54,32 +43,19 @@ impl ProcessedFrame {data,y_stride,uv_stride,- image_buf,} = &self.frame_data;match self.format {PixelFormat::Rgba => {DecodedFrame::new_with_arc(Arc::clone(data), self.width, self.height)}- PixelFormat::Nv12 => {- if let Some(img_buf) = image_buf {- DecodedFrame::new_nv12_zero_copy(- self.width,- self.height,- *y_stride,- *uv_stride,- img_buf.0.retained(),- )- } else {- DecodedFrame::new_nv12_with_arc(- Arc::clone(data),- self.width,- self.height,- *y_stride,- *uv_stride,- )- }- }+ PixelFormat::Nv12 => DecodedFrame::new_nv12_with_arc(+ Arc::clone(data),+ self.width,+ self.height,+ *y_stride,+ *uv_stride,+ ),PixelFormat::Yuv420p => DecodedFrame::new_yuv420p_with_arc(Arc::clone(data),self.width,@@ -233,21 +209,14 @@ impl CachedFrame {let pixel_format =cap_video_decode::avassetreader::pixel_format_to_pixel(image_buf.pixel_format());- let (format, y_stride, uv_stride, stored_image_buf) = match pixel_format {- format::Pixel::NV12 => {- let y_stride = image_buf.plane_bytes_per_row(0) as u32;- let uv_stride = image_buf.plane_bytes_per_row(1) as u32;- (- PixelFormat::Nv12,- y_stride,- uv_stride,- Some(Arc::new(SendableImageBuf(image_buf))),- )- }- format::Pixel::RGBA | format::Pixel::BGRA | format::Pixel::YUV420P => {+ match pixel_format {+ format::Pixel::NV12+ | format::Pixel::RGBA+ | format::Pixel::BGRA+ | format::Pixel::YUV420P => {let mut img = image_buf;let (data, fmt, y_str, uv_str) = processor.extract_raw(&mut img);- return Self(ProcessedFrame {+ Self(ProcessedFrame {_number: number,width,height,@@ -256,13 +225,12 @@ impl CachedFrame {data: Arc::new(data),y_stride: y_str,uv_stride: uv_str,- image_buf: None,},- });+ })}_ => {let black_frame = vec![0u8; (width * height * 4) as usize];- return Self(ProcessedFrame {+ Self(ProcessedFrame {_number: number,width,height,@@ -271,25 +239,10 @@ impl CachedFrame {data: Arc::new(black_frame),y_stride: width * 4,uv_stride: 0,- image_buf: None,},- });+ })}- };-- let frame = ProcessedFrame {- _number: number,- width,- height,- format,- frame_data: FrameData {- data: Arc::new(Vec::new()),- y_stride,- uv_stride,- image_buf: stored_image_buf,- },- };- Self(frame)+ }}fn data(&self) -> &ProcessedFrame {@@ -523,18 +476,21 @@ impl AVAssetReaderDecoder {false};- let mut i = 0;- while i < pending_requests.len() {- let request = &pending_requests[i];+ let mut unfulfilled = Vec::with_capacity(pending_requests.len());+ let mut last_sent_data = None;+ for request in pending_requests.drain(..) {if let Some(cached) = cache.get(&request.frame) {let data = cached.data().clone();- let req = pending_requests.remove(i);- let _ = req.sender.send(data.to_decoded_frame());- *last_sent_frame.borrow_mut() = Some(data);+ let _ = request.sender.send(data.to_decoded_frame());+ last_sent_data = Some(data);} else {- i += 1;+ unfulfilled.push(request);}}+ if let Some(data) = last_sent_data {+ *last_sent_frame.borrow_mut() = Some(data);+ }+ pending_requests = unfulfilled;if pending_requests.is_empty() {continue;diff --git a/crates/rendering/src/decoder/mod.rs b/crates/rendering/src/decoder/mod.rsindex f02800b2d..81b92997a 100644--- a/crates/rendering/src/decoder/mod.rs+++ b/crates/rendering/src/decoder/mod.rs@@ -70,31 +70,9 @@ pub struct DecoderInitResult {pub decoder_type: DecoderType,}-#[cfg(target_os = "macos")]-use cidre::{arc::R, cv};-#[cfg(target_os = "windows")]use windows::Win32::{Foundation::HANDLE, Graphics::Direct3D11::ID3D11Texture2D};-#[cfg(target_os = "macos")]-pub struct SendableImageBuf(R<cv::ImageBuf>);--#[cfg(target_os = "macos")]-unsafe impl Send for SendableImageBuf {}-#[cfg(target_os = "macos")]-unsafe impl Sync for SendableImageBuf {}--#[cfg(target_os = "macos")]-impl SendableImageBuf {- pub fn new(image_buf: R<cv::ImageBuf>) -> Self {- Self(image_buf)- }-- pub fn inner(&self) -> &cv::ImageBuf {- &self.0- }-}-#[cfg(target_os = "windows")]pub struct SendableD3D11Texture {texture: ID3D11Texture2D,@@ -174,8 +152,6 @@ pub struct DecodedFrame {format: PixelFormat,y_stride: u32,uv_stride: u32,- #[cfg(target_os = "macos")]- iosurface_backing: Option<Arc<SendableImageBuf>>,#[cfg(target_os = "windows")]d3d11_texture_backing: Option<Arc<SendableD3D11Texture>>,}@@ -202,8 +178,6 @@ impl DecodedFrame {format: PixelFormat::Rgba,y_stride: width * 4,uv_stride: 0,- #[cfg(target_os = "macos")]- iosurface_backing: None,#[cfg(target_os = "windows")]d3d11_texture_backing: None,}@@ -217,8 +191,6 @@ impl DecodedFrame {format: PixelFormat::Rgba,y_stride: width * 4,uv_stride: 0,- #[cfg(target_os = "macos")]- iosurface_backing: None,#[cfg(target_os = "windows")]d3d11_texture_backing: None,}@@ -232,8 +204,6 @@ impl DecodedFrame {format: PixelFormat::Nv12,y_stride,uv_stride,- #[cfg(target_os = "macos")]- iosurface_backing: None,#[cfg(target_os = "windows")]d3d11_texture_backing: None,}@@ -253,8 +223,6 @@ impl DecodedFrame {format: PixelFormat::Nv12,y_stride,uv_stride,- #[cfg(target_os = "macos")]- iosurface_backing: None,#[cfg(target_os = "windows")]d3d11_texture_backing: None,}@@ -274,8 +242,6 @@ impl DecodedFrame {format: PixelFormat::Yuv420p,y_stride,uv_stride,- #[cfg(target_os = "macos")]- iosurface_backing: None,#[cfg(target_os = "windows")]d3d11_texture_backing: None,}@@ -295,78 +261,11 @@ impl DecodedFrame {format: PixelFormat::Yuv420p,y_stride,uv_stride,- #[cfg(target_os = "macos")]- iosurface_backing: None,#[cfg(target_os = "windows")]d3d11_texture_backing: None,}}- #[cfg(target_os = "macos")]- pub fn new_nv12_with_iosurface(- data: Vec<u8>,- width: u32,- height: u32,- y_stride: u32,- uv_stride: u32,- image_buf: R<cv::ImageBuf>,- ) -> Self {- Self {- data: Arc::new(data),- width,- height,- format: PixelFormat::Nv12,- y_stride,- uv_stride,- iosurface_backing: Some(Arc::new(SendableImageBuf::new(image_buf))),- }- }-- #[cfg(target_os = "macos")]- pub fn new_nv12_with_iosurface_arc(- data: Arc<Vec<u8>>,- width: u32,- height: u32,- y_stride: u32,- uv_stride: u32,- image_buf: R<cv::ImageBuf>,- ) -> Self {- Self {- data,- width,- height,- format: PixelFormat::Nv12,- y_stride,- uv_stride,- iosurface_backing: Some(Arc::new(SendableImageBuf::new(image_buf))),- }- }-- #[cfg(target_os = "macos")]- pub fn new_nv12_zero_copy(- width: u32,- height: u32,- y_stride: u32,- uv_stride: u32,- image_buf: R<cv::ImageBuf>,- ) -> Self {- Self {- data: Arc::new(Vec::new()),- width,- height,- format: PixelFormat::Nv12,- y_stride,- uv_stride,- iosurface_backing: Some(Arc::new(SendableImageBuf::new(image_buf))),- }- }-- #[cfg(target_os = "macos")]- #[allow(clippy::redundant_closure)]- pub fn iosurface_backing(&self) -> Option<&cv::ImageBuf> {- self.iosurface_backing.as_ref().map(|b| b.inner())- }-#[cfg(target_os = "windows")]pub fn new_nv12_with_d3d11_texture(width: u32, height: u32, texture: ID3D11Texture2D) -> Self {Self {diff --git a/crates/rendering/src/layers/camera.rs b/crates/rendering/src/layers/camera.rsindex c4c5dc741..a0c1d85c3 100644--- a/crates/rendering/src/layers/camera.rs+++ b/crates/rendering/src/layers/camera.rs@@ -130,35 +130,6 @@ impl CameraLayer {);}PixelFormat::Nv12 => {- #[cfg(target_os = "macos")]- let iosurface_result = camera_frame.iosurface_backing().map(|image_buf| {- self.yuv_converter- .convert_nv12_from_iosurface(device, queue, image_buf)- });-- #[cfg(target_os = "macos")]- if let Some(Ok(_)) = iosurface_result {- self.copy_from_yuv_output(device, queue, next_texture, frame_size);- } else if let (Some(y_data), Some(uv_data)) =- (camera_frame.y_plane(), camera_frame.uv_plane())- && self- .yuv_converter- .convert_nv12(- device,- queue,- y_data,- uv_data,- frame_size.x,- frame_size.y,- camera_frame.y_stride(),- camera_frame.uv_stride(),- )- .is_ok()- {- self.copy_from_yuv_output(device, queue, next_texture, frame_size);- }-- #[cfg(not(target_os = "macos"))]if let (Some(y_data), Some(uv_data)) =(camera_frame.y_plane(), camera_frame.uv_plane())&& selfdiff --git a/crates/rendering/src/layers/display.rs b/crates/rendering/src/layers/display.rsindex bf797a9b9..c799f8dfa 100644--- a/crates/rendering/src/layers/display.rs+++ b/crates/rendering/src/layers/display.rs@@ -134,26 +134,9 @@ impl DisplayLayer {PixelFormat::Nv12 => {let screen_frame = &segment_frames.screen_frame;- #[cfg(target_os = "macos")]- let iosurface_result = screen_frame.iosurface_backing().map(|image_buf| {- self.yuv_converter- .convert_nv12_from_iosurface(device, queue, image_buf)- });-#[cfg(target_os = "macos")]if !self.prefer_cpu_conversion {- if let Some(Ok(_)) = iosurface_result {- if self.yuv_converter.output_texture().is_some() {- self.pending_copy = Some(PendingTextureCopy {- width: frame_size.x,- height: frame_size.y,- dst_texture_index: next_texture,- });- true- } else {- false- }- } else if let (Some(y_data), Some(uv_data)) =+ if let (Some(y_data), Some(uv_data)) =(screen_frame.y_plane(), screen_frame.uv_plane()){let y_stride = screen_frame.y_stride();diff --git a/crates/video-decode/src/avassetreader.rs b/crates/video-decode/src/avassetreader.rsindex 17ddf6f95..189d60e01 100644--- a/crates/video-decode/src/avassetreader.rs+++ b/crates/video-decode/src/avassetreader.rs@@ -1,4 +1,4 @@-use std::path::PathBuf;+use std::path::{Path, PathBuf};use cidre::{arc::{self, R},@@ -17,7 +17,7 @@ pub struct KeyframeIndex {}impl KeyframeIndex {- pub fn build(path: &PathBuf) -> Result<Self, String> {+ pub fn build(path: &Path) -> Result<Self, String> {let build_start = std::time::Instant::now();let input = avformat::input(path)@@ -165,6 +165,17 @@ impl KeyframeIndex {}}+fn compute_seek_time(keyframe_index: Option<&KeyframeIndex>, requested_time: f32) -> f32 {+ if let Some(kf_index) = keyframe_index {+ let fps = kf_index.fps();+ let target_frame = (requested_time as f64 * fps).round() as u32;+ if let Some((_, keyframe_time)) = kf_index.nearest_keyframe_before(target_frame) {+ return keyframe_time as f32;+ }+ }+ requested_time+}+pub struct AVAssetReaderDecoder {path: PathBuf,pixel_format: cv::PixelFormat,@@ -230,17 +241,7 @@ impl AVAssetReaderDecoder {)};- let seek_time = if let Some(ref kf_index) = keyframe_index {- let fps = kf_index.fps();- let target_frame = (start_time as f64 * fps).round() as u32;- if let Some((_, keyframe_time)) = kf_index.nearest_keyframe_before(target_frame) {- keyframe_time as f32- } else {- start_time- }- } else {- start_time- };+ let seek_time = compute_seek_time(keyframe_index.as_ref(), start_time);let (track_output, reader) = Self::get_reader_track_output(&path,@@ -267,18 +268,7 @@ impl AVAssetReaderDecoder {pub fn reset(&mut self, requested_time: f32) -> Result<(), String> {self.reader.cancel_reading();- let seek_time = if let Some(ref keyframe_index) = self.keyframe_index {- let fps = keyframe_index.fps();- let target_frame = (requested_time as f64 * fps).round() as u32;-- if let Some((_, keyframe_time)) = keyframe_index.nearest_keyframe_before(target_frame) {- keyframe_time as f32- } else {- requested_time- }- } else {- requested_time- };+ let seek_time = compute_seek_time(self.keyframe_index.as_ref(), requested_time);(self.track_output, self.reader) = Self::get_reader_track_output(&self.path,@@ -319,7 +309,7 @@ impl AVAssetReaderDecoder {}fn get_reader_track_output(- path: &PathBuf,+ path: &Path,time: f32,handle: &TokioHandle,pixel_format: cv::PixelFormat,