diff --git a/common/src/ffmpeg-rebroadcast.ts b/common/src/ffmpeg-rebroadcast.ts index 67b960397..8c9bed12d 100644 --- a/common/src/ffmpeg-rebroadcast.ts +++ b/common/src/ffmpeg-rebroadcast.ts @@ -294,8 +294,8 @@ export async function startParserSession(ffmpegInput: FFmpegIn // tbh parsing stdout is super sketchy way of doing this. parseAudioCodec(cp).then(result => inputAudioCodec = result); - await parseVideoCodec(cp).then(result => inputVideoCodec = result); parseResolution(cp).then(result => inputVideoResolution = result); + await parseVideoCodec(cp).then(result => inputVideoCodec = result); return { sdp, @@ -307,8 +307,8 @@ export async function startParserSession(ffmpegInput: FFmpegIn }, get inputVideoResolution() { return { - width: parseInt(inputVideoResolution?.[1]), - height: parseInt(inputVideoResolution?.[2]), + width: parseInt(inputVideoResolution?.[2]), + height: parseInt(inputVideoResolution?.[3]), } }, get isActive() { return isActive }, diff --git a/common/src/stream-parser.ts b/common/src/stream-parser.ts index b28eab240..1ab26bf75 100644 --- a/common/src/stream-parser.ts +++ b/common/src/stream-parser.ts @@ -209,7 +209,7 @@ export function createFragmentedMp4Parser(options?: StreamParserOptions): Stream } export interface RawVideoParserOptions { - size?: { + size: { width: number, height: number }; @@ -232,10 +232,9 @@ export const PIXEL_FORMAT_RGB24: RawVideoPixelFormat = { computeLength: (width, height) => width * height * 3, } -export function createRawVideoParser(options?: RawVideoParserOptions): StreamParser { +export function createRawVideoParser(options: RawVideoParserOptions): StreamParser { const pixelFormat = options?.pixelFormat || PIXEL_FORMAT_YUV420P; let filter: string; - options = options || {}; const { size, everyNFrames } = options; if (size) { filter = `scale=${size.width}:${size.height}`; @@ -248,21 +247,28 @@ export function createRawVideoParser(options?: RawVideoParserOptions): StreamPar filter = filter + `select=not(mod(n\\,${everyNFrames}))` } + const inputArguments: string[] = []; + if (options.size) + inputArguments.push('-s', `${options.size.width}x${options.size.height}`); + + inputArguments.push('-pix_fmt', pixelFormat.name); return { + inputArguments, container: 'rawvideo', outputArguments: [ - ...(filter ? ['-vf', filter] : []), + '-s', `${options.size.width}x${options.size.height}`, '-an', '-vcodec', 'rawvideo', '-pix_fmt', pixelFormat.name, '-f', 'rawvideo', ], async *parse(socket: Duplex, width: number, height: number): AsyncGenerator { + width = size?.width || width; + height = size?.height || height + if (!width || !height) throw new Error("error parsing rawvideo, unknown width and height"); - width = size?.width || width; - height = size?.height || height const toRead = pixelFormat.computeLength(width, height); while (true) { const buffer = await readLength(socket, toRead);