Vanilagy / mp4-muxer

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

avc1.7a1034 codec fails with error DOMException: Unsupported codec profile. #10

Closed magnet-clip closed 1 year ago

magnet-clip commented 1 year ago

Hi,

I am not sure whether this is related to mp4muxer or this is a generic browser constraint, but in Chrome I am getting an error when trying to record a video using avc1.7a1034 codec. Ultimately my goal is to record a video in yuv422 format, so I am trying this configuration.

I configure muxer as follows:

 muxer = new Muxer({
    target: new ArrayBufferTarget(),
    video: {
        codec: "avc",
        width: 1920,
        height: 1080,
    },
});

and VideoEncoder in the following way:

this.videoEncoder = new VideoEncoder({
    output: (chunk, meta) => {
        // console.log(chunk, meta);
        try {
            return this.muxer.addVideoChunk(chunk, meta); // <--------- ERROR "DOMException: Unsupported codec profile." IS THROWN IN HERE
        } catch (e) {
            console.error(e); 
        }
    },
    error: (e) => console.error(e),
});
this.videoEncoder.configure({
    codec: "avc1.7a1034",
    width: 1920,
    height: 1080,
    bitrate: 50e6,
    framerate: 25,
});

Are you aware of such issue, and whether there could be any fix for that?

0-mandrixx-0 commented 1 year ago

this is definitely a webcodec error. you can try to keep your profile (1st two digits) and change level to for example 33 instead of 34.

many profiles aren't supported yet, and the list depends on the device. some will be accepted but will crash later. the chromium guys don't want to maintain a list of implemented codecs in webcodecs, so you have to guess and try

I use this bit of code to check what I can do with a device. let me know if you find working codec strings that aren't in my list

static videoCodecs:any = ['avc1.420033','avc1.42001E','avc1.4D401E','hvc1.2.4.L153','vp8','vp9','vp09.00.10.08','avc1.640033','hvc1.1.6.H150.90','hev1.1.6.L120.90','av01.0.01M.08','av01.0.15M.10','hev1.1.6.L93.B0','hev1.2.4.L93.B0','hvc1.3.E.L93.B0','hvc1.4.10.L93.B0'];
    // crash ,'hvc1.1.6.H150.90','hev1.1.6.L120.90'
    // untested ,'hev1.1.6.L93.B0','hev1.2.4.L93.B0','hvc1.3.E.L93.B0','hvc1.4.10.L93.B0'
    // supported but nok : ,'av01.0.01M.08','av01.0.15M.10'
    static goodCodecs:Array<any>=new Array<any>();
    static checkVideoCodecs() {
        Util.videoCodecs.forEach(codec => {
            (async () => {
                try {
                    let config:VideoEncoderConfig = {
                        codec: codec,
                        width: 640,
                        height: 360,
                        framerate: 30,
                    };
                    Util.testVideoEncoder(config);
                } catch (e:any) {
                    console.log("CODEC "+codec+" UNKNOWN");
                }
            })();
        });
    }
    static testVideoEncoder(config:VideoEncoderConfig) {
        let videoEncoder:any = new window.VideoEncoder({
          output: (encodedChunk, config) => {},
          error: (err) => {
            console.log("err:",err);
          },
        });
        videoEncoder.configure(config);
        if (!Data.videoCodec) Data.videoCodec = config.codec;
        Util.goodCodecs.push(config.codec);
        console.log("CODEC IS SUPPORTED:",config.codec);
        videoEncoder.close();
    }
magnet-clip commented 1 year ago

Thank you for your suggestions, I believe I should close this one then