Change archive --sync-start defaults

This commit is contained in:
bytedream 2024-04-09 22:58:28 +02:00
parent b9f5fadbb3
commit 9e5feef4d4

View file

@ -1527,13 +1527,13 @@ struct SyncVideo {
fn sync_videos(mut sync_videos: Vec<SyncVideo>, value: f64) -> Result<Option<HashMap<usize, u64>>> { fn sync_videos(mut sync_videos: Vec<SyncVideo>, value: f64) -> Result<Option<HashMap<usize, u64>>> {
let mut result = HashMap::new(); let mut result = HashMap::new();
let hasher = HasherConfig::new().to_hasher(); let hasher = HasherConfig::new().preproc_dct().to_hasher();
let start_frame = 50; let start_frame = 300;
sync_videos.sort_by_key(|sv| sv.length); sync_videos.sort_by_key(|sv| sv.length);
let sync_base = sync_videos.remove(0); let sync_base = sync_videos.remove(0);
let sync_hashes = extract_frame_hashes(&sync_base.path, start_frame, 100, &hasher)?; let sync_hashes = extract_frame_hashes(&sync_base.path, start_frame, 50, &hasher)?;
for sync_video in sync_videos { for sync_video in sync_videos {
let mut highest_frame_match = f64::INFINITY; let mut highest_frame_match = f64::INFINITY;
@ -1558,22 +1558,20 @@ fn sync_videos(mut sync_videos: Vec<SyncVideo>, value: f64) -> Result<Option<Has
&hasher, &hasher,
)?); )?);
let check_frame_windows_result = check_frame_windows(&sync_hashes, &hashes); let mut check_frame_windows_result: Vec<(usize, f64)> =
if let Some(offset) = check_frame_windows_result check_frame_windows(&sync_hashes, &hashes)
.iter() .into_iter()
.enumerate() .enumerate()
.find_map(|(i, cfw)| (*cfw <= value).then_some(i)) .collect();
{ check_frame_windows_result.sort_by(|(_, a), (_, b)| a.partial_cmp(&b).unwrap());
result.insert(sync_video.idx, frame + offset as u64 - start_frame); if check_frame_windows_result[0].1 <= value {
result.insert(
sync_video.idx,
frame + check_frame_windows_result[0].0 as u64 - start_frame,
);
break; break;
} else { } else if check_frame_windows_result[0].1 < highest_frame_match {
let curr_highest_frame_match = *check_frame_windows_result highest_frame_match = check_frame_windows_result[0].1
.iter()
.min_by(|a, b| a.total_cmp(b))
.unwrap();
if curr_highest_frame_match < highest_frame_match {
highest_frame_match = curr_highest_frame_match
}
} }
frame = (frame + 300 - sync_hashes.len() as u64).min(sync_video.available_frames) frame = (frame + 300 - sync_hashes.len() as u64).min(sync_video.available_frames)
@ -1610,7 +1608,7 @@ fn extract_frame_hashes(
.args([ .args([
"-vf", "-vf",
format!( format!(
r#"select=between(n\,{}\,{}),setpts=PTS-STARTPTS"#, r#"select=between(n\,{}\,{}),setpts=PTS-STARTPTS,scale=-1:240"#,
start_frame, start_frame,
start_frame + frame_count start_frame + frame_count
) )