enhance(backend): ビデオファイルにビデオトラックがあるかを確認するように

(cherry picked from commit 23d38a2d6492a2b24e9b2c031d66c3e8a5d382ef)
This commit is contained in:
kakkokari-gtyih 2024-03-12 21:50:46 +09:00
parent 5c1d86b796
commit e82ead49e3
2 changed files with 41 additions and 3 deletions

View file

@ -317,6 +317,27 @@ export class FileInfoService {
return mime; return mime;
} }
/**
*
* m4a, webmなど
*/
@bindThis
private hasVideoTrackOnVideoFile(path: string): Promise<boolean> {
return new Promise((resolve, reject) => {
try {
FFmpeg.ffprobe(path, (err, metadata) => {
if (err) {
resolve(true);
return;
}
resolve(metadata.streams.some((stream) => stream.codec_type === 'video'));
});
} catch (e) {
resolve(true);
}
});
}
/** /**
* Detect MIME Type and extension * Detect MIME Type and extension
*/ */
@ -339,6 +360,26 @@ export class FileInfoService {
return TYPE_SVG; return TYPE_SVG;
} }
if (type.mime.startsWith('video') && !(await this.hasVideoTrackOnVideoFile(path))) {
const newMime = `audio/${type.mime.split('/')[1]}`;
if (newMime === 'audio/mp4') {
return {
mime: 'audio/aac',
ext: 'm4a',
};
}
if (newMime === 'audio/webm') {
return {
mime: 'audio/webm',
ext: 'webm',
};
}
return {
mime: newMime,
ext: type.ext,
};
}
return { return {
mime: this.fixMime(type.mime), mime: this.fixMime(type.mime),
ext: type.ext, ext: type.ext,

View file

@ -323,8 +323,6 @@ describe('FileInfoService', () => {
}); });
}); });
/*
* video/webmとして検出されてしまう
test('WEBM AUDIO', async () => { test('WEBM AUDIO', async () => {
const path = `${resources}/kick_gaba7.webm`; const path = `${resources}/kick_gaba7.webm`;
const info = await fileInfoService.getFileInfo(path, { skipSensitiveDetection: true }) as any; const info = await fileInfoService.getFileInfo(path, { skipSensitiveDetection: true }) as any;
@ -344,6 +342,5 @@ describe('FileInfoService', () => {
}, },
}); });
}); });
*/
}); });
}); });