useInputStreams
useInputStreams
returns an object representing registered streams and their current state.
Reference
12 collapsed lines
import { InputStream, Text, Tiles, useInputStreams,} from "@swmansion/smelter";import Smelter from "@swmansion/smelter-node";
type InputTileProps = { inputId: string; state?: "ready" | "playing" | "finished";};
function InputTile({ inputId, state }: InputTileProps) { if (state === "finished") { return <Text style={{ fontSize: 40 }}>Stream {inputId} finished</Text>; } if (state === "playing") { return <InputStream inputId={inputId} />; } return ( <Text style={{ fontSize: 40 }}> Waiting for stream {inputId} to connect </Text> );}
function ExampleApp() { const inputs = useInputStreams(); return ( <Tiles transition={{ durationMs: 200 }}> {Object.values(inputs).map((input) => ( <InputTile key={input.inputId} inputId={input.inputId} state={input.videoState} /> ))} </Tiles> );}
async function run() { const smelter = new Smelter(); await smelter.init();
await smelter.registerOutput("output", <ExampleApp />, {18 collapsed lines
type: "mp4", serverPath: "./output.mp4", video: { encoder: { type: "ffmpeg_h264", preset: "ultrafast", }, resolution: { width: 1920, height: 1080, }, }, audio: { encoder: { type: "aac", channels: "stereo", }, }, });
11 collapsed lines
await smelter.registerInput("input_1", { type: "mp4", serverPath: "./inputExample1.mp4", });
await smelter.registerInput("input_2", { type: "mp4", serverPath: "./inputExample2.mp4", });
await smelter.start();}void run();
function useInputStreams(): Record<string, InputStreamInfo>;
Type definitions
type InputStreamInfo = { inputId: Id; videoState?: "ready" | "playing" | "finished"; audioState?: "ready" | "playing" | "finished"; offsetMs?: number; videoDurationMs?: number; audioDurationMs?: number;}
function useInputStreams(): Record<string, InputStreamInfo>;
Returns
Object that maps ids of registered input streams to info about their state.
- Type:
Record<string, InputStreamInfo>
where (InputStreamInfo
)
InputStreamInfo
Type definitions
type InputStreamInfo = { inputId: string; videoState?: "ready" | "playing" | "finished"; audioState?: "ready" | "playing" | "finished"; offsetMs?: number; videoDurationMs?: number; audioDurationMs?: number;}
Properties
inputId
ID of an input. It identifies a stream registered using a Smelter.registerInput method.
- Type:
string
videoState
Current state of a video track in the specific input.
- Type:
"ready" | "playing" | "finished"
audioState
Current state of an audio track in the specific input.
- Type:
"ready" | "playing" | "finished"
videoDurationMs
Length of a video track if available. Only supported for some inputs e.g. mp4.
- Type:
number
audioDurationMs
Length of an audio track if available. Only supported for some inputs e.g. mp4.
- Type:
number
offsetMs
Timestamp (relative to the queue start) representing time when input was added.
- Type:
number