Skip to content

Commit

Permalink
[demos] Fix prettier config (#622)
Browse files Browse the repository at this point in the history
  • Loading branch information
wkozyra95 authored Jul 11, 2024
1 parent ef56167 commit b7e6b86
Show file tree
Hide file tree
Showing 11 changed files with 327 additions and 414 deletions.
File renamed without changes.
90 changes: 43 additions & 47 deletions demos/1-videoconferencing/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
import { runCompositorExample } from "../utils/run";
import { gstStreamWebcam } from "../utils/gst";
import { downloadAsync, sleepAsync } from "../utils/utils";
import { Component, Resolution } from "../types/api.d";
import {
ffmpegSendVideoFromMp4,
ffplayStartPlayerAsync,
} from "../utils/ffmpeg";
import path from "path";
import { runCompositorExample } from '../utils/run';
import { gstStreamWebcam } from '../utils/gst';
import { downloadAsync, sleepAsync } from '../utils/utils';
import { Component, Resolution } from '../types/api.d';
import { ffmpegSendVideoFromMp4, ffplayStartPlayerAsync } from '../utils/ffmpeg';
import path from 'path';
import {
registerImageAsync,
registerInputAsync,
registerOutputAsync,
startAsync,
updateOutputAsync,
} from "../utils/api";
} from '../utils/api';

const OUTPUT_RESOLUTION: Resolution = {
width: 1920,
Expand All @@ -22,44 +19,44 @@ const OUTPUT_RESOLUTION: Resolution = {

const INPUT_PORT = 8000;
const OUTPUT_PORT = 8002;
const IP = "127.0.0.1";
const IP = '127.0.0.1';
const DISPLAY_LOGS = true;

const BACKGROUND_URL =
"https://raw.githubusercontent.com/membraneframework-labs/video_compositor_snapshot_tests/main/demo_assets/triangles_background.png";
'https://raw.githubusercontent.com/membraneframework-labs/video_compositor_snapshot_tests/main/demo_assets/triangles_background.png';
const CALL_URL =
"https://raw.githubusercontent.com/membraneframework-labs/video_compositor_snapshot_tests/main/demo_assets/call.mp4";
'https://raw.githubusercontent.com/membraneframework-labs/video_compositor_snapshot_tests/main/demo_assets/call.mp4';

async function exampleAsync() {
const useWebCam = process.env.LIVE_COMPOSITOR_WEBCAM !== "false";
const useWebCam = process.env.LIVE_COMPOSITOR_WEBCAM !== 'false';
await ffplayStartPlayerAsync(IP, DISPLAY_LOGS, OUTPUT_PORT);

// sleep to make sure ffplay have a chance to start before compositor starts sending packets
await sleepAsync(2000);

await registerImageAsync("background", {
asset_type: "png",
await registerImageAsync('background', {
asset_type: 'png',
url: BACKGROUND_URL,
});

await registerInputAsync("input_1", {
type: "rtp_stream",
transport_protocol: useWebCam ? "tcp_server" : "udp",
await registerInputAsync('input_1', {
type: 'rtp_stream',
transport_protocol: useWebCam ? 'tcp_server' : 'udp',
port: INPUT_PORT,
video: {
decoder: "ffmpeg_h264",
decoder: 'ffmpeg_h264',
},
});

await registerOutputAsync("output_1", {
type: "rtp_stream",
await registerOutputAsync('output_1', {
type: 'rtp_stream',
ip: IP,
port: OUTPUT_PORT,
video: {
resolution: OUTPUT_RESOLUTION,
encoder: {
type: "ffmpeg_h264",
preset: "medium",
type: 'ffmpeg_h264',
preset: 'medium',
},
initial: {
root: sceneWithInputs(1),
Expand All @@ -70,19 +67,18 @@ async function exampleAsync() {
if (useWebCam) {
gstStreamWebcam(IP, INPUT_PORT, DISPLAY_LOGS);
} else {
const callPath = path.join(__dirname, "../assets/call.mp4");
const callPath = path.join(__dirname, '../assets/call.mp4');
await downloadAsync(CALL_URL, callPath);
ffmpegSendVideoFromMp4(INPUT_PORT, callPath, DISPLAY_LOGS);
}
await startAsync();

const inputs = [
2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5,
4, 3, 2, 1,
2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1,
];

for (let i = 0; i < inputs.length; i++) {
await updateOutputAsync("output_1", {
await updateOutputAsync('output_1', {
video: {
root: sceneWithInputs(inputs[i]),
},
Expand All @@ -94,31 +90,31 @@ async function exampleAsync() {
function sceneWithInputs(n: number): Component {
const children: Array<Component> = Array.from({ length: n }, (_, i) => {
const text: Component = {
type: "text",
type: 'text',
text: `InputStream ${i} 🚀`,
font_size: 25,
align: "center",
color_rgba: "#FFFFFFFF",
background_color_rgba: "#FF0000FF",
font_family: "Arial",
align: 'center',
color_rgba: '#FFFFFFFF',
background_color_rgba: '#FF0000FF',
font_family: 'Arial',
};

const inputStreamTile: Component = {
type: "view",
type: 'view',
children: [
{
type: "rescaler",
type: 'rescaler',
child: {
type: "input_stream",
input_id: "input_1",
type: 'input_stream',
input_id: 'input_1',
},
},
{
type: "view",
type: 'view',
height: 50,
bottom: 0,
left: 0,
children: [{ type: "view" }, text, { type: "view" }],
children: [{ type: 'view' }, text, { type: 'view' }],
},
],
};
Expand All @@ -127,39 +123,39 @@ function sceneWithInputs(n: number): Component {
});

const tiles: Component = {
type: "tiles",
id: "tile",
type: 'tiles',
id: 'tile',
padding: 5,
children: children,
transition: {
duration_ms: 700,
easing_function: {
function_name: "cubic_bezier",
function_name: 'cubic_bezier',
points: [0.35, 0.22, 0.1, 0.8],
},
},
};

const background: Component = {
type: "image",
image_id: "background",
type: 'image',
image_id: 'background',
};

return {
type: "view",
type: 'view',
width: OUTPUT_RESOLUTION.width,
height: OUTPUT_RESOLUTION.height,
children: [
{
type: "view",
type: 'view',
width: OUTPUT_RESOLUTION.width,
height: OUTPUT_RESOLUTION.height,
top: 0,
left: 0,
children: [background],
},
{
type: "view",
type: 'view',
width: OUTPUT_RESOLUTION.width,
height: OUTPUT_RESOLUTION.height,
top: 0,
Expand Down
Loading

0 comments on commit b7e6b86

Please sign in to comment.