Spaces:
Running
Running
Update rust_combiner/src/lib.rs
Browse files- rust_combiner/src/lib.rs +25 -4
rust_combiner/src/lib.rs
CHANGED
@@ -1,8 +1,25 @@
|
|
1 |
-
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
-
#[pyfunction]
|
|
|
|
|
|
|
4 |
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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]
|
|
|
|
|
|
|
|
|
|
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 |
+
}
|