Skip to content

🎥 Make videos programmatically with React

remotion.dev/convert: hide crop option for audio-only convert inputs (#8529)

pupuking723cede3761f0d2
diff --git a/packages/convert/app/components/ConvertUi.tsx b/packages/convert/app/components/ConvertUi.tsx
index 13157fd4b8..e1551384de 100644
--- a/packages/convert/app/components/ConvertUi.tsx
+++ b/packages/convert/app/components/ConvertUi.tsx
@@ -19,7 +19,11 @@ import type {
ConvertSections,
RotateOrMirrorOrCropState,
} from '~/lib/default-ui';
-import {getOrderOfSections, isConvertEnabledByDefault} from '~/lib/default-ui';
+import {
+ getOrderOfSections,
+ isConvertEnabledByDefault,
+ isVideoOnlySection,
+} from '~/lib/default-ui';
import {getNewName} from '~/lib/generate-new-name';
import {
getActualAudioOperation,
@@ -594,6 +598,10 @@ const ConvertUI = ({
<>
<div className="w-full gap-4 flex flex-col">
{order.map((section) => {
+ if (inputIsAudioExclusively && isVideoOnlySection(section)) {
+ return null;
+ }
+
if (section === 'convert') {
return (
<div key="convert">
@@ -630,10 +638,6 @@ const ConvertUI = ({
}
if (section === 'mirror') {
- if (inputIsAudioExclusively) {
- return null;
- }
-
return (
<div key="mirror">
<ConvertUiSection
@@ -656,10 +660,6 @@ const ConvertUI = ({
}
if (section === 'rotate') {
- if (inputIsAudioExclusively) {
- return null;
- }
-
return (
<div key="rotate">
<ConvertUiSection
@@ -719,10 +719,6 @@ const ConvertUI = ({
}
if (section === 'resize') {
- if (inputIsAudioExclusively) {
- return null;
- }
-
return (
<div key="resize">
<ConvertUiSection
diff --git a/packages/convert/app/lib/default-ui.ts b/packages/convert/app/lib/default-ui.ts
index f0f589dd9d..8f8c67440a 100644
--- a/packages/convert/app/lib/default-ui.ts
+++ b/packages/convert/app/lib/default-ui.ts
@@ -136,6 +136,23 @@ export type ConvertSections =
| 'crop'
| 'resample';
+export const isVideoOnlySection = (section: ConvertSections): boolean => {
+ if (
+ section === 'rotate' ||
+ section === 'mirror' ||
+ section === 'resize' ||
+ section === 'crop'
+ ) {
+ return true;
+ }
+
+ if (section === 'convert' || section === 'resample') {
+ return false;
+ }
+
+ throw new Error(section satisfies never);
+};
+
export const getOrderOfSections = (
action: RouteAction,
): {[key in ConvertSections]: number} => {
diff --git a/packages/convert/test/default-ui.test.ts b/packages/convert/test/default-ui.test.ts
new file mode 100644
index 0000000000..523febd418
--- /dev/null
+++ b/packages/convert/test/default-ui.test.ts
@@ -0,0 +1,17 @@
+import {expect, test} from 'bun:test';
+import {isVideoOnlySection} from '../app/lib/default-ui';
+
+test('treats crop as a video-only operation section', () => {
+ expect(isVideoOnlySection('crop')).toBe(true);
+});
+
+test('treats rotate, mirror, and resize as video-only operation sections', () => {
+ expect(isVideoOnlySection('rotate')).toBe(true);
+ expect(isVideoOnlySection('mirror')).toBe(true);
+ expect(isVideoOnlySection('resize')).toBe(true);
+});
+
+test('keeps conversion and resampling available for audio-only files', () => {
+ expect(isVideoOnlySection('convert')).toBe(false);
+ expect(isVideoOnlySection('resample')).toBe(false);
+});