Skip to content

Commit 42c777d

Browse files
committed
Don't count still images in audio files as a video streams
1 parent 52cbe93 commit 42c777d

File tree

2 files changed

+39
-17
lines changed

2 files changed

+39
-17
lines changed

app/support/media-files/detect.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@ import { open } from 'fs/promises';
22

33
import { spawnAsync } from '../spawn-async';
44

5-
import { AvcStream, FfprobeResult, H264Info, MediaInfo, MediaInfoVideo } from './types';
5+
import {
6+
AvcStream,
7+
FfprobeResult,
8+
H264Info,
9+
MediaInfo,
10+
MediaInfoVideo,
11+
VideoStream,
12+
} from './types';
613
import { addFileExtension } from './file-ext';
714

815
export async function detectMediaType(
@@ -64,7 +71,13 @@ export async function detectMediaType(
6471
const { format, streams } = await runFfprobe(localFilePath);
6572
const fmt = format.format_name.split(',')[0].toLowerCase();
6673

67-
const videoStream = streams.find((s) => s.codec_type === 'video');
74+
const videoStream = streams.find(
75+
(s) =>
76+
s.codec_type === 'video' &&
77+
// And not an album cover or other static image
78+
s.disposition.attached_pic !== 1 &&
79+
s.disposition.still_image !== 1,
80+
) as VideoStream | undefined;
6881
const audioStream = streams.find((s) => s.codec_type === 'audio');
6982

7083
if (videoStream && format.duration) {

app/support/media-files/types.ts

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -88,21 +88,30 @@ export type FilesToUpload = { [variant: string]: { path: string; ext: string } }
8888
export type VisualPreviews = { [variant: string]: { w: number; h: number; ext: string } };
8989
export type NonVisualPreviews = { [variant: string]: { ext: string } };
9090

91-
export type Stream = { codec_name: string } & (
92-
| {
93-
codec_type: 'video';
94-
width: number;
95-
height: number;
96-
nb_frames: string;
97-
side_data_list?: Record<string, string | number>[];
98-
is_avc?: 'true' | 'false';
99-
}
100-
| {
101-
codec_type: 'audio';
102-
}
103-
);
104-
105-
export type AvcStream = Stream & {
91+
type CommonStream = {
92+
codec_name: string;
93+
disposition: {
94+
attached_pic: 1 | 0;
95+
still_image: 1 | 0;
96+
};
97+
};
98+
99+
export type VideoStream = CommonStream & {
100+
codec_type: 'video';
101+
width: number;
102+
height: number;
103+
nb_frames: string;
104+
side_data_list?: Record<string, string | number>[];
105+
is_avc?: 'true' | 'false';
106+
};
107+
108+
export type AudioStream = CommonStream & {
109+
codec_type: 'audio';
110+
};
111+
112+
export type Stream = VideoStream | AudioStream;
113+
114+
export type AvcStream = VideoStream & {
106115
is_avc: 'true';
107116
profile: string;
108117
level: number;

0 commit comments

Comments
 (0)