Skip to content

🎥 Make videos programmatically with React

fix duration display

Jonny Burger9c69a2962b71
diff --git a/packages/convert/app/components/ContainerOverview.tsx b/packages/convert/app/components/ContainerOverview.tsx
index b6a2fb188a..9c0755e96e 100644
--- a/packages/convert/app/components/ContainerOverview.tsx
+++ b/packages/convert/app/components/ContainerOverview.tsx
@@ -16,7 +16,7 @@ import {Skeleton} from './ui/skeleton';
export const ContainerOverview: React.FC<{
readonly dimensions: Dimensions | null;
- readonly durationInSeconds: number | null;
+ readonly durationInSeconds: number | null | undefined;
readonly videoCodec: MediaParserVideoCodec | null;
readonly audioCodec: MediaParserAudioCodec | null | undefined;
readonly size: number | null;
@@ -63,14 +63,13 @@ export const ContainerOverview: React.FC<{
Duration
</TableCell>
<TableCell className="text-right">
- {
- // TODO: For display1687984009979.webm, this does not get displayed
- durationInSeconds === null ? (
- <Skeleton className="h-3 w-[100px] inline-block" />
- ) : (
- <>{formatSeconds(durationInSeconds)}</>
- )
- }
+ {durationInSeconds === undefined ? (
+ <Skeleton className="h-3 w-[100px] inline-block" />
+ ) : durationInSeconds === null ? (
+ <span>N/A</span>
+ ) : (
+ <>{formatSeconds(durationInSeconds)}</>
+ )}
</TableCell>
</TableRow>
<TableRow>
diff --git a/packages/convert/app/components/use-probe.ts b/packages/convert/app/components/use-probe.ts
index df2acf782d..13cf17697e 100644
--- a/packages/convert/app/components/use-probe.ts
+++ b/packages/convert/app/components/use-probe.ts
@@ -30,9 +30,9 @@ export const useProbe = ({
MediaParserAudioCodec | null | undefined
>(undefined);
const [fps, setFps] = useState<number | null | undefined>(undefined);
- const [durationInSeconds, setDurationInSeconds] = useState<number | null>(
- null,
- );
+ const [durationInSeconds, setDurationInSeconds] = useState<
+ number | null | undefined
+ >(undefined);
const [dimensions, setDimensions] = useState<Dimensions | null>(null);
const [name, setName] = useState<string | null>(null);
const [videoCodec, setVideoCodec] = useState<MediaParserVideoCodec | null>(
diff --git a/packages/media-parser/src/get-duration.ts b/packages/media-parser/src/get-duration.ts
index 60b0703170..cd29e8675d 100644
--- a/packages/media-parser/src/get-duration.ts
+++ b/packages/media-parser/src/get-duration.ts
@@ -7,7 +7,7 @@ import {
} from './boxes/iso-base-media/traversal';
import {getStrhBox, getStrlBoxes} from './boxes/riff/traversal';
import type {DurationSegment} from './boxes/webm/segments/all-segments';
-import {getTracks} from './get-tracks';
+import {getTracks, hasTracks} from './get-tracks';
import type {
AnySegment,
IsoBaseMediaStructure,
@@ -142,10 +142,5 @@ export const hasDuration = (
structure: Structure,
parserState: ParserState,
): boolean => {
- try {
- const duration = getDuration(structure, parserState);
- return getDuration(structure, parserState) !== null && duration !== 0;
- } catch {
- return false;
- }
+ return hasTracks(structure, parserState);
};