Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting a video's codec in JavaScript

I'm working on desktop app based on Electron (i.e. Node.js and a Chrome browser shell crammed together), and one of its features will include loading arbitrary video files from the local filesystem.

A challenge I'm facing is that I won't know the codec used by the arbitrary video files. I can filter by file extension (i.e. .mp4, .webm, etc)... but MP4 files can use numerous codecs, which aren't obvious from the file extension. I don't really know that a video file is unsupported until the HTML5 video player comes up blank (and I'm not even sure how to programmatically detect when THIS happens).

I'm already using a loadedmetadata event handler to detect the video's dimensions, but it doesn't seem to expose information about the underlying codec.

Is there any way around this? I'm looking for Node.js packages that can identify codecs in the native "main" process, rather than letting the Chrome "renderer" process try detecting it at the browser level. However, all of the Node.js video packages that I'm seen rely on ffmpeg executables, which I can't easily bundle with my Electron app.

There are a million code samples for detecting which codecs your browser supports. But that's coming from the assumption that you're dealing with a known video file and an unknown browser. What about the reverse... when you have a guaranteed known browser, but an unknown video file?

like image 435
Steve Perkins Avatar asked May 26 '16 12:05

Steve Perkins


People also ask

How do I find the codec of a video?

To determine what codec was used with a specific file, play the file in the Player, if possible. While the file is playing, right-click the file in the library, and then select Properties. On the File tab, look at the Audio codec and Video codec sections.

How do I find the codec for a youtube video?

If using Windows, select "Tools" and then "Codec Information" This step will retrieve the same information as in the step for Mac users above.

What is codec in HTML?

The Codec Tag is another way to represent the codec used to encode a media file such as a video or music file. Usually, there is more information available for the codec used in a media file. One of them is the Codec Tag. The value for the Codec Tag usually consists of a string of numbers.


Video Answer


1 Answers

You can use mux.js to inspect the MP4 atoms inside the file. You'll need to load the file into a UInt8Array, then call muxjs.mp4.tools.inspect(bytes) to get a list of parsed atoms.

like image 57
Mike Griffith Avatar answered Oct 01 '22 02:10

Mike Griffith