Skip to content

Commit

Permalink
Add readrateInitialBurst property
Browse files Browse the repository at this point in the history
  • Loading branch information
longnguyen2004 committed Jan 24, 2025
1 parent 2f417bf commit cfe8bde
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/media/newApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,12 @@ export type PlayStreamOptions = {
*/
frameRate: number,

/**
* Same as ffmpeg's `readrate_initial_burst` command line flag
* See https://ffmpeg.org/ffmpeg.html#:~:text=%2Dreadrate_initial_burst
*/
readrateInitialBurst: number | undefined,

/**
* Enable RTCP Sender Report for synchronization
*/
Expand Down Expand Up @@ -319,6 +325,7 @@ export async function playStream(
width: video.width,
height: video.height,
frameRate: video.framerate_num / video.framerate_den,
readrateInitialBurst: undefined,
rtcpSenderReportEnabled: true,
forceChacha20Encryption: false
} satisfies PlayStreamOptions;
Expand All @@ -345,6 +352,11 @@ export async function playStream(
: defaultOptions.frameRate
),

readrateInitialBurst:
isFiniteNonZero(opts.readrateInitialBurst) && opts.readrateInitialBurst > 0
? opts.readrateInitialBurst
: defaultOptions.readrateInitialBurst,

rtcpSenderReportEnabled:
opts.rtcpSenderReportEnabled ?? defaultOptions.rtcpSenderReportEnabled,

Expand Down Expand Up @@ -389,6 +401,21 @@ export async function playStream(
audio.stream.pipe(aStream);
vStream.syncStream = aStream;
aStream.syncStream = vStream;

const burstTime = mergedOptions.readrateInitialBurst;
if (typeof burstTime === "number")
{
vStream.sync = aStream.sync = false;
vStream.noSleep = aStream.noSleep = true;
const stopBurst = (pts: number) => {
if (pts < burstTime * 1000)
return;
vStream.sync = aStream.sync = true;
vStream.noSleep = aStream.noSleep = false;
vStream.off("pts", stopBurst);
}
vStream.on("pts", stopBurst);
}
}
return new Promise<void>((resolve) => {
vStream.once("finish", () => {
Expand Down

0 comments on commit cfe8bde

Please sign in to comment.