Vanilagy / mp4-muxer

MP4 multiplexer in pure TypeScript with support for WebCodecs API, video & audio.
https://vanilagy.github.io/mp4-muxer/demo
MIT License
434 stars 33 forks source link

Error: TS2322: Type '{ codec: string; width: number; height: number; }' is not assignable to type 'undefined'. #19

Closed AmitMY closed 1 year ago

AmitMY commented 1 year ago

The expected type comes from property 'video' which is declared here on type 'MuxerOptions<ArrayBufferTarget, undefined, undefined>'

Because now the default is undefined with no way of changing it: https://github.com/Vanilagy/mp4-muxer/blob/main/src/muxer.ts#L33-L36

Vanilagy commented 1 year ago

Can you show me your code that errors? How are you using muxer options?

AmitMY commented 1 year ago

This is only an error in 3.0.0

      const {Muxer, ArrayBufferTarget} = await import('mp4-muxer');
      this.videoType = 'mp4';
      this.muxer = new Muxer({
        target: new ArrayBufferTarget(),
        video: {
          codec: 'avc',
          width: image.width,
          height: image.height,
        },
      });
Vanilagy commented 1 year ago

Ah yes, I incorrectly used generics in the declaration file. I released a fix in v3.0.1, can you please verify?

AmitMY commented 1 year ago

Given your fix, it doesn't work as is.

It seems like I need to modify my definition to:

new Muxer<ArrayBufferTarget, VideoOptions>({

But I can't import it

image
Vanilagy commented 1 year ago

No you shouldn't have to update your definition, the generics are inferred from what you pass to the Muxer. What is the error now? From the above example, it seems like you're not passing fastStart, which is a required property since v3.

Vanilagy commented 1 year ago

This works for me in v3.0.1. Note how the second generic is properly inferred from what gets passed:

CleanShot 2023-10-30 at 12 46 36

AmitMY commented 1 year ago

with fastStart, there's no need for explicit typing. thanks!