Skip to content

Commit 6efeaad

Browse files
committed
generated videos
1 parent dd266f6 commit 6efeaad

File tree

2 files changed

+84
-80
lines changed

2 files changed

+84
-80
lines changed

generate/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ license = "BUSL-1.1"
77
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
88

99
[features]
10-
default = ["web_renderer" ]
10+
default = ["web_renderer"]
1111
decklink = ["live_compositor/decklink"]
1212
web_renderer = ["live_compositor/web_renderer"]
1313

@@ -30,5 +30,5 @@ tracing = { workspace = true }
3030
opus = { workspace = true }
3131
pitch-detection = "0.3.0"
3232
rand = { workspace = true }
33-
schemars = { workspace = true}
33+
schemars = { workspace = true }
3434
tracing-subscriber = { version = "0.3.18", features = ["json", "env-filter"] }

generate/src/bin/generate_sample_videos.rs

+82-78
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
use std::{
2-
fs::{self, File},
3-
io::Write,
2+
fs::{self},
43
path::PathBuf,
5-
process::{Command, Stdio},
6-
thread::{self, Thread},
4+
thread::{self},
75
time::Duration,
86
};
97

108
use anyhow::Result;
11-
use compositor_api::types::Resolution;
9+
use compositor_render::{event_handler::subscribe, Resolution};
1210
use generate::compositor_instance::CompositorInstance;
1311
use serde_json::json;
1412

@@ -25,50 +23,50 @@ fn main() {
2523
"1920x1080",
2624
);
2725

28-
// generate_video_series(
29-
// Duration::from_secs(10),
30-
// Resolution {
31-
// width: 1080,
32-
// height: 1920,
33-
// },
34-
// "1080x1920",
35-
// );
36-
37-
// generate_video_series(
38-
// Duration::from_secs(10),
39-
// Resolution {
40-
// width: 854,
41-
// height: 480,
42-
// },
43-
// "854x480",
44-
// );
45-
46-
// generate_video_series(
47-
// Duration::from_secs(10),
48-
// Resolution {
49-
// width: 480,
50-
// height: 854,
51-
// },
52-
// "480x854",
53-
// );
54-
55-
// generate_video_series(
56-
// Duration::from_secs(10),
57-
// Resolution {
58-
// width: 1440,
59-
// height: 1080,
60-
// },
61-
// "1440x1080",
62-
// );
63-
64-
// generate_video_series(
65-
// Duration::from_secs(10),
66-
// Resolution {
67-
// width: 1080,
68-
// height: 1440,
69-
// },
70-
// "1080x1440",
71-
// );
26+
generate_video_series(
27+
Duration::from_secs(10),
28+
Resolution {
29+
width: 1080,
30+
height: 1920,
31+
},
32+
"1080x1920",
33+
);
34+
35+
generate_video_series(
36+
Duration::from_secs(10),
37+
Resolution {
38+
width: 854,
39+
height: 480,
40+
},
41+
"854x480",
42+
);
43+
44+
generate_video_series(
45+
Duration::from_secs(10),
46+
Resolution {
47+
width: 480,
48+
height: 854,
49+
},
50+
"480x854",
51+
);
52+
53+
generate_video_series(
54+
Duration::from_secs(10),
55+
Resolution {
56+
width: 1440,
57+
height: 1080,
58+
},
59+
"1440x1080",
60+
);
61+
62+
generate_video_series(
63+
Duration::from_secs(10),
64+
Resolution {
65+
width: 1080,
66+
height: 1440,
67+
},
68+
"1080x1440",
69+
);
7270
}
7371

