Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var fs = require('fs');
var MP4Box = require('mp4box');
if (process.argv.length < 3) {
console.log("usage: node mp4codec.js ");
return;
}
var mp4boxfile = MP4Box.createFile();
var stopParse = false;
mp4boxfile.onReady = function (info) {
var mime = 'video/mp4; codecs=\"';
for (var i = 0; i < info.tracks.length; i++) {
if (i !== 0) mime += ',';
mime+= info.tracks[i].codec;
}
mime += '\"';
console.log(mime);
stopParse = true;
}
var filePos = 0;
var filereader = fs.createReadStream(process.argv[2]);
filereader.on('readable', function () {
return new Promise(function(resolve, reject) {
var readBlock = readBlockFactory();
mp4boxFile = MP4Box.createFile(false);
var uintArr;
//Will store timing data to help analyse the extracted data
var timing = {};
mp4boxFile.onError = reject;
//When the data is ready, look for the right track
mp4boxFile.onReady = function(videoData) {
for (var i = 0; i < videoData.tracks.length; i++) {
//Find the metadata track. Collect Id and number of samples
if (videoData.tracks[i].codec == 'gpmd') {
trackId = videoData.tracks[i].id;
nb_samples = videoData.tracks[i].nb_samples;
timing.start = videoData.tracks[i].created;
} else if (videoData.tracks[i].type == 'video') {
var vid = videoData.tracks[i];
//Deduce framerate from video track