Skip to content

🎥 Make videos programmatically with React

select the quality

Jonny Burgerf7b0ada33e53
diff --git a/packages/convert/app/components/ConvertUi.tsx b/packages/convert/app/components/ConvertUi.tsx
index 9ca60a75a0..0c5836a3d2 100644
--- a/packages/convert/app/components/ConvertUi.tsx
+++ b/packages/convert/app/components/ConvertUi.tsx
@@ -2,6 +2,7 @@ import {Button} from '@/components/ui/button';
import type {
Dimensions,
LogLevel,
+ M3uStream,
MediaParserAudioCodec,
MediaParserContainer,
MediaParserVideoCodec,
@@ -41,6 +42,7 @@ import {ConvertUiSection} from './ConvertUiSection';
import {ErrorState} from './ErrorState';
import {flipVideoFrame} from './flip-video';
import {getDefaultContainerForConversion} from './guess-codec-from-source';
+import {M3uStreamSelector} from './M3uStreamSelector';
import {MirrorComponents} from './MirrorComponents';
import {PauseResumeAndCancel} from './PauseResumeAndCancel';
import {ResizeUi} from './ResizeUi';
@@ -70,6 +72,7 @@ const ConvertUI = ({
videoThumbnailRef,
rotation,
dimensions,
+ m3uStreams,
}: {
readonly src: Source;
readonly setSrc: React.Dispatch<React.SetStateAction<Source | null>>;
@@ -83,6 +86,7 @@ const ConvertUI = ({
readonly rotation: number | null;
readonly inputContainer: MediaParserContainer | null;
readonly logLevel: LogLevel;
+ readonly m3uStreams: M3uStream[] | null;
readonly action: RouteAction;
readonly enableRotateOrMirror: RotateOrMirrorState;
readonly setEnableRotateOrMirror: React.Dispatch<
@@ -106,6 +110,7 @@ const ConvertUI = ({
>({});
const [state, setState] = useState<ConvertState>({type: 'idle'});
const [name, setName] = useState<string | null>(null);
+ const [selectedM3uId, setSelectedM3uId] = useState<number | null>(null);
const [enableConvert, setEnableConvert] = useState(() =>
isConvertEnabledByDefault(action),
);
@@ -261,6 +266,9 @@ const ConvertUI = ({
);
return operation;
},
+ selectM3uStream: ({streams}) => {
+ return selectedM3uId ?? streams[0].id;
+ },
// Remotion team can see usage on https://www.remotion.pro/projects/remotiondevconvert/
apiKey: 'rm_pub_9a996d341238eaa34e696b099968d8510420b9f6ba4aa0ee',
})
@@ -300,6 +308,7 @@ const ConvertUI = ({
enableConvert,
audioOperationSelection,
videoOperationSelection,
+ selectedM3uId,
]);
const dimissError = useCallback(() => {
@@ -450,6 +459,13 @@ const ConvertUI = ({
return (
<>
<div className="w-full gap-4 flex flex-col">
+ {m3uStreams ? (
+ <M3uStreamSelector
+ streams={m3uStreams}
+ selectedId={selectedM3uId}
+ setSelectedM3uId={setSelectedM3uId}
+ />
+ ) : null}
{order.map((section) => {
if (section === 'convert') {
return (
diff --git a/packages/convert/app/components/FileAvailable.tsx b/packages/convert/app/components/FileAvailable.tsx
index 2b37e4fa5c..01539eb421 100644
--- a/packages/convert/app/components/FileAvailable.tsx
+++ b/packages/convert/app/components/FileAvailable.tsx
@@ -93,6 +93,7 @@ export const FileAvailable: React.FC<{
>
<div className="gap-4">
<ConvertUI
+ m3uStreams={probeResult.m3u}
inputContainer={probeResult.container}
currentAudioCodec={probeResult.audioCodec ?? null}
currentVideoCodec={probeResult.videoCodec ?? null}
diff --git a/packages/convert/app/components/M3uStreamSelector.tsx b/packages/convert/app/components/M3uStreamSelector.tsx
new file mode 100644
index 0000000000..c2705ac3d3
--- /dev/null
+++ b/packages/convert/app/components/M3uStreamSelector.tsx
@@ -0,0 +1,48 @@
+import type {M3uStream} from '@remotion/media-parser';
+import React from 'react';
+import {Label} from './ui/label';
+import {
+ Select,
+ SelectContent,
+ SelectGroup,
+ SelectItem,
+ SelectTrigger,
+ SelectValue,
+} from './ui/select';
+
+export const M3uStreamSelector: React.FC<{
+ readonly streams: M3uStream[];
+ readonly selectedId: number | null;
+ readonly setSelectedM3uId: React.Dispatch<
+ React.SetStateAction<number | null>
+ >;
+}> = ({setSelectedM3uId, selectedId, streams}) => {
+ return (
+ <div className="mb-4">
+ <Label htmlFor="quality">Select quality</Label>
+ <Select
+ value={String(selectedId ?? streams[0].id)}
+ onValueChange={(v) => setSelectedM3uId(Number(v))}
+ >
+ <SelectTrigger id="quality">
+ <SelectValue placeholder="Select quality level" />
+ </SelectTrigger>
+ <SelectContent>
+ {streams.map((stream) => {
+ return (
+ <SelectGroup key={stream.id}>
+ <SelectItem value={String(stream.id)}>
+ {stream.resolution ? (
+ <div>
+ {stream.resolution?.width}x{stream.resolution?.height}
+ </div>
+ ) : null}
+ </SelectItem>
+ </SelectGroup>
+ );
+ })}
+ </SelectContent>
+ </Select>
+ </div>
+ );
+};
diff --git a/packages/convert/app/components/use-probe.ts b/packages/convert/app/components/use-probe.ts
index 92ef6f628d..bbcfd1031f 100644
--- a/packages/convert/app/components/use-probe.ts
+++ b/packages/convert/app/components/use-probe.ts
@@ -73,7 +73,6 @@ export const useProbe = ({
setMetadata(newMetadata);
},
onM3uStreams: (m) => {
- console.log(m);
setM3u(m);
},
onContainer(c) {
@@ -175,6 +174,7 @@ export const useProbe = ({
keyframes,
unrotatedDimensions,
images,
+ m3u,
};
}, [
tracks,
@@ -195,5 +195,6 @@ export const useProbe = ({
keyframes,
unrotatedDimensions,
images,
+ m3u,
]);
};
diff --git a/packages/media-parser/src/containers/m3u/get-streams.ts b/packages/media-parser/src/containers/m3u/get-streams.ts
index fde41f4ddc..d7a925ba20 100644
--- a/packages/media-parser/src/containers/m3u/get-streams.ts
+++ b/packages/media-parser/src/containers/m3u/get-streams.ts
@@ -53,6 +53,11 @@ export const getM3uStreams = (
}
}
+ // Maybe this is already a playlist
+ if (boxes.length === 0) {
+ return null;
+ }
+
const sorted = boxes.slice().sort((a, b) => {
const aResolution = a.resolution
? a.resolution.width * a.resolution.height
diff --git a/packages/webcodecs/src/can-copy-audio-track.ts b/packages/webcodecs/src/can-copy-audio-track.ts
index c480c88fbf..a6b9a816bd 100644
--- a/packages/webcodecs/src/can-copy-audio-track.ts
+++ b/packages/webcodecs/src/can-copy-audio-track.ts
@@ -20,9 +20,7 @@ export const canCopyAudioTrack = ({
if (outputContainer === 'mp4') {
return (
inputCodec === 'aac' &&
- (inputContainer === 'mp4' ||
- inputContainer === 'avi' ||
- inputContainer === 'm3u8')
+ (inputContainer === 'mp4' || inputContainer === 'avi')
);
}