fix pts_scale: use capture fps (not declared 120) for timestamp correction
This commit is contained in:
@@ -327,7 +327,7 @@ impl CaptureSession {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Re-encode the intermediate file with correct timestamps.
|
/// Re-encode the intermediate file with correct timestamps.
|
||||||
/// The capture declares -framerate 120 but delivers at a lower rate.
|
/// The capture declares -framerate N and applies fps=M filter.
|
||||||
/// This scales PTS to match real-time duration.
|
/// This scales PTS to match real-time duration.
|
||||||
pub fn fix_intermediate_fps(
|
pub fn fix_intermediate_fps(
|
||||||
ffmpeg: &std::path::Path,
|
ffmpeg: &std::path::Path,
|
||||||
@@ -335,6 +335,7 @@ pub fn fix_intermediate_fps(
|
|||||||
output: &std::path::Path,
|
output: &std::path::Path,
|
||||||
elapsed_secs: f64,
|
elapsed_secs: f64,
|
||||||
frame_count: u64,
|
frame_count: u64,
|
||||||
|
capture_fps: u32,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
@@ -344,11 +345,10 @@ pub fn fix_intermediate_fps(
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
let declared_fps = 120.0f64;
|
|
||||||
let actual_fps = frame_count as f64 / elapsed_secs;
|
let actual_fps = frame_count as f64 / elapsed_secs;
|
||||||
let pts_scale = declared_fps / actual_fps;
|
let pts_scale = capture_fps as f64 / actual_fps;
|
||||||
tracing::info!(
|
tracing::info!(
|
||||||
"capture fix: {frame_count} frames in {elapsed_secs:.1}s = {actual_fps:.1}fps, pts_scale={pts_scale:.2}"
|
"capture fix: {frame_count} frames in {elapsed_secs:.1}s = {actual_fps:.1}fps (declared {capture_fps}), pts_scale={pts_scale:.2}"
|
||||||
);
|
);
|
||||||
|
|
||||||
// Re-encode with scaled PTS to fix timing
|
// Re-encode with scaled PTS to fix timing
|
||||||
|
|||||||
@@ -435,8 +435,9 @@ fn pause_capture(state: State<'_, AppState>) -> Result<(), String> {
|
|||||||
let frames = session.frame_counter.load(std::sync::atomic::Ordering::Relaxed);
|
let frames = session.frame_counter.load(std::sync::atomic::Ordering::Relaxed);
|
||||||
let raw_path = session.stop().map_err(|e| format!("{e:#}"))?;
|
let raw_path = session.stop().map_err(|e| format!("{e:#}"))?;
|
||||||
let ffmpeg = bootstrap::ffmpeg_path(&state.app_dir);
|
let ffmpeg = bootstrap::ffmpeg_path(&state.app_dir);
|
||||||
|
let cap_fps = lock(&state.config).capture.default_fps;
|
||||||
let fixed_path = raw_path.with_extension("fixed.mp4");
|
let fixed_path = raw_path.with_extension("fixed.mp4");
|
||||||
capture::fix_intermediate_fps(&ffmpeg, &raw_path, &fixed_path, elapsed, frames)
|
capture::fix_intermediate_fps(&ffmpeg, &raw_path, &fixed_path, elapsed, frames, cap_fps)
|
||||||
.map_err(|e| format!("fixing fps: {e:#}"))?;
|
.map_err(|e| format!("fixing fps: {e:#}"))?;
|
||||||
let path = if fixed_path.exists() { fixed_path } else { raw_path };
|
let path = if fixed_path.exists() { fixed_path } else { raw_path };
|
||||||
|
|
||||||
@@ -523,8 +524,9 @@ fn stop_capture(app: AppHandle, state: State<'_, AppState>) -> Result<RecordedCl
|
|||||||
let frames = session.frame_counter.load(std::sync::atomic::Ordering::Relaxed);
|
let frames = session.frame_counter.load(std::sync::atomic::Ordering::Relaxed);
|
||||||
let raw_path = session.stop().map_err(|e| format!("{e:#}"))?;
|
let raw_path = session.stop().map_err(|e| format!("{e:#}"))?;
|
||||||
let ffmpeg = bootstrap::ffmpeg_path(&state.app_dir);
|
let ffmpeg = bootstrap::ffmpeg_path(&state.app_dir);
|
||||||
|
let cap_fps = lock(&state.config).capture.default_fps;
|
||||||
let fixed_path = raw_path.with_extension("fixed.mp4");
|
let fixed_path = raw_path.with_extension("fixed.mp4");
|
||||||
capture::fix_intermediate_fps(&ffmpeg, &raw_path, &fixed_path, elapsed, frames)
|
capture::fix_intermediate_fps(&ffmpeg, &raw_path, &fixed_path, elapsed, frames, cap_fps)
|
||||||
.map_err(|e| format!("fixing fps: {e:#}"))?;
|
.map_err(|e| format!("fixing fps: {e:#}"))?;
|
||||||
let final_path = if fixed_path.exists() { fixed_path } else { raw_path };
|
let final_path = if fixed_path.exists() { fixed_path } else { raw_path };
|
||||||
ss.segments.push(final_path);
|
ss.segments.push(final_path);
|
||||||
|
|||||||
Reference in New Issue
Block a user