Skip to content

🎥 Make videos programmatically with React

nice

Jonny Burger6057f95b7b93
diff --git a/packages/docs/docs/media-parser/foreign-file-types.mdx b/packages/docs/docs/media-parser/foreign-file-types.mdx
index 5dce719ecd..18d946d883 100644
--- a/packages/docs/docs/media-parser/foreign-file-types.mdx
+++ b/packages/docs/docs/media-parser/foreign-file-types.mdx
@@ -45,6 +45,9 @@ try {
An error if the image is a `png`, `jpeg`, `bmp` or `webp`.
+- `fileName`: The name of the file - from file name or `Content-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` or `webp`).
- `dimensions`: The dimensions of the image (`width` and `height`).
@@ -52,10 +55,22 @@ An error if the image is a `png`, `jpeg`, `bmp` or `webp`.
An error if the image is a GIF.
+- `fileName`: The name of the file - from file name or `Content-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 or `Content-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 or `Content-Disposition` header.
+- `sizeInBytes`: The size of the file in bytes.
+- `mimeType`: The MIME type of the file.
diff --git a/packages/media-parser/src/errors.ts b/packages/media-parser/src/errors.ts
index 01021bd3df..472e660d36 100644
--- a/packages/media-parser/src/errors.ts
+++ b/packages/media-parser/src/errors.ts
@@ -1,20 +1,24 @@
export class IsAGifError extends Error {
public mimeType: string | null;
public sizeInBytes: number | null;
+ public fileName: string | null;
constructor({
message,
mimeType,
sizeInBytes,
+ fileName,
}: {
message: string;
mimeType: string | null;
sizeInBytes: number | null;
+ fileName: string | null;
}) {
super(message);
- this.name = 'IsAGifError';
+ this.fileName = 'IsAGifError';
this.mimeType = mimeType;
this.sizeInBytes = sizeInBytes;
+ this.fileName = fileName;
if (Error.captureStackTrace) {
Error.captureStackTrace(this, IsAGifError);
@@ -30,6 +34,7 @@ export class IsAnImageError extends Error {
public dimensions: Dimensions | null;
public mimeType: string | null;
public sizeInBytes: number | null;
+ public fileName: string | null;
constructor({
dimensions,
@@ -37,12 +42,14 @@ export class IsAnImageError extends Error {
message,
mimeType,
sizeInBytes,
+ fileName,
}: {
message: string;
imageType: ImageType;
dimensions: Dimensions | null;
mimeType: string | null;
sizeInBytes: number | null;
+ fileName: string | null;
}) {
super(message);
this.name = 'IsAnImageError';
@@ -50,6 +57,7 @@ export class IsAnImageError extends Error {
this.dimensions = dimensions;
this.mimeType = mimeType;
this.sizeInBytes = sizeInBytes;
+ this.fileName = fileName;
if (Error.captureStackTrace) {
Error.captureStackTrace(this, IsAnImageError);
@@ -60,20 +68,24 @@ export class IsAnImageError extends Error {
export class IsAPdfError extends Error {
public mimeType: string | null;
public sizeInBytes: number | null;
+ public fileName: string | null;
constructor({
message,
mimeType,
sizeInBytes,
+ fileName,
}: {
message: string;
mimeType: string | null;
sizeInBytes: number | null;
+ fileName: string | null;
}) {
super(message);
this.name = 'IsAPdfError';
this.mimeType = mimeType;
this.sizeInBytes = sizeInBytes;
+ this.fileName = fileName;
if (Error.captureStackTrace) {
Error.captureStackTrace(this, IsAPdfError);
@@ -84,20 +96,24 @@ export class IsAPdfError extends Error {
export class IsAnUnsupportedFileTypeError extends Error {
public mimeType: string | null;
public sizeInBytes: number | null;
+ public fileName: string | null;
constructor({
message,
mimeType,
sizeInBytes,
+ fileName,
}: {
message: string;
mimeType: string | null;
sizeInBytes: number | null;
+ fileName: string | null;
}) {
super(message);
this.name = 'IsAnUnsupportedFileTypeError';
this.mimeType = mimeType;
this.sizeInBytes = sizeInBytes;
+ this.fileName = fileName;
if (Error.captureStackTrace) {
Error.captureStackTrace(this, IsAnUnsupportedFileTypeError);
diff --git a/packages/media-parser/src/parse-media.ts b/packages/media-parser/src/parse-media.ts
index 9d1fcd8944..3aed586599 100644
--- a/packages/media-parser/src/parse-media.ts
+++ b/packages/media-parser/src/parse-media.ts
@@ -151,6 +151,7 @@ export const parseMedia: ParseMedia = async ({
fields: fields ?? {},
mimeType: contentType,
contentLength,
+ name,
});
}
diff --git a/packages/media-parser/src/parse-video.ts b/packages/media-parser/src/parse-video.ts
index ce3d29e8cb..79bc92a030 100644
--- a/packages/media-parser/src/parse-video.ts
+++ b/packages/media-parser/src/parse-video.ts
@@ -41,6 +41,7 @@ export const parseVideo = ({
fields,
mimeType,
contentLength,
+ name,
}: {
iterator: BufferIterator;
options: ParserContext;
@@ -49,6 +50,7 @@ export const parseVideo = ({
fields: Options<ParseMediaFields>;
mimeType: string | null;
contentLength: number | null;
+ name: string | null;
}): Promise<ParseResult<Structure>> => {
if (iterator.bytesRemaining() === 0) {
return Promise.reject(new Error('no bytes'));
@@ -105,6 +107,7 @@ export const parseVideo = ({
message: 'GIF files are not yet supported',
mimeType,
sizeInBytes: contentLength,
+ fileName: name,
}),
);
}
@@ -115,6 +118,7 @@ export const parseVideo = ({
message: 'GIF files are not supported',
mimeType,
sizeInBytes: contentLength,
+ fileName: name,
}),
);
}
@@ -132,6 +136,7 @@ export const parseVideo = ({
dimensions: fileType.dimensions,
mimeType,
sizeInBytes: contentLength,
+ fileName: name,
}),
);
}
@@ -142,6 +147,7 @@ export const parseVideo = ({
message: 'Unknown file format',
mimeType,
sizeInBytes: contentLength,
+ fileName: name,
}),
);
}