Change VideoSampleResource interface, validate return values, add more proper VideoSample.copyTo() logic, fix decoder/encoder color space issues

This commit is contained in:
Vanilagy
2026-05-08 19:37:41 +02:00
parent f5bd540863
commit ab9958234a
7 changed files with 831 additions and 654 deletions
+1 -11
View File
@@ -35,7 +35,6 @@ export class NodeAvVideoEncoder extends CustomVideoEncoder {
avCodec!: NodeAv.Codec;
codecContext: NodeAv.CodecContext | null = null;
lastBuffer: Buffer | null = null;
colorSpaceSet = false;
packetEmitted = false;
scaler: NodeAv.SoftwareScaleContext | null = null;
@@ -65,6 +64,7 @@ export class NodeAvVideoEncoder extends CustomVideoEncoder {
this.packet.alloc();
const codecId = CODEC_TO_CODEC_ID[this.codec];
assert(codecId !== undefined);
let codec: NodeAv.Codec | null = null;
if (this.config.hardwareAcceleration === 'prefer-software') {
@@ -203,15 +203,6 @@ export class NodeAvVideoEncoder extends CustomVideoEncoder {
this.frame.fromBuffer(this.lastBuffer);
}
if (!this.colorSpaceSet) {
this.codecContext.colorPrimaries = this.frame.colorPrimaries;
this.codecContext.colorTrc = this.frame.colorTrc;
this.codecContext.colorSpace = this.frame.colorSpace;
this.codecContext.colorRange = this.frame.colorRange;
this.colorSpaceSet = true;
}
let frameToEncode = this.frame;
const requiresScaler
@@ -550,7 +541,6 @@ export class NodeAvVideoEncoder extends CustomVideoEncoder {
}
this.packetEmitted = false;
this.colorSpaceSet = false;
}
close(): MaybePromise<void> {