How do I get HTML5 video codec information from JavaScript?

I want to know the video codec and mainly the audio codec used to encode HTML5 video because, for example, Firefox supports MP4 video, but on my Windows version if the sound is encoded with "sowt" the sound will not work. In this case, I can provide a WEBM source, but I have to know if there is a problem with the MP4 source.

I found this one , but this IE11 property is not yet implemented in other browsers.

What do you think? Is it possible?

Thanks in advance.

+4


source to share


2 answers


The details of the low-level codec are not provided via the media item. You can check if the browser can play a specific file using a method canPlayType()

with a mime-type / codec argument as an argument, but this is a generic request that won't give specific information about a specific file, just a (potential) browser capability.

The property audioTracks

you are referring to (this is also supported in Safari ) lists the available audio tracks in the file that the browser already has decoded, i.e. able to read and process. Track data is a more "semantic" type of description (track type (main, translation, ..), language, etc.), rather than anything about the encoding used for the original data.

The only way to detect this low-level information is to load the video file (or part of it) using XMLHttpRequest (comes with CORS requirements) or FileReader as a byte buffer (ArrayBuffer) and parse it manually. Possibility, but it provides many bugs.



Typically, when a browser skips the first choice and uses the secondary, third, etc., it means the browser cannot play that particular file, which means it has a problem with the file, but for that browser.

The best approach is to choose codecs that work with most browsers in one or more combinations, and always make sure the video is transferred to one of these formats directly, or at least converted to such a format.

+3


source


FFmpeg or mp4box will help you get the video codec. This article will help you understand more https://medium.com/@JackPu/how-js-get-video-codec-548a33cf7454



0


source







All Articles