Foreign file types
If you pass a file that is not one of the supported formats, parseMedia()
will throw an error.
Sometimes this error can contain useful information about the file type nonetheless.
This is useful if you allow users to upload an arbitrary file and want to get information about it with just one pass.
Get information about a video, or get the file type if it's not a videotsx
import {parseMedia ,IsAnImageError ,IsAGifError ,IsAPdfError ,IsAnUnsupportedFileTypeError ,IsAnUnsupportedAudioTypeError ,} from '@remotion/media-parser';try {awaitparseMedia ({src : 'https://example.com/my-video.png',fields : {},});} catch (e ) {if (e instanceofIsAnImageError ) {console .log ('The file is an image of format:',e .imageType ,'dimensions:',e .dimensions ,);} else if (e instanceofIsAGifError ) {console .log ('The file is a GIF');} else if (e instanceofIsAPdfError ) {console .log ('The file is a PDF');} else if (e instanceofIsAnUnsupportedAudioTypeError ) {console .log ('The file is an audio file of format:',e .audioType );} else if (e instanceofIsAnUnsupportedFileTypeError ) {console .log ('The file is of an unsupported type');}}
Get information about a video, or get the file type if it's not a videotsx
import {parseMedia ,IsAnImageError ,IsAGifError ,IsAPdfError ,IsAnUnsupportedFileTypeError ,IsAnUnsupportedAudioTypeError ,} from '@remotion/media-parser';try {awaitparseMedia ({src : 'https://example.com/my-video.png',fields : {},});} catch (e ) {if (e instanceofIsAnImageError ) {console .log ('The file is an image of format:',e .imageType ,'dimensions:',e .dimensions ,);} else if (e instanceofIsAGifError ) {console .log ('The file is a GIF');} else if (e instanceofIsAPdfError ) {console .log ('The file is a PDF');} else if (e instanceofIsAnUnsupportedAudioTypeError ) {console .log ('The file is an audio file of format:',e .audioType );} else if (e instanceofIsAnUnsupportedFileTypeError ) {console .log ('The file is of an unsupported type');}}
Available errors
IsAnImageError
An error if the image is a png
, jpeg
, bmp
or webp
.
fileName
: The name of the file - from file name orContent-Disposition
header.sizeInBytes
: The size of the file in bytes.mimeType
: The MIME type of the file.imageType
: The type of the image (png
,jpeg
,bmp
orwebp
).dimensions
: The dimensions of the image (width
andheight
).
IsAnUnsupportedAudioTypeError
An error if the file is an audio file that @remotion/media-parser
does not yet support.
fileName
: The name of the file - from file name orContent-Disposition
header.sizeInBytes
: The size of the file in bytes.mimeType
: The MIME type of the file.audioType
: The type of the audio file - one ofmp3
,wav
andaac
.
note
@remotion/media-parser
aims to support these audio formats in the future, in which case they will not throw an error but return audio tracks.
IsAGifError
An error if the image is a GIF.
fileName
: The name of the file - from file name orContent-Disposition
header.sizeInBytes
: The size of the file in bytes.mimeType
: The MIME type of the file.
IsAPdfError
An error if the file is a PDF.
fileName
: The name of the file - from file name orContent-Disposition
header.sizeInBytes
: The size of the file in bytes.mimeType
: The MIME type of the file.
IsAnUnsupportedFileTypeError
An error if the file is of a type that @remotion/media-parser
does not recognize.
fileName
: The name of the file - from file name orContent-Disposition
header.sizeInBytes
: The size of the file in bytes.mimeType
: The MIME type of the file.