7472
fn generate_video_series(duration: Duration, resolution: Resolution, name_suffix: &str) {
@@ -131,7 +129,7 @@ fn generate_video_series(duration: Duration, resolution: Resolution, name_suffix
131129
fn workingdir() -> PathBuf {
132130
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
133131
.join("workingdir")
134-
.join("inputs_mp4_maybe")
132+
.join("inputs_mp4")
135133
}
136134

137135
fn generate_video(
@@ -142,26 +140,25 @@ fn generate_video(
142140
resolution: &Resolution,
143141
) -> Result<()> {
144142
let instance = CompositorInstance::start();
145-
let output_port = instance.get_port();
146143

147144
instance.send_request(
148145
"output/output_1/register",
149146
json!({
150-
"type": "rtp_stream",
151-
"transport_protocol": "tcp_server",
152-
"port": output_port,
153-
// "type": "mp4",
154-
// "path": format!("{}", path.to_string_lossy().to_string()),
147+
"type": "mp4",
148+
"path": format!("{}", path.to_string_lossy().to_string()),
155149
"video": {
156150
"resolution": {
157151
"width": resolution.width,
158152
"height": resolution.height,
159153
},
160154
"encoder": {
161155
"type": "ffmpeg_h264",
162-
"preset": "ultrafast"
156+
"preset": "medium",
157+
"ffmpeg_options": {
158+
"crf": "32"
159+
}
163160
},
164-
"initial": scene(text, rgba_color, Duration::ZERO)
161+
"initial": scene(text, rgba_color, resolution, Duration::ZERO)
165162
},
166163
}),
167164
)?;
@@ -179,29 +176,36 @@ fn generate_video(
179176
instance.send_request(
180177
"output/output_1/update",
181178
json!({
182-
"video": scene(text, rgba_color, pts),
179+
"video": scene(text, rgba_color, resolution, pts),
183180
"schedule_time_ms": pts.as_millis(),
184181
}),
185182
)?;
186183
}
187184

188-
let gst_thread = thread::Builder::new().name("gst sink".to_string()).spawn(move ||{
189-
let gst_cmd = format!(
190-
"gst-launch-1.0 -v tcpclientsrc host=127.0.0.1 port={} ! \"application/x-rtp-stream\" ! rtpstreamdepay ! queue ! \"application/x-rtp,media=video,clock-rate=90000,encoding-name=H264,payload=96\" ! queue ! rtph264depay ! h264parse ! mp4mux ! filesink location={}",
191-
output_port,
192-
path.to_string_lossy()
193-
);
194-
Command::new("bash").arg("-c").arg(gst_cmd).status().unwrap();
195-
}).unwrap();
196-
197185
instance.send_request("start", json!({}))?;
198186

199-
gst_thread.join().unwrap();
187+
thread::spawn(|| {
188+
let event_receiver = subscribe();
189+
loop {
190+
if let Ok(event) = event_receiver.recv() {
191+
if event.kind == "OUTPUT_DONE".to_string() {
192+
break;
193+
}
194+
}
195+
}
196+
})
197+
.join()
198+
.unwrap();
200199

201200
Ok(())
202201
}
203202

204-
fn scene(text: &str, rgba_color: &str, pts: Duration) -> serde_json::Value {
203+
fn scene(
204+
text: &str,
205+
rgba_color: &str,
206+
resolution: &Resolution,
207+
pts: Duration,
208+
) -> serde_json::Value {
205209
json!({
206210
"root": {
207211
"type": "view",
@@ -212,24 +216,24 @@ fn scene(text: &str, rgba_color: &str, pts: Duration) -> serde_json::Value {
212216
{
213217
"type": "text",
214218
"text": text,
215-
"font_size": 250,
216-
"width": 1920,
219+
"font_size": resolution.width / 8,
220+
"width": resolution.width,
217221
"align": "center",
218222
"font_family": "Comic Sans MS",
219223
},
220224
{ "type": "view" },
221225
{
222226
"type": "view",
223-
"bottom": 100,
224-
"right": 100,
225-
"width": 300,
226-
"height": 100,
227+
"bottom": resolution.height / 6,
228+
"right": resolution.width / 8,
229+
"width": resolution.width / 6,
230+
"height": resolution.height / 6,
227231
"children": [
228232
{
229233
"type": "text",
230234
"text": format!("{:.2}s", pts.as_millis() as f32 / 1000.0),
231-
"font_size": 90,
232-
"width": 300,
235+
"font_size": resolution.width / 16,
236+
"width": resolution.width / 6,
233237
"align": "right",
234238
"font_family": "Comic Sans MS",
235239
},

0 commit comments

Comments
 (0)