sreepathi-ravikumar commited on
Commit
253529f
·
verified ·
1 Parent(s): 2f97d5f

Update rust_combiner/src/lib.rs

Browse files
Files changed (1) hide show
  1. rust_combiner/src/lib.rs +25 -4
rust_combiner/src/lib.rs CHANGED
@@ -1,8 +1,25 @@
1
- // rust_combiner/src/lib.rs use pyo3::prelude::*; use pyo3::wrap_pyfunction; use std::fs::File; use std::io::Write; use std::process::Command; use uuid::Uuid;
 
 
 
 
 
2
 
3
- #[pyfunction] fn combine_clips(clips: Vec<String>) -> PyResult<String> { let paths: Vec<&str> = clips.iter().map(|s| s.as_str()).collect(); concat_videos(paths) }
 
 
 
4
 
5
- fn concat_videos(clips: Vec<&str>) -> PyResult<String> { // Step 1: Write file list let list_file = format!("/tmp/clips_{}.txt", Uuid::new_v4()); let mut file = File::create(&list_file) .map_err(|e| pyo3::exceptions::PyIOError::new_err(e.to_string()))?; for clip in &clips { writeln!(file, "file '{}'", clip) .map_err(|e| pyo3::exceptions::PyIOError::new_err(e.to_string()))?; }
 
 
 
 
 
 
 
 
 
6
 
7
  // Step 2: Run FFmpeg
8
  let output_file = format!("/tmp/final_video_{}.mp4", Uuid::new_v4());
@@ -26,4 +43,8 @@ if status.success() {
26
 
27
  }
28
 
29
- #[pymodule] fn rust_combiner(_py: Python, m: &PyModule) -> PyResult<()> { m.add_function(wrap_pyfunction!(combine_clips, m)?)?; Ok(()) }
 
 
 
 
 
1
+ use pyo3::prelude::*;
2
+ use pyo3::wrap_pyfunction;
3
+ use std::fs::File;
4
+ use std::io::Write;
5
+ use std::process::Command;
6
+ use uuid::Uuid;
7
 
8
+ #[pyfunction]
9
+ fn combine_clips(clips: Vec<String>) -> PyResult<String> {
10
+ let paths: Vec<&str> = clips.iter().map(|s| s.as_str()).collect();
11
+ concat_videos(paths)
12
 
13
+ }
14
+
15
+ fn concat_videos(clips: Vec<&str>) -> PyResult<String> {
16
+ // Step 1: Write file list
17
+ let list_file = format!("/tmp/clips_{}.txt", Uuid::new_v4());
18
+ let mut file = File::create(&list_file)
19
+ .map_err(|e| pyo3::exceptions::PyIOError::new_err(e.to_string()))?;
20
+ for clip in &clips { writeln!(file, "file '{}'", clip)
21
+ .map_err(|e| pyo3::exceptions::PyIOError::new_err(e.to_string()))?;
22
+ }
23
 
24
  // Step 2: Run FFmpeg
25
  let output_file = format!("/tmp/final_video_{}.mp4", Uuid::new_v4());
 
43
 
44
  }
45
 
46
+ #[pymodule]
47
+ fn rust_combiner(_py: Python, m: &PyModule) -> PyResult<()> {
48
+ m.add_function(wrap_pyfunction!(combine_clips, m)?)?;
49
+ Ok(())
50
+ }