Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
alik-git committed Dec 6, 2024
1 parent dc36ab3 commit d219ba6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
10 changes: 3 additions & 7 deletions krec/bindings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1351,16 +1351,12 @@ fn combine_with_video(video_path: &str, krec_path: &str, output_path: &str) -> P

#[gen_stub_pyfunction]
#[pyfunction]
fn extract_from_video(
py: Python<'_>,
video_path: &str,
verbose: Option<bool>,
) -> PyResult<PyKRec> {
fn extract_from_video(py: Python<'_>, video_path: &str, verbose: Option<bool>) -> PyResult<PyKRec> {
info!("Python binding: extract_from_video called");

let krec = ::krec::extract_from_video(video_path, verbose)
.map_err(|e| PyErr::new::<pyo3::exceptions::PyIOError, _>(e.to_string()))?;

Ok(PyKRec { inner: krec })
}

Expand Down
18 changes: 7 additions & 11 deletions src/ffmpeg.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::KRec;
use color_eyre::{eyre::eyre, Result};
use std::path::Path;
use tempfile::NamedTempFile;
use thiserror::Error;
use tracing::{debug, info, instrument, warn};
use tempfile::NamedTempFile;

#[derive(Error, Debug)]
pub enum FFmpegError {
Expand Down Expand Up @@ -84,21 +84,17 @@ pub fn combine_with_video(
}
}

pub fn extract_from_video(
video_path: &str,
verbose: Option<bool>,
) -> Result<KRec, FFmpegError> {
pub fn extract_from_video(video_path: &str, verbose: Option<bool>) -> Result<KRec, FFmpegError> {
info!("Starting extract_from_video");

// Check if input file exists
if !Path::new(video_path).exists() {
return Err(FFmpegError::InputNotFound(video_path.to_string()));
}

// Create a temporary file for FFmpeg output
let temp_file = NamedTempFile::new().map_err(|e|
FFmpegError::FFmpeg(format!("Failed to create temporary file: {}", e))
)?;
let temp_file = NamedTempFile::new()
.map_err(|e| FFmpegError::FFmpeg(format!("Failed to create temporary file: {}", e)))?;
let temp_path = temp_file.path().to_string_lossy().to_string();

// Construct ffmpeg command
Expand Down Expand Up @@ -135,9 +131,9 @@ pub fn extract_from_video(
}

// Load the KRec from the temporary file
let krec = KRec::load(&temp_path).map_err(|e|
let krec = KRec::load(&temp_path).map_err(|e| {
FFmpegError::FFmpeg(format!("Failed to load KRec from temporary file: {}", e))
)?;
})?;

// The temporary file will be automatically deleted when temp_file goes out of scope
info!("Successfully extracted KRec from video");
Expand Down

0 comments on commit d219ba6

Please sign in to comment.