Open afuimApp opened 2 weeks ago
i mange to check if video/mp4
is video by this code:
function isVideoFile(file: File): Promise<boolean> {
return new Promise((resolve, reject) => {
const videoElement = document.createElement('video');
videoElement.preload = 'metadata';
videoElement.onloadedmetadata = () => {
resolve(videoElement.videoHeight > 0);
};
videoElement.onerror = () => {
reject(new Error('Unable to determine if the file is a video.'));
};
videoElement.src = URL.createObjectURL(file);
});
}
I am not sure if this works for every video, but this will at least detect some video's:
const metadata = await mm.parseFile(filePath);
const isVideo = typeof metadata.common.hdVideo !== 'undefined';
There are probably better ways to detect if the MP4 is a video file, may on the presence of the moov
atom.
Ideally this should work as well, but it does not. There is definitely room for improvement/
const hasVideoTrack = metadata .format.trackInfo.find(trackInfo => trackInfo.type === TrackType.video);
Has the question been asked before?
Question
First of all, thank you very much for the good work you did here. Excellent library.
I use the library for 2 things:
1 - Extract background image from audio files. 2 - Check if mp4 file is video or audio.
I use the
parseBlob
function.My user uploads a file, before I upload it, in the browser I check the file type according to its mimeType, and according to the file type I upload it to a different server, video to another server and audio to another server.
My problem is with
video/mp4
type files that are sometimes only video and sometimes only audio.I saw in the library that you can get details about video in the object
trackInfo.video?: IVideoTrack
but no matter what file, with or without video I don't get this information.I would be happy to help.