Skip to content

🎥 Make videos programmatically with React

`@remotion/media`: Simplify HLS input creation using createInputFrom

Jonny Burger31e60d76b251
diff --git a/packages/media/src/create-input.ts b/packages/media/src/create-input.ts
index 8181f0e1fe..602131165c 100644
--- a/packages/media/src/create-input.ts
+++ b/packages/media/src/create-input.ts
@@ -1,20 +1,5 @@
-import type {UrlSourceOptions} from 'mediabunny';
-import {
- ALL_FORMATS,
- HLS_FORMATS,
- Input,
- PathedSource,
- UrlSource,
-} from 'mediabunny';
-
-export const isHlsSource = (src: string): boolean => {
- try {
- const url = new URL(src, 'http://placeholder');
- return url.pathname.toLowerCase().endsWith('.m3u8');
- } catch {
- return src.toLowerCase().endsWith('.m3u8');
- }
-};
+import type {CreateInputFromOptions} from 'mediabunny';
+import {ALL_FORMATS, createInputFrom} from 'mediabunny';
export const createInput = ({
src,
@@ -23,28 +8,10 @@ export const createInput = ({
}: {
src: string;
credentials: RequestCredentials | undefined;
- urlSourceOptions?: Partial<UrlSourceOptions>;
-}): Input => {
- const requestInit = credentials ? {credentials} : undefined;
- const sourceOptions: UrlSourceOptions | undefined =
- requestInit || urlSourceOptions
- ? {
- ...urlSourceOptions,
- ...(requestInit ? {requestInit} : undefined),
- }
- : undefined;
-
- if (isHlsSource(src)) {
- return new Input({
- source: new PathedSource(src, ({path}) => {
- return new UrlSource(path, sourceOptions);
- }),
- formats: HLS_FORMATS,
- });
- }
-
- return new Input({
- source: new UrlSource(src, sourceOptions),
- formats: ALL_FORMATS,
+ urlSourceOptions?: Partial<CreateInputFromOptions>;
+}) => {
+ return createInputFrom(src, ALL_FORMATS, {
+ ...urlSourceOptions,
+ ...(credentials ? {requestInit: {credentials}} : undefined),
});
};
diff --git a/packages/media/src/video-extraction/get-frames-since-keyframe.ts b/packages/media/src/video-extraction/get-frames-since-keyframe.ts
index 6f15a471cc..87f0d88b7d 100644
--- a/packages/media/src/video-extraction/get-frames-since-keyframe.ts
+++ b/packages/media/src/video-extraction/get-frames-since-keyframe.ts
@@ -1,4 +1,5 @@
-import type {Input, InputFormat, UrlSourceOptions} from 'mediabunny';
+import type {Input, InputFormat} from 'mediabunny';
+import type {CreateInputFromOptions} from 'mediabunny';
import {
AudioSampleSink,
EncodedPacketSink,
@@ -35,7 +36,7 @@ export type VideoSinkResult =
const getRetryDelay = (() => {
return null;
-}) satisfies UrlSourceOptions['getRetryDelay'];
+}) satisfies CreateInputFromOptions['getRetryDelay'];
const getFormatOrNullOrNetworkError = async (
input: Input,