0

I want to extract video track's codec string from a webm video in javascript and pass it to browser's VideDecoder configure method to decode this video.

For example: If the codec of video track in webm video is V_VP9 in the EBML formatted file but how do I extract the whole string like this 'vp09.01.20.08.01'.

So to summarise I want a codec string of video track from the webm video file in javascript.

I tried setting only 'vp09' into VideoDecoder configure but this is giving error as codec string is ambiguous.

1 Answers1

0

You may use the MediaSource web API

The MediaSource interface of the Media Source Extensions API represents a source of media data for an HTMLMediaElement object. A MediaSource object can be attached to a HTMLMediaElement to be played in the user agent.

Then the API has a sourceopen event that you can listen to, as per doc here.

Fired when the MediaSource instance has been opened by a media element and is ready for data to be appended to the SourceBuffer objects in sourceBuffers.

I would start writing my JS code from one of the Mozilla web doc examples here, specifying your specific webm codec, and building from there.

const video = document.querySelector("video");
const assetURL = "frag_bunny.mp4";
// Need to be specific for Blink regarding codecs
// ./mp4info frag_bunny.mp4 | grep Codec
const mimeCodec = 'video/mp4; codecs="avc1.42E01E, mp4a.40.2"';
let mediaSource;

if ("MediaSource" in window && MediaSource.isTypeSupported(mimeCodec)) {
  mediaSource = getMediaSource();
  console.log(mediaSource.readyState); // closed
  video.src = URL.createObjectURL(mediaSource);
  mediaSource.addEventListener("sourceopen", sourceOpen);
} else {
  console.error("Unsupported MIME type or codec: ", mimeCodec);
}
Marc
  • 2,183
  • 2
  • 11
  • 16