//! Throwaway probe: how long is each region chunk of a movie's voice? //! //! The question it answers is whether the chunks of a resolved voice region are //! CONSECUTIVE SEGMENTS (concatenate them) or ALTERNATE TAKES (chunk 0 is the //! whole track). Getting that backwards plays the dialogue three times over. use std::process::Command; use sylpheed_formats::{media, slb::VoiceLang}; fn main() { let disc = std::env::var("SYLPHEED_DISC").expect("set SYLPHEED_DISC to the extracted disc root"); let src = media::DirectorySource::new(&disc); for movie in ["ADV", "S00A", "RT01A"] { let Some((s, e)) = media::resolve_movie_voice_region(&src, movie, VoiceLang::English) else { println!("{movie}: no region"); continue; }; let riffs = media::voice_region_riffs(&src, s, e).expect("riffs"); println!( "{movie}: region [{s}, {e}) = {} bytes, {} chunk(s)", e - s, riffs.len() ); for (i, r) in riffs.iter().enumerate() { let p = std::env::temp_dir().join(format!("vc_{movie}_{i}.xma.wav")); std::fs::write(&p, r).unwrap(); // XMA declares no duration, so DECODE it and measure the result. let w = std::env::temp_dir().join(format!("vc_{movie}_{i}.wav")); let _ = Command::new("ffmpeg") .args(["-hide_banner", "-loglevel", "error", "-y", "-i"]) .arg(&p) .arg(&w) .output(); let out = Command::new("ffprobe") .args([ "-v", "error", "-show_entries", "format=duration", "-of", "csv=p=0", ]) .arg(&w) .output() .unwrap(); let dur = String::from_utf8_lossy(&out.stdout).trim().to_string(); if std::env::var("KEEP_WAV").is_ok() { let keep = std::path::Path::new(&std::env::var("KEEP_WAV").unwrap()) .join(format!("{movie}_chunk{i}.wav")); let _ = std::fs::rename(&w, &keep); println!(" kept -> {}", keep.display()); } else { let _ = std::fs::remove_file(&w); } println!(" chunk {i}: {} bytes -> {dur} s", r.len()); let _ = std::fs::remove_file(&p); } } }