chore: cargo fmt + clippy fix for collapsed if-let chain (T017)

- cargo fmt applied across all modified source files
- Collapse nested if let Some / if !is_empty into a single let-chain (clippy::collapsible_match)
- All other warnings are pre-existing dead-code lint on unused trait methods

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Cameron
2026-03-18 23:09:58 -04:00
parent 5c9f5c7d0b
commit c1b6013412
8 changed files with 201 additions and 160 deletions

View File

@@ -738,7 +738,11 @@ impl InsightGenerator {
.map(|t| t.name) .map(|t| t.name)
.collect() .collect()
}; };
log::info!("Fetched {} tags for photo: {:?}", tag_names.len(), tag_names); log::info!(
"Fetched {} tags for photo: {:?}",
tag_names.len(),
tag_names
);
// 4. Get location name from GPS coordinates (needed for RAG query) // 4. Get location name from GPS coordinates (needed for RAG query)
let location = match exif { let location = match exif {
@@ -827,7 +831,10 @@ impl InsightGenerator {
Some(desc) Some(desc)
} }
Err(e) => { Err(e) => {
log::warn!("Failed to generate photo description for RAG enrichment: {}", e); log::warn!(
"Failed to generate photo description for RAG enrichment: {}",
e
);
None None
} }
} }
@@ -845,7 +852,11 @@ impl InsightGenerator {
if !tag_names.is_empty() { if !tag_names.is_empty() {
parts.push(format!("tags: {}", tag_names.join(", "))); parts.push(format!("tags: {}", tag_names.join(", ")));
} }
if parts.is_empty() { None } else { Some(parts.join(". ")) } if parts.is_empty() {
None
} else {
Some(parts.join(". "))
}
}; };
let mut search_enrichment: Option<String> = enriched_query.clone(); let mut search_enrichment: Option<String> = enriched_query.clone();
@@ -900,7 +911,11 @@ impl InsightGenerator {
if !tag_names.is_empty() { if !tag_names.is_empty() {
parts.push(format!("tags: {}", tag_names.join(", "))); parts.push(format!("tags: {}", tag_names.join(", ")));
} }
if parts.is_empty() { None } else { Some(parts.join(". ")) } if parts.is_empty() {
None
} else {
Some(parts.join(". "))
}
}; };
// Step 3: Try historical RAG (>30 days ago) using extracted topics // Step 3: Try historical RAG (>30 days ago) using extracted topics
@@ -980,7 +995,14 @@ impl InsightGenerator {
log::info!("No immediate messages found, trying basic RAG as fallback"); log::info!("No immediate messages found, trying basic RAG as fallback");
// Fallback to basic RAG even without strong query // Fallback to basic RAG even without strong query
match self match self
.find_relevant_messages_rag(date_taken, None, contact.as_deref(), None, 20, enriched_query.as_deref()) .find_relevant_messages_rag(
date_taken,
None,
contact.as_deref(),
None,
20,
enriched_query.as_deref(),
)
.await .await
{ {
Ok(rag_messages) if !rag_messages.is_empty() => { Ok(rag_messages) if !rag_messages.is_empty() => {
@@ -1399,11 +1421,7 @@ Return ONLY the summary, nothing else."#,
Ok(d) => d, Ok(d) => d,
Err(e) => return format!("Error: failed to parse date '{}': {}", date_str, e), Err(e) => return format!("Error: failed to parse date '{}': {}", date_str, e),
}; };
let timestamp = date let timestamp = date.and_hms_opt(12, 0, 0).unwrap().and_utc().timestamp();
.and_hms_opt(12, 0, 0)
.unwrap()
.and_utc()
.timestamp();
log::info!( log::info!(
"tool_get_sms_messages: date={}, contact='{}', days_radius={}", "tool_get_sms_messages: date={}, contact='{}', days_radius={}",
@@ -1442,7 +1460,11 @@ Return ONLY the summary, nothing else."#,
format!("[{}] {}: {}", ts, sender, m.body) format!("[{}] {}: {}", ts, sender, m.body)
}) })
.collect(); .collect();
format!("Found {} messages:\n{}", messages.len(), formatted.join("\n")) format!(
"Found {} messages:\n{}",
messages.len(),
formatted.join("\n")
)
} }
Ok(_) => "No messages found.".to_string(), Ok(_) => "No messages found.".to_string(),
Err(e) => format!("Error fetching SMS messages: {}", e), Err(e) => format!("Error fetching SMS messages: {}", e),
@@ -1468,11 +1490,7 @@ Return ONLY the summary, nothing else."#,
Ok(d) => d, Ok(d) => d,
Err(e) => return format!("Error: failed to parse date '{}': {}", date_str, e), Err(e) => return format!("Error: failed to parse date '{}': {}", date_str, e),
}; };
let timestamp = date let timestamp = date.and_hms_opt(12, 0, 0).unwrap().and_utc().timestamp();
.and_hms_opt(12, 0, 0)
.unwrap()
.and_utc()
.timestamp();
log::info!( log::info!(
"tool_get_calendar_events: date={}, days_radius={}", "tool_get_calendar_events: date={}, days_radius={}",
@@ -1541,11 +1559,7 @@ Return ONLY the summary, nothing else."#,
Ok(d) => d, Ok(d) => d,
Err(e) => return format!("Error: failed to parse date '{}': {}", date_str, e), Err(e) => return format!("Error: failed to parse date '{}': {}", date_str, e),
}; };
let timestamp = date let timestamp = date.and_hms_opt(12, 0, 0).unwrap().and_utc().timestamp();
.and_hms_opt(12, 0, 0)
.unwrap()
.and_utc()
.timestamp();
log::info!( log::info!(
"tool_get_location_history: date={}, days_radius={}", "tool_get_location_history: date={}, days_radius={}",
@@ -1805,10 +1819,8 @@ Return ONLY the summary, nothing else."#,
// 2a. Verify the model exists on at least one server before checking capabilities // 2a. Verify the model exists on at least one server before checking capabilities
if let Some(ref model_name) = custom_model { if let Some(ref model_name) = custom_model {
let available_on_primary = OllamaClient::is_model_available( let available_on_primary =
&ollama_client.primary_url, OllamaClient::is_model_available(&ollama_client.primary_url, model_name)
model_name,
)
.await .await
.unwrap_or(false); .unwrap_or(false);
@@ -2002,8 +2014,9 @@ Return ONLY the summary, nothing else."#,
messages.push(response.clone()); messages.push(response.clone());
if let Some(ref tool_calls) = response.tool_calls { if let Some(ref tool_calls) = response.tool_calls
if !tool_calls.is_empty() { && !tool_calls.is_empty()
{
for tool_call in tool_calls { for tool_call in tool_calls {
log::info!( log::info!(
"Agentic tool call [{}]: {} {:?}", "Agentic tool call [{}]: {} {:?}",
@@ -2024,7 +2037,6 @@ Return ONLY the summary, nothing else."#,
} }
continue; continue;
} }
}
// No tool calls — this is the final answer // No tool calls — this is the final answer
final_content = response.content; final_content = response.content;
@@ -2033,13 +2045,14 @@ Return ONLY the summary, nothing else."#,
// If loop exhausted without final answer, ask for one // If loop exhausted without final answer, ask for one
if final_content.is_empty() { if final_content.is_empty() {
log::info!("Agentic loop exhausted after {} iterations, requesting final answer", iterations_used); log::info!(
"Agentic loop exhausted after {} iterations, requesting final answer",
iterations_used
);
messages.push(ChatMessage::user( messages.push(ChatMessage::user(
"Based on the context gathered, please write the final photo insight: a title and a detailed personal summary. Write in first person as Cameron.", "Based on the context gathered, please write the final photo insight: a title and a detailed personal summary. Write in first person as Cameron.",
)); ));
let final_response = ollama_client let final_response = ollama_client.chat_with_tools(messages, vec![]).await?;
.chat_with_tools(messages, vec![])
.await?;
final_content = final_response.content; final_content = final_response.content;
} }
@@ -2179,18 +2192,29 @@ mod tests {
Some("vacation, hiking, mountains".to_string()), Some("vacation, hiking, mountains".to_string()),
); );
assert!(result.contains("## Tags"), "Should include Tags section"); assert!(result.contains("## Tags"), "Should include Tags section");
assert!(result.contains("vacation, hiking, mountains"), "Should include tag names"); assert!(
result.contains("vacation, hiking, mountains"),
"Should include tag names"
);
} }
#[test] #[test]
fn combine_contexts_omits_tags_section_when_no_tags() { fn combine_contexts_omits_tags_section_when_no_tags() {
let result = InsightGenerator::combine_contexts( let result = InsightGenerator::combine_contexts(
Some("some messages".to_string()), Some("some messages".to_string()),
None, None, None, None,
None,
None,
None, // no tags None, // no tags
); );
assert!(!result.contains("## Tags"), "Should not include Tags section when None"); assert!(
assert!(result.contains("## Messages"), "Should still include Messages"); !result.contains("## Tags"),
"Should not include Tags section when None"
);
assert!(
result.contains("## Messages"),
"Should still include Messages"
);
} }
#[test] #[test]

View File

@@ -528,10 +528,8 @@ Analyze the image and use specific details from both the visual content and the
// Try fallback server if available // Try fallback server if available
if let Some(fallback_url) = &self.fallback_url { if let Some(fallback_url) = &self.fallback_url {
let fallback_model = self let fallback_model =
.fallback_model self.fallback_model.as_ref().unwrap_or(&self.primary_model);
.as_ref()
.unwrap_or(&self.primary_model);
log::info!( log::info!(
"Attempting chat_with_tools with fallback server: {} (model: {})", "Attempting chat_with_tools with fallback server: {} (model: {})",
@@ -578,7 +576,9 @@ Analyze the image and use specific details from both the visual content and the
let model = if base_url == self.primary_url { let model = if base_url == self.primary_url {
&self.primary_model &self.primary_model
} else { } else {
self.fallback_model.as_deref().unwrap_or(&self.primary_model) self.fallback_model
.as_deref()
.unwrap_or(&self.primary_model)
}; };
let options = self.num_ctx.map(|ctx| OllamaOptions { num_ctx: Some(ctx) }); let options = self.num_ctx.map(|ctx| OllamaOptions { num_ctx: Some(ctx) });
@@ -602,7 +602,11 @@ Analyze the image and use specific details from both the visual content and the
if !response.status().is_success() { if !response.status().is_success() {
let status = response.status(); let status = response.status();
let body = response.text().await.unwrap_or_default(); let body = response.text().await.unwrap_or_default();
anyhow::bail!("Ollama chat request failed with status {}: {}", status, body); anyhow::bail!(
"Ollama chat request failed with status {}: {}",
status,
body
);
} }
let chat_response: OllamaChatResponse = response let chat_response: OllamaChatResponse = response
@@ -804,13 +808,28 @@ pub struct ChatMessage {
impl ChatMessage { impl ChatMessage {
pub fn system(content: impl Into<String>) -> Self { pub fn system(content: impl Into<String>) -> Self {
Self { role: "system".to_string(), content: content.into(), tool_calls: None, images: None } Self {
role: "system".to_string(),
content: content.into(),
tool_calls: None,
images: None,
}
} }
pub fn user(content: impl Into<String>) -> Self { pub fn user(content: impl Into<String>) -> Self {
Self { role: "user".to_string(), content: content.into(), tool_calls: None, images: None } Self {
role: "user".to_string(),
content: content.into(),
tool_calls: None,
images: None,
}
} }
pub fn tool_result(content: impl Into<String>) -> Self { pub fn tool_result(content: impl Into<String>) -> Self {
Self { role: "tool".to_string(), content: content.into(), tool_calls: None, images: None } Self {
role: "tool".to_string(),
content: content.into(),
tool_calls: None,
images: None,
}
} }
} }

View File

@@ -4,7 +4,7 @@ use std::ops::DerefMut;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use crate::database::models::{InsertVideoPreviewClip, VideoPreviewClip}; use crate::database::models::{InsertVideoPreviewClip, VideoPreviewClip};
use crate::database::{connect, DbError, DbErrorKind}; use crate::database::{DbError, DbErrorKind, connect};
use crate::otel::trace_db_call; use crate::otel::trace_db_call;
pub trait PreviewDao: Sync + Send { pub trait PreviewDao: Sync + Send {
@@ -232,10 +232,7 @@ mod tests {
.unwrap(); .unwrap();
// Status should remain "pending" from the first insert // Status should remain "pending" from the first insert
let clip = dao let clip = dao.get_preview(&ctx, "photos/video.mp4").unwrap().unwrap();
.get_preview(&ctx, "photos/video.mp4")
.unwrap()
.unwrap();
assert_eq!(clip.status, "pending"); assert_eq!(clip.status, "pending");
} }
@@ -256,10 +253,7 @@ mod tests {
) )
.unwrap(); .unwrap();
let clip = dao let clip = dao.get_preview(&ctx, "photos/video.mp4").unwrap().unwrap();
.get_preview(&ctx, "photos/video.mp4")
.unwrap()
.unwrap();
assert_eq!(clip.status, "complete"); assert_eq!(clip.status, "complete");
assert_eq!(clip.duration_seconds, Some(9.5)); assert_eq!(clip.duration_seconds, Some(9.5));
assert_eq!(clip.file_size_bytes, Some(1024000)); assert_eq!(clip.file_size_bytes, Some(1024000));
@@ -283,10 +277,7 @@ mod tests {
) )
.unwrap(); .unwrap();
let clip = dao let clip = dao.get_preview(&ctx, "photos/video.mp4").unwrap().unwrap();
.get_preview(&ctx, "photos/video.mp4")
.unwrap()
.unwrap();
assert_eq!(clip.status, "failed"); assert_eq!(clip.status, "failed");
assert_eq!( assert_eq!(
clip.error_message.as_deref(), clip.error_message.as_deref(),

View File

@@ -1490,7 +1490,8 @@ mod tests {
let request: Query<FilesRequest> = let request: Query<FilesRequest> =
Query::from_query("path=&tag_ids=1,3&recursive=true").unwrap(); Query::from_query("path=&tag_ids=1,3&recursive=true").unwrap();
let mut tag_dao = SqliteTagDao::new(std::sync::Arc::new(Mutex::new(in_memory_db_connection()))); let mut tag_dao =
SqliteTagDao::new(std::sync::Arc::new(Mutex::new(in_memory_db_connection())));
let tag1 = tag_dao let tag1 = tag_dao
.create_tag(&opentelemetry::Context::current(), "tag1") .create_tag(&opentelemetry::Context::current(), "tag1")
@@ -1536,7 +1537,8 @@ mod tests {
exp: 12345, exp: 12345,
}; };
let mut tag_dao = SqliteTagDao::new(std::sync::Arc::new(Mutex::new(in_memory_db_connection()))); let mut tag_dao =
SqliteTagDao::new(std::sync::Arc::new(Mutex::new(in_memory_db_connection())));
let tag1 = tag_dao let tag1 = tag_dao
.create_tag(&opentelemetry::Context::current(), "tag1") .create_tag(&opentelemetry::Context::current(), "tag1")

View File

@@ -600,8 +600,7 @@ async fn get_video_preview(
Some(path) => path, Some(path) => path,
None => { None => {
span.set_status(Status::error("Invalid path")); span.set_status(Status::error("Invalid path"));
return HttpResponse::BadRequest() return HttpResponse::BadRequest().json(serde_json::json!({"error": "Invalid path"}));
.json(serde_json::json!({"error": "Invalid path"}));
} }
}; };
@@ -634,8 +633,7 @@ async fn get_video_preview(
} }
Err(_) => { Err(_) => {
// File missing on disk but DB says complete - reset and regenerate // File missing on disk but DB says complete - reset and regenerate
let mut dao = let mut dao = preview_dao.lock().expect("Unable to lock PreviewDao");
preview_dao.lock().expect("Unable to lock PreviewDao");
let _ = dao.update_status( let _ = dao.update_status(
&context, &context,
&relative_path, &relative_path,
@@ -665,12 +663,10 @@ async fn get_video_preview(
})) }))
} }
"failed" => { "failed" => {
let error_msg = let error_msg = clip
clip.error_message.unwrap_or_else(|| "Unknown error".to_string()); .error_message
span.set_status(Status::error(format!( .unwrap_or_else(|| "Unknown error".to_string());
"Generation failed: {}", span.set_status(Status::error(format!("Generation failed: {}", error_msg)));
error_msg
)));
HttpResponse::InternalServerError().json(serde_json::json!({ HttpResponse::InternalServerError().json(serde_json::json!({
"error": format!("Generation failed: {}", error_msg) "error": format!("Generation failed: {}", error_msg)
})) }))
@@ -708,8 +704,7 @@ async fn get_video_preview(
} }
Err(_) => { Err(_) => {
span.set_status(Status::error("Database error")); span.set_status(Status::error("Database error"));
HttpResponse::InternalServerError() HttpResponse::InternalServerError().json(serde_json::json!({"error": "Database error"}))
.json(serde_json::json!({"error": "Database error"}))
} }
} }
} }
@@ -768,10 +763,7 @@ async fn get_preview_status(
path: path.clone(), path: path.clone(),
status: clip.status.clone(), status: clip.status.clone(),
preview_url: if clip.status == "complete" { preview_url: if clip.status == "complete" {
Some(format!( Some(format!("/video/preview?path={}", urlencoding::encode(path)))
"/video/preview?path={}",
urlencoding::encode(path)
))
} else { } else {
None None
}, },
@@ -810,8 +802,7 @@ async fn get_preview_status(
} }
Err(_) => { Err(_) => {
span.set_status(Status::error("Database error")); span.set_status(Status::error("Database error"));
HttpResponse::InternalServerError() HttpResponse::InternalServerError().json(serde_json::json!({"error": "Database error"}))
.json(serde_json::json!({"error": "Database error"}))
} }
} }
} }
@@ -1213,9 +1204,7 @@ fn main() -> std::io::Result<()> {
.app_data::<Data<Mutex<Box<dyn PreviewDao>>>>(Data::new(Mutex::new(Box::new( .app_data::<Data<Mutex<Box<dyn PreviewDao>>>>(Data::new(Mutex::new(Box::new(
preview_dao, preview_dao,
)))) ))))
.app_data( .app_data(web::JsonConfig::default().error_handler(|err, req| {
web::JsonConfig::default()
.error_handler(|err, req| {
let detail = err.to_string(); let detail = err.to_string();
log::warn!( log::warn!(
"JSON parse error on {} {}: {}", "JSON parse error on {} {}: {}",
@@ -1223,11 +1212,10 @@ fn main() -> std::io::Result<()> {
req.uri(), req.uri(),
detail detail
); );
let response = HttpResponse::BadRequest() let response =
.json(serde_json::json!({"error": detail})); HttpResponse::BadRequest().json(serde_json::json!({"error": detail}));
actix_web::error::InternalError::from_response(err, response).into() actix_web::error::InternalError::from_response(err, response).into()
}), }))
)
.app_data::<Data<InsightGenerator>>(Data::new(app_data.insight_generator.clone())) .app_data::<Data<InsightGenerator>>(Data::new(app_data.insight_generator.clone()))
.wrap(prometheus.clone()) .wrap(prometheus.clone())
}) })
@@ -1765,9 +1753,7 @@ mod tests {
// Verify the DAO now has a pending record // Verify the DAO now has a pending record
let mut dao_lock = preview_dao.lock().unwrap(); let mut dao_lock = preview_dao.lock().unwrap();
let ctx = opentelemetry::Context::new(); let ctx = opentelemetry::Context::new();
let clip = dao_lock let clip = dao_lock.get_preview(&ctx, "photos/new_video.mp4").unwrap();
.get_preview(&ctx, "photos/new_video.mp4")
.unwrap();
assert!(clip.is_some()); assert!(clip.is_some());
assert_eq!(clip.unwrap().status, "pending"); assert_eq!(clip.unwrap().status, "pending");
} }
@@ -1778,7 +1764,14 @@ mod tests {
let ctx = opentelemetry::Context::new(); let ctx = opentelemetry::Context::new();
dao.insert_preview(&ctx, "photos/done.mp4", "pending") dao.insert_preview(&ctx, "photos/done.mp4", "pending")
.unwrap(); .unwrap();
dao.update_status(&ctx, "photos/done.mp4", "complete", Some(9.5), Some(500000), None) dao.update_status(
&ctx,
"photos/done.mp4",
"complete",
Some(9.5),
Some(500000),
None,
)
.unwrap(); .unwrap();
let preview_dao = make_preview_dao(dao); let preview_dao = make_preview_dao(dao);
@@ -1806,7 +1799,12 @@ mod tests {
let previews = body["previews"].as_array().unwrap(); let previews = body["previews"].as_array().unwrap();
assert_eq!(previews.len(), 1); assert_eq!(previews.len(), 1);
assert_eq!(previews[0]["status"], "complete"); assert_eq!(previews[0]["status"], "complete");
assert!(previews[0]["preview_url"].as_str().unwrap().contains("photos%2Fdone.mp4")); assert!(
previews[0]["preview_url"]
.as_str()
.unwrap()
.contains("photos%2Fdone.mp4")
);
} }
#[actix_rt::test] #[actix_rt::test]

