admin管理员组

文章数量:1395381

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 es 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 ing 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?

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 es 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 ing 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?

Share Improve this question edited May 26, 2016 at 12:43 Steve Perkins asked May 26, 2016 at 12:37 Steve PerkinsSteve Perkins 11.9k19 gold badges67 silver badges98 bronze badges 1
  • 1 ".. which I can't easily bundle with my Electron app" — you can use npmjs./package/ffbinaries which will download the binary matching the user's platform. So you don't have to bundle anything. – Michael Commented Apr 23, 2017 at 16:14
Add a ment  | 

2 Answers 2

Reset to default 2

Easiest is to use mux.js as follows muxjs.mp4.probe.tracks(e). That returns you an array of the tracks.

Example output:

[
  {
    "id": 1,
    "type": "video",
    "codec": "avc1.64101e",
    "timescale": 12288
  },
  {
    "id": 2,
    "type": "audio",
    "codec": "mp4a.40.2",
    "timescale": 44100
  }
]

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.

本文标签: nodejsDetecting a video39s codec in JavaScriptStack Overflow