gpac / mp4box.js

JavaScript version of GPAC's MP4Box tool
https://gpac.github.io/mp4box.js/
BSD 3-Clause "New" or "Revised" License
1.92k stars 325 forks source link

Windows Media Player doesn't reproduce audio from file that was created with mp4box library #342

Open AlexMixilab opened 1 year ago

AlexMixilab commented 1 year ago

I am using the mp4box library to create a media file that includes video and audio tracks. I have set up my audio encoder output callback using the following code: `if (encodingAudioTrack === null) { let encodingAudioTrackOptions = { timescale: this.timescale, samplerate: this.options.audioConfig?.sampleRate, channel_count: this.options.audioConfig?.numberOfChannels, samplesize: 16, hdlr: 'soun', name: 'SoundHandler', type: 'mp4a', brands: ['mp42', 'mp41', 'isom'], } encodingAudioTrack = this.file.addTrack(encodingAudioTrackOptions); }

if (this.previousEncodedAudioChunk) { let ab = new ArrayBuffer(this.previousEncodedAudioChunk.byteLength); this.previousEncodedAudioChunk.copyTo(ab); const sampleDuration = chunk.timestamp - this.previousEncodedAudioChunk.timestamp; this.file.addSample(encodingAudioTrack, ab, { dts: this.audioSampleTimestamp, cts: this.audioSampleTimestamp, duration: sampleDuration, }); this.audioChunkCount++; this.audioSampleTimestamp = this.audioSampleTimestamp + (sampleDuration ?? 0); }`

This is the config for AudioEncoder from WebCodec API: audioEncoderConfig = { codec: 'mp4a.40.2', sampleRate: combinedStream.getAudioTracks()[0].getSettings().sampleRate ?? 0, numberOfChannels: combinedStream.getAudioTracks()[0].getSettings().channelCount ?? 0, bitrate: 128_000, }

However, when I save the created file and launch it with Windows 10 Media Player or Movies & TV, the audio doesn't play. MPC_HC Player, on the other hand, opens the file correctly. I noticed that when I check the info with MediaInfo tool, the codec identifier is mp4a instead of mp4a.40.2 that was set.

Am I missing some details or did I set something wrong? I appreciate any help.

hughfenghen commented 1 year ago

@AlexMixilab FYI https://github.com/gpac/mp4box.js/issues/341