//! ffmpeg 사이드카 실기 테스트 — src-tauri/binaries에 사이드카가 있을 때만 실행된다. //! (없으면 조용히 통과 — CI에서 fetch-ffmpeg 후 실행하면 전체 커버) use archive_indexer::ffmpeg::{self, FfTools}; use std::path::{Path, PathBuf}; fn tools() -> Option { // crates/archive-indexer → ../../binaries let bin = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../binaries"); let triple = if cfg!(all(windows, target_arch = "x86_64")) { "x86_64-pc-windows-msvc" } else if cfg!(all(windows, target_arch = "aarch64")) { "aarch64-pc-windows-msvc" } else if cfg!(all(target_os = "macos", target_arch = "aarch64")) { "aarch64-apple-darwin" } else { "x86_64-apple-darwin" }; let ext = if cfg!(windows) { ".exe" } else { "" }; let ffmpeg = bin.join(format!("ffmpeg-{triple}{ext}")); let ffprobe = bin.join(format!("ffprobe-{triple}{ext}")); if ffmpeg.is_file() && ffprobe.is_file() { Some(FfTools { ffmpeg, ffprobe }) } else { None } } fn make_test_video(t: &FfTools, dir: &Path) -> PathBuf { let out = dir.join("테스트영상.mp4"); let vcodec = if cfg!(windows) { "h264_mf" } else { "h264_videotoolbox" }; let status = ffmpeg::command(&t.ffmpeg) .args([ "-y", "-v", "error", "-f", "lavfi", "-i", "testsrc2=duration=2:size=320x240:rate=25", "-c:v", vcodec, "-b:v", "300k", ]) .arg(&out) .status() .expect("ffmpeg 실행 실패"); assert!(status.success(), "테스트 영상 생성 실패"); out } #[test] fn probe_and_thumbnail_roundtrip() { let Some(t) = tools() else { eprintln!("사이드카 없음 — 건너뜀 (scripts/fetch-ffmpeg.ps1 실행 후 재시도)"); return; }; let dir = tempfile::tempdir().unwrap(); let video = make_test_video(&t, dir.path()); // ffprobe 메타 let info = ffmpeg::probe(&t, &video).unwrap(); assert_eq!(info.vcodec.as_deref(), Some("h264")); assert_eq!(info.width, Some(320)); assert_eq!(info.height, Some(240)); let dur = info.duration_ms.expect("duration 없음"); assert!((1500..=2500).contains(&dur), "duration {dur}ms"); assert!(info.fps.unwrap() > 20.0); // 프레임 썸네일 let thumb = dir.path().join("thumbs/aa/key.jpg"); let (w, h) = ffmpeg::extract_frame_jpeg(&t, &video, &thumb, 0.5, 256).unwrap(); assert!(thumb.is_file()); assert!(w == 256 || h == 256, "긴 변이 256이어야 함: {w}x{h}"); }