@mediabunny/server 1.62.1 → 1.63.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mediabunny/server",
3
3
  "author": "Vanilagy",
4
- "version": "1.62.1",
4
+ "version": "1.63.0",
5
5
  "description": "Adds full video and audio decoder and encoder support to Mediabunny for use in server-side environments (Node, Bun, Deno). Based on NodeAV.",
6
6
  "main": "./dist/bundles/mediabunny-server.cjs",
7
7
  "module": "./dist/bundles/mediabunny-server.mjs",
@@ -35,7 +35,7 @@
35
35
  },
36
36
  "dependencies": {
37
37
  "node-av": "^6.0.0",
38
- "@mediabunny/prores": "^1.62.1"
38
+ "@mediabunny/prores": "^1.63.0"
39
39
  },
40
40
  "peerDependencies": {
41
41
  "mediabunny": "^1.45.0"
@@ -49,6 +49,8 @@ export class NodeAvAudioDecoder extends CustomAudioDecoder {
49
49
  codecContext.sampleRate = this.config.sampleRate;
50
50
  codecContext.channelLayout = getChannelLayout(this.config.numberOfChannels);
51
51
  codecContext.timeBase = new NodeAv.Rational(1, this.config.sampleRate);
52
+ // Without this, leading samples are discarded (like Opus pre-skip) without advancing the frame timestamp
53
+ codecContext.pktTimebase = new NodeAv.Rational(1, this.config.sampleRate);
52
54
  codecContext.codecType = NodeAv.AVMEDIA_TYPE_AUDIO;
53
55
  codecContext.codecId = codecId;
54
56
  codecContext.extraData = this.config.description
@@ -40,8 +40,6 @@ export class NodeAvAudioEncoder extends CustomAudioEncoder {
40
40
  resampler: NodeAv.SoftwareResampleContext | null = null;
41
41
  dstFrame: NodeAv.Frame | null = null;
42
42
  avCodec!: NodeAv.Codec;
43
- firstExpectedTimestamp: number | null = null;
44
- outputTimestampOffset = 0;
45
43
 
46
44
  inputParametersKey: string | null = null;
47
45
  resamplerInputSampleRate: number | null = null;
@@ -143,8 +141,6 @@ export class NodeAvAudioEncoder extends CustomAudioEncoder {
143
141
  assert(this.codecContext);
144
142
  }
145
143
 
146
- this.firstExpectedTimestamp ??= audioSample.timestamp;
147
-
148
144
  if (audioSample._data instanceof AvFrameAudioSampleResource) {
149
145
  // Release any buffers still referenced from the previous encode before reffing the new frame, otherwise
150
146
  // av_frame_ref leaks them
@@ -261,14 +257,13 @@ export class NodeAvAudioEncoder extends CustomAudioEncoder {
261
257
 
262
258
  receivePacket(ret: number) {
263
259
  assert(this.codecContext);
264
- assert(this.firstExpectedTimestamp !== null);
265
260
  NodeAv.FFmpegError.throwIfError(ret, 'Receive packet');
266
261
 
267
262
  if (!this.packet.data) {
268
263
  return;
269
264
  }
270
265
 
271
- let timestamp = Number(this.packet.pts) / this.codecContext.sampleRate;
266
+ const timestamp = Number(this.packet.pts) / this.codecContext.sampleRate;
272
267
  const duration = Number(this.packet.duration) / this.codecContext.sampleRate;
273
268
 
274
269
  let data: Uint8Array = this.packet.data;
@@ -277,11 +272,6 @@ export class NodeAvAudioEncoder extends CustomAudioEncoder {
277
272
  if (this.packetEmitted) {
278
273
  metadata = {};
279
274
  } else {
280
- // To compensate for any negative timestamp things that FFmpeg might do. It does these for a reason, to
281
- // indicate encoder delay, but the notion of this is not yet supported in Mediabunny. Yes, this technically
282
- // introduces audio sync drift.
283
- this.outputTimestampOffset = Math.max(this.firstExpectedTimestamp - timestamp, 0);
284
-
285
275
  const codecString = this.config.codec;
286
276
  let description = this.codecContext.extraData
287
277
  ? toUint8Array(this.codecContext.extraData)
@@ -348,8 +338,6 @@ export class NodeAvAudioEncoder extends CustomAudioEncoder {
348
338
  data = final;
349
339
  }
350
340
 
351
- timestamp += this.outputTimestampOffset;
352
-
353
341
  const packet = new EncodedPacket(
354
342
  data,
355
343
  'key',
@@ -391,8 +379,6 @@ export class NodeAvAudioEncoder extends CustomAudioEncoder {
391
379
  this.codecContext.freeContext();
392
380
  this.codecContext = null;
393
381
  this.packetEmitted = false;
394
- this.firstExpectedTimestamp = null;
395
- this.outputTimestampOffset = 0;
396
382
  this.adtsHeaderTemplate = null;
397
383
 
398
384
  this.resampler?.free();