Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MP4 video data is missing #2286

Open
1 task done
afuimApp opened this issue Nov 11, 2024 · 2 comments
Open
1 task done

MP4 video data is missing #2286

afuimApp opened this issue Nov 11, 2024 · 2 comments
Assignees
Labels
question Question, clarification, discussion

Comments

@afuimApp
Copy link

Has the question been asked before?

  • I have searched the existing issues

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.

@afuimApp afuimApp added the question Question, clarification, discussion label Nov 11, 2024
@afuimApp
Copy link
Author

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);
  });
}

@Borewit Borewit self-assigned this Nov 11, 2024
@Borewit
Copy link
Owner

Borewit commented Nov 11, 2024

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);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question, clarification, discussion
Projects
None yet
Development

No branches or pull requests

2 participants