Skip to content

Commit

Permalink
Add generate
Browse files Browse the repository at this point in the history
  • Loading branch information
WojciechBarczynski committed Aug 23, 2024
1 parent 23c1e51 commit 0b6d374
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 5 deletions.
3 changes: 0 additions & 3 deletions docs/pages/guides/offline-processing.md
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,3 @@ We are going to schedule output update 5s after the begging and configure it to:
LiveCompositor bin starts composing automatically after spawning, so it's important to register all inputs/outputs and register all updates in [`handle_init`](https://hexdocs.pm/membrane_core/Membrane.Pipeline.html#c:handle_init/2) or [`handle_setup`](https://hexdocs.pm/membrane_core/Membrane.Pipeline.html#c:handle_setup/2) callbacks - before spawned bin will start processing buffers.
</TabItem>
</Tabs>



2 changes: 1 addition & 1 deletion docs/sidebars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const sidebars: SidebarsConfig = {
{
type: 'doc',
id: 'guides/quick-start',
label: 'Quick start',
label: 'Quick Start',
},
{
type: 'doc',
Expand Down
5 changes: 4 additions & 1 deletion generate/src/bin/generate_docs_examples/main.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
use std::path::PathBuf;

use basic_layouts::generate_basic_layouts_guide;
use offline_processing::generate_offline_processing_guide;
use quick_start::generate_quick_start_guide;
use transition::generate_tile_transition_video;
use view_transitions::generate_view_transition_guide;

mod basic_layouts;
mod offline_processing;
mod quick_start;
mod transition;
mod view_transitions;

fn main() {
generate_quick_start_guide().unwrap();
generate_basic_layouts_guide().unwrap();
generate_tile_transition_video().unwrap();
generate_view_transition_guide().unwrap();
generate_offline_processing_guide().unwrap();
generate_tile_transition_video().unwrap();
}

fn workingdir() -> PathBuf {
Expand Down
119 changes: 119 additions & 0 deletions generate/src/bin/generate_docs_examples/offline_processing.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
use std::{fs, process::Command, thread};

use anyhow::Result;
use generate::{compositor_instance::CompositorInstance, packet_sender::PacketSender};
use serde_json::json;

use crate::{pages_dir, workingdir};

pub(super) fn generate_offline_processing_guide() -> Result<()> {
let instance = CompositorInstance::start();
let output_port = instance.get_port();
let input_1_port = instance.get_port();
let input_2_port = instance.get_port();

instance.send_request(
"input/input_1/register",
json!({
"type": "rtp_stream",
"transport_protocol": "tcp_server",
"port": input_1_port,
"video": {
"decoder": "ffmpeg_h264"
},
"required": true
}),
)?;

instance.send_request(
"input/input_2/register",
json!({
"type": "rtp_stream",
"transport_protocol": "tcp_server",
"port": input_2_port,
"video": {
"decoder": "ffmpeg_h264"
},
"required": true,
"offset_ms": 5000
}),
)?;

instance.send_request(
"output/output_1/register",
json!({
"type": "rtp_stream",
"transport_protocol": "tcp_server",
"port": output_port,
"video": {
"resolution": {
"width": 1280,
"height": 720,
},
"encoder": {
"type": "ffmpeg_h264",
"preset": "ultrafast"
},
"initial": {
"root": {
"type": "rescaler",
"children": [{
"type": "input_stream",
"input_id": "input_1"
}]
}
}
},
}),
)?;

PacketSender::new(input_1_port)
.unwrap()
.send(&fs::read(workingdir().join("input_1.rtp")).unwrap())
.unwrap();
PacketSender::new(input_2_port)
.unwrap()
.send(&fs::read(workingdir().join("input_2.rtp")).unwrap())
.unwrap();

instance.send_request(
"output/output_1/update",
json!({
"video": {
"type": "tiles",
"background_color_rgba": "#4d4d4dff",
"children": [
{ "type": "input_stream", "input_id": "input_1" },
{ "type": "input_stream", "input_id": "input_2" }
]
},
"schedule_time_ms": 5000
}),
)?;

instance.send_request(
"output/output_1/unregister",
json!({
"schedule_time_ms": 10_000,
}),
)?;

let path = pages_dir()
.join("guides")
.join("assets")
.join("offline_processing.webp");
let gst_thread = thread::Builder::new().name("gst sink".to_string()).spawn(move ||{
let gst_cmd = format!(
"gst-launch-1.0 -v tcpclientsrc host=127.0.0.1 port={} ! \"application/x-rtp-stream\" ! rtpstreamdepay ! rtph264depay ! video/x-h264,framerate=30/1 ! h264parse ! h264timestamper ! decodebin ! webpenc animated=true speed=6 quality=50 ! filesink location={}",
output_port,
path.to_string_lossy(),
);
Command::new("bash").arg("-c").arg(gst_cmd).status().unwrap();
}).unwrap();

instance.send_request("start", json!({}))?;

gst_thread.join().unwrap();

Ok(())
}

0 comments on commit 0b6d374

Please sign in to comment.