外来文件类型
如果你传递的文件不是支持的格式之一,parseMedia() 将抛出错误。
尽管如此,有时这个错误仍可能包含关于文件类型的有用信息。
🌐 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 videoimport {parseMedia ,IsAnImageError ,IsAPdfError ,IsAnUnsupportedFileTypeError } 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 instanceofIsAPdfError ) {console .log ('The file is a PDF'); } else if (e instanceofIsAnUnsupportedFileTypeError ) {console .log ('The file is of an unsupported type'); } }
可用错误
🌐 Available errors
IsAnImageError
如果图片是 png、jpeg、bmp、gif 或 webp,则会出现错误。
🌐 An error if the image is a png, jpeg, bmp, gif or webp.
fileName:文件的名称 - 来自文件名或Content-Disposition头部。sizeInBytes:文件的字节大小。mimeType:文件的 MIME 类型。imageType:图片的类型(png、jpeg、bmp、gif或webp)。dimensions:图片的尺寸(width和height)。
IsAPdfError
如果文件是 PDF,则会出错。
🌐 An error if the file is a PDF.
fileName:文件的名称 - 来自文件名或Content-Disposition头部。sizeInBytes:文件的字节大小。mimeType:文件的 MIME 类型。
IsAnUnsupportedFileTypeError
如果文件类型是 @remotion/media-parser 无法识别的类型,则会出现错误。
🌐 An error if the file is of a type that @remotion/media-parser does not recognize.
fileName:文件的名称 - 来自文件名或Content-Disposition头部。sizeInBytes:文件的字节大小。mimeType:文件的 MIME 类型。