View File

@@ -46,11 +46,8 @@ impl AppState {
let video_playlist_manager = let video_playlist_manager =
VideoPlaylistManager::new(video_path.clone(), playlist_generator.start()); VideoPlaylistManager::new(video_path.clone(), playlist_generator.start());
let preview_clip_generator = PreviewClipGenerator::new( let preview_clip_generator =
preview_clips_path.clone(), PreviewClipGenerator::new(preview_clips_path.clone(), base_path.clone(), preview_dao);
base_path.clone(),
preview_dao,
);
Self { Self {
stream_manager, stream_manager,
@@ -141,9 +138,10 @@ impl Default for AppState {
); );
// Ensure preview clips directory exists // Ensure preview clips directory exists
let preview_clips_path = env::var("PREVIEW_CLIPS_DIRECTORY") let preview_clips_path =
.unwrap_or_else(|_| "preview_clips".to_string()); env::var("PREVIEW_CLIPS_DIRECTORY").unwrap_or_else(|_| "preview_clips".to_string());
std::fs::create_dir_all(&preview_clips_path).expect("Failed to create PREVIEW_CLIPS_DIRECTORY"); std::fs::create_dir_all(&preview_clips_path)
.expect("Failed to create PREVIEW_CLIPS_DIRECTORY");
Self::new( Self::new(
Arc::new(StreamActor {}.start()), Arc::new(StreamActor {}.start()),

View File

@@ -159,12 +159,14 @@ async fn get_video_rotation(video_path: &str) -> i32 {
.await; .await;
if let Ok(output) = output if let Ok(output) = output
&& output.status.success() { && output.status.success()
{
let rotation_str = String::from_utf8_lossy(&output.stdout); let rotation_str = String::from_utf8_lossy(&output.stdout);
let rotation_str = rotation_str.trim(); let rotation_str = rotation_str.trim();
if !rotation_str.is_empty() if !rotation_str.is_empty()
&& let Ok(rotation) = rotation_str.parse::<i32>() && let Ok(rotation) = rotation_str.parse::<i32>()
&& rotation != 0 { && rotation != 0
{
debug!( debug!(
"Detected rotation {}° from stream tag for {}", "Detected rotation {}° from stream tag for {}",
rotation, video_path rotation, video_path
@@ -188,11 +190,13 @@ async fn get_video_rotation(video_path: &str) -> i32 {
.await; .await;
if let Ok(output) = output if let Ok(output) = output
&& output.status.success() { && output.status.success()
{
let rotation_str = String::from_utf8_lossy(&output.stdout); let rotation_str = String::from_utf8_lossy(&output.stdout);
let rotation_str = rotation_str.trim(); let rotation_str = rotation_str.trim();
if !rotation_str.is_empty() if !rotation_str.is_empty()
&& let Ok(rotation) = rotation_str.parse::<f64>() { && let Ok(rotation) = rotation_str.parse::<f64>()
{
let rotation = rotation.abs() as i32; let rotation = rotation.abs() as i32;
if rotation != 0 { if rotation != 0 {
debug!( debug!(
@@ -550,7 +554,8 @@ impl Handler<GeneratePreviewClipMessage> for PreviewClipGenerator {
{ {
let otel_ctx = opentelemetry::Context::current(); let otel_ctx = opentelemetry::Context::current();
let mut dao = preview_dao.lock().expect("Unable to lock PreviewDao"); let mut dao = preview_dao.lock().expect("Unable to lock PreviewDao");
let _ = dao.update_status(&otel_ctx, &relative_path, "processing", None, None, None); let _ =
dao.update_status(&otel_ctx, &relative_path, "processing", None, None, None);
} }
// Compute output path: join preview_clips_dir with relative path, change ext to .mp4 // Compute output path: join preview_clips_dir with relative path, change ext to .mp4

View File

@@ -183,7 +183,11 @@ impl Ffmpeg {
Ok(output_file.to_string()) Ok(output_file.to_string())
} }
pub async fn create_gif_from_frames(&self, frame_base_dir: &str, output_file: &str) -> Result<i32> { pub async fn create_gif_from_frames(
&self,
frame_base_dir: &str,
output_file: &str,
) -> Result<i32> {
let output = Command::new("ffmpeg") let output = Command::new("ffmpeg")
.arg("-y") .arg("-y")
.args(["-framerate", "4"]) .args(["-framerate", "4"])
@@ -278,10 +282,7 @@ pub async fn generate_preview_clip(input_file: &str, output_file: &str) -> Resul
"select='lt(mod(t,{:.4}),1)',setpts=N/FRAME_RATE/TB,fps=30,scale=-2:480,format=yuv420p", "select='lt(mod(t,{:.4}),1)',setpts=N/FRAME_RATE/TB,fps=30,scale=-2:480,format=yuv420p",
interval interval
); );
let af = format!( let af = format!("aselect='lt(mod(t,{:.4}),1)',asetpts=N/SR/TB", interval);
"aselect='lt(mod(t,{:.4}),1)',asetpts=N/SR/TB",
interval
);
cmd.args(["-vf", &vf]); cmd.args(["-vf", &vf]);
cmd.args(["-af", &af]); cmd.args(["-af", &af]);
@@ -326,7 +327,10 @@ pub async fn generate_preview_clip(input_file: &str, output_file: &str) -> Resul
info!( info!(
"Generated preview clip '{}' ({:.1}s, {} bytes) in {:?}", "Generated preview clip '{}' ({:.1}s, {} bytes) in {:?}",
output_file, clip_duration, file_size, start.elapsed() output_file,
clip_duration,
file_size,
start.elapsed()
); );
Ok((clip_duration, file_size)) Ok((clip_duration, file_size))