npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mp4filechecker

v1.0.6

Published

Check details of an mp4 file, e.g. to determine if transcoding is required

Downloads

40,348

Readme

mp4filechecker

npm install mp4filechecker

Checks a File or Blob to determine if it is an mp4 file matching a particular codec and dimensions.

Usage:

import { checkMp4File } from 'mp4filechecker';

const file = fileOrBlob; // e.g. fileInput.files[0]

const options = {
  maxWidth: 1280,
  maxHeight: 720,
  supportedMimeTypes: ['video/mp4'],
  supportedVideoCodecs: [/^avc1\.42e0/, /^avc1\.4d40/, /^avc1\.6400/],
  supportedAudioCodecs: ['mp4a.40.2', 'mp4a.40.5'],
};

if (checkMp4File(file, options)) {
  // file matches the given options
}

Inspiration

I was initially trying to use ffmpeg.js to transcode the video in the browser to a desired resolution and level of compression when a user selects a video to upload (e.g. using a file input). This would alleviate the need to use server-side video compression/transcoding, or a potentially costly cloud transcoding service. Unfortunately using this method was too slow for my purposes, so the next idea I had was to use the browser to just detect if the video was already in an acceptable format (i.e. compressed using a well-supported codec and not too large in its dimensions). If the video was already acceptable, then the transcoding could be skipped. Only videos which did not meet these criteria would then be transcoded, ultimately reducing the processing costs of server-side/cloud transcoding.

After trawling github/stackoverflow for ideas, looking up information about browser support for various containers/codecs on Wikipedia, and playing with this helpful tool, I decided that (at the time of writing) there are only a few viable options for delivering video via the web:

  • Using MP4 with any of the AVC1/H.264 video codecs, and either the mp4a.40.2 or mp4a.40.5 audio codecs
  • Using WebM with the VP8 or VP9 video codec, and either the opus or vorbis audio codecs

(N.B. AV1 for both containers is also gaining popularity, but not as widely supported)

The main issue with WebM is that it's not supported on iOS/Safari (and pre-Edge Internet Explorer, for those to whom that still matters). This leaves MP4 as the only truely viable one-size-fits-all uploadable format for video files.

This library therefore targets the MP4 file, using the GPAC MP4Box JS port to parse the Mp4 file information, checking it against a list of sanctioned audio/video codecs, and ensuring the video's dimensions are within maximum bounds.

Given a video file passes this test, there can be some level of certainty that the video will not require transcoding for it to effectively and functionally be served on the web.