Skip to content

🎥 Make videos programmatically with React

remotion.dev/convert: Load a video from a URL

Jonny Burgerb5028280170b
diff --git a/packages/convert/app/components/AlternativePickFileOptions.tsx b/packages/convert/app/components/AlternativePickFileOptions.tsx
new file mode 100644
index 0000000000..500362f07f
--- /dev/null
+++ b/packages/convert/app/components/AlternativePickFileOptions.tsx
@@ -0,0 +1,94 @@
+import React, {useCallback, useMemo} from 'react';
+import {Button} from './ui/button';
+import {
+ Dialog,
+ DialogContent,
+ DialogDescription,
+ DialogHeader,
+ DialogTitle,
+} from './ui/dialog';
+import {Input} from './ui/input';
+
+export const AlternativePickFileOptions: React.FC<{
+ readonly onSampleFile: () => void;
+}> = ({onSampleFile}) => {
+ const [open, setOpen] = React.useState(false);
+ const [value, setValue] = React.useState('');
+
+ const onOpenChange = React.useCallback(() => {
+ setOpen((prev) => !prev);
+ }, []);
+
+ const onOpenUrl = React.useCallback(() => {
+ setOpen(true);
+ }, []);
+
+ const isValid = useMemo(() => {
+ try {
+ // eslint-disable-next-line no-new
+ new URL(value);
+ return true;
+ } catch {
+ return false;
+ }
+ }, [value]);
+
+ const set = useCallback(() => {
+ const currentUrl = new URL(window.location.href);
+ currentUrl.searchParams.set('url', value);
+ window.location.href = currentUrl.toString();
+ }, [value]);
+
+ const onKeydown = useCallback(
+ (e: React.KeyboardEvent<HTMLInputElement>) => {
+ if (!isValid) {
+ return;
+ }
+
+ if (e.key === 'Enter') {
+ set();
+ }
+ },
+ [isValid, set],
+ );
+
+ return (
+ <div>
+ <a
+ className="font-brand text-brand cursor cursor-pointer hover:underline"
+ onClick={onSampleFile}
+ >
+ Use a sample file
+ </a>
+ <div className="w-4" />
+ <a
+ className="font-brand text-brand cursor cursor-pointer hover:underline"
+ onClick={onOpenUrl}
+ >
+ Load from URL
+ </a>
+ <Dialog open={open} onOpenChange={onOpenChange}>
+ <DialogContent>
+ <DialogHeader>
+ <DialogTitle className="font-brand">Load from URL</DialogTitle>
+ <div className="h-1" />
+ <DialogDescription>
+ The file must support being loaded on this domain.
+ </DialogDescription>
+ <div className="h-2" />
+ <Input
+ onKeyDown={onKeydown}
+ value={value}
+ onChange={(e) => setValue(e.target.value)}
+ placeholder="For example: https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8"
+ />
+ <div className="h-2" />
+ <Button disabled={!isValid} variant="brand" onClick={set}>
+ Load
+ </Button>
+ </DialogHeader>
+ </DialogContent>
+ </Dialog>
+ </div>
+ );
+};
diff --git a/packages/convert/app/components/PickFile.tsx b/packages/convert/app/components/PickFile.tsx
index 84001bb1cd..8e843b5239 100644
--- a/packages/convert/app/components/PickFile.tsx
+++ b/packages/convert/app/components/PickFile.tsx
@@ -1,6 +1,7 @@
import React, {useCallback} from 'react';
import {SAMPLE_FILE} from '~/lib/config';
import type {Source} from '~/lib/convert-state';
+import {AlternativePickFileOptions} from './AlternativePickFileOptions';
import {DropFileBox} from './DropFileBox';
import {TextMarkLogo} from './TextMarkLogo';
import {WhyRemotionConvert} from './WhyRemotionConvert';
@@ -50,12 +51,7 @@ export const PickFile: React.FC<{
<div className="h-4" />
<div className="font-brand">or </div>
<div className="h-4" />
- <a
- className="font-brand text-brand cursor cursor-pointer hover:underline"
- onClick={onSampleFile}
- >
- Use a sample file
- </a>
+ <AlternativePickFileOptions onSampleFile={onSampleFile} />
<div className="h-10" />
</div>
<div className="w-full bg-white border-t-2 border-black">