-
-
Save czaux/3af94d8f867b730be2fd265b0c0380c1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const fs = require('fs'); | |
const fsp = fs.promises; | |
const MediaInfo = require('mediainfo.js'); | |
const path = require('path'); | |
async function readMediaFile(filePath) { | |
let fileHandle; | |
let mediainfo; | |
try { | |
fileHandle = await fsp.open(filePath, 'r'); | |
mediainfo = await MediaInfo({ chunkSize: 1024*1024, format: 'JSON', cover_data: true }); | |
const getSize = async () => (await fileHandle.stat()).size | |
const readChunk = async (size, offset) => { | |
const buffer = new Uint8Array(size) | |
await fileHandle.read(buffer, 0, size, offset) | |
return buffer | |
} | |
const result = await mediainfo.analyzeData(getSize, readChunk); | |
console.log(result) | |
} catch (error) { | |
console.error(error) | |
} finally { | |
fileHandle && (await fileHandle.close()) | |
mediainfo && mediainfo.close() | |
} | |
} | |
module.exports.readMediaFile = readMediaFile; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment