Reset video
Added in Scrcpy 3.0
Restart video capture and encoding.
Because a video must start with a configuration and keyframe to be decoded, sometimes you might want to manually restart video capture and encoding, which produces a new configuration packet and keyframe data packet immediately.
For example, when you want to save a video from a specific point, or stream the video to multiple players, and a new player is added.
Reset video will cause a very small pause in the video stream, but it should be acceptable for most cases.
Usage
- JavaScript
- TypeScript
// Using `ScrcpyControlMessageSerializer`
const message = serializer.resetVideo();
// Using `ScrcpyControlMessageWriter`
await writer.resetVideo();
// Using `AdbScrcpyClient`
await client.controller.resetVideo();
import { AndroidKeyEventAction } from "@yume-chan/scrcpy";
// Using `ScrcpyControlMessageSerializer`
const message: Uint8Array = serializer.resetVideo();
// Using `ScrcpyControlMessageWriter`
await writer.resetVideo();
// Using `AdbScrcpyClient`
await client.controller!.resetVideo();
Because the transmission delay, some video packets for previous configuration might still arrive after the reset video command. You can still send them to existing consumers (decoders, muxers, or remote clients), but new consumers should only be started when the next configuration
packet is received.
- JavaScript
- TypeScript
let consumers = [];
let pendingConsumers = []; // New decoders, muxers, or remote clients waiting for the next `configuration` packet
for await (const packet of videoPacketStream) {
switch (packet.type) {
case "configuration":
if (pendingConsumers.length) {
// Initialize pending consumers
consumers = consumers.concat(pendingConsumers);
pendingConsumers = [];
}
// Send packets to `consumers`
break;
case "data":
// Send packets to `consumers`
break;
}
}
import { ScrcpyMediaStreamPacket } from "@yume-chan/scrcpy";
declare const videoPacketStream: ReadableStream<ScrcpyMediaStreamPacket>;
let consumers: unknown[] = [];
let pendingConsumers: unknown[] = []; // New decoders, muxers, or remote clients waiting for the next `configuration` packet
for await (const packet of videoPacketStream) {
switch (packet.type) {
case "configuration":
if (pendingConsumers.length) {
// Initialize pending consumers
consumers = consumers.concat(pendingConsumers);
pendingConsumers = [];
}
// Send packets to `consumers`
break;
case "data":
// Send packets to `consumers`
break;
}
}