1
0
mirror of https://github.com/immich-app/immich.git synced 2024-12-25 10:43:13 +02:00

feat: M2TS (#2896)

Support the Blu-ray disc Audio-Video (BDAV) MPEG-2 Transport Stream (M2TS) format.

https://en.wikipedia.org/wiki/.m2ts

Fixes: #2350
This commit is contained in:
Thomas 2023-06-21 19:50:12 +01:00 committed by GitHub
parent c03d8e312a
commit 069c68bfe4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 79 additions and 44 deletions

View File

@ -137,6 +137,12 @@ class FileHelper {
case 'jxl': case 'jxl':
return {"type": "image", "subType": "jxl"}; return {"type": "image", "subType": "jxl"};
case 'mts':
return {"type": "video", "subType": "mp2t"};
case 'm2ts':
return {"type": "video", "subType": "mp2t"};
default: default:
return {"type": "unsupport", "subType": "unsupport"}; return {"type": "unsupport", "subType": "unsupport"};
} }

View File

@ -51,7 +51,6 @@ describe('assetUploadOption', () => {
for (const { mimetype, extension } of [ for (const { mimetype, extension } of [
{ mimetype: 'image/avif', extension: 'avif' }, { mimetype: 'image/avif', extension: 'avif' },
{ mimetype: 'image/dng', extension: 'dng' },
{ mimetype: 'image/gif', extension: 'gif' }, { mimetype: 'image/gif', extension: 'gif' },
{ mimetype: 'image/heic', extension: 'heic' }, { mimetype: 'image/heic', extension: 'heic' },
{ mimetype: 'image/heif', extension: 'heif' }, { mimetype: 'image/heif', extension: 'heif' },
@ -89,8 +88,8 @@ describe('assetUploadOption', () => {
{ mimetype: 'image/x-sony-sr2', extension: 'sr2' }, { mimetype: 'image/x-sony-sr2', extension: 'sr2' },
{ mimetype: 'image/x-sony-srf', extension: 'srf' }, { mimetype: 'image/x-sony-srf', extension: 'srf' },
{ mimetype: 'video/3gpp', extension: '3gp' }, { mimetype: 'video/3gpp', extension: '3gp' },
{ mimetype: 'video/avi', extension: 'avi' }, { mimetype: 'video/mp2t', extension: 'm2ts' },
{ mimetype: 'video/mov', extension: 'mov' }, { mimetype: 'video/mp2t', extension: 'mts' },
{ mimetype: 'video/mp4', extension: 'mp4' }, { mimetype: 'video/mp4', extension: 'mp4' },
{ mimetype: 'video/mpeg', extension: 'mpg' }, { mimetype: 'video/mpeg', extension: 'mpg' },
{ mimetype: 'video/quicktime', extension: 'mov' }, { mimetype: 'video/quicktime', extension: 'mov' },

View File

@ -51,7 +51,6 @@ const logger = new Logger('AssetUploadConfig');
const validMimeTypes = [ const validMimeTypes = [
'image/avif', 'image/avif',
'image/dng',
'image/gif', 'image/gif',
'image/heic', 'image/heic',
'image/heif', 'image/heif',
@ -88,8 +87,7 @@ const validMimeTypes = [
'image/x-sony-sr2', 'image/x-sony-sr2',
'image/x-sony-srf', 'image/x-sony-srf',
'video/3gpp', 'video/3gpp',
'video/avi', 'video/mp2t',
'video/mov',
'video/mp4', 'video/mp4',
'video/mpeg', 'video/mpeg',
'video/quicktime', 'video/quicktime',

View File

@ -1,4 +1,4 @@
{ {
"extends": "./tsconfig.json", "extends": "./tsconfig.json",
"exclude": ["node_modules", "test", "dist", "**/*spec.ts"] "exclude": ["dist", "node_modules", "upload", "test", "**/*spec.ts"]
} }

View File

@ -60,44 +60,58 @@ describe('get asset filename', () => {
}); });
describe('get file mime type', () => { describe('get file mime type', () => {
for (const { extension, mimeType } of [ for (const { mimetype, extension } of [
{ extension: '3fr', mimeType: 'image/x-hasselblad-3fr' }, { mimetype: 'image/avif', extension: 'avif' },
{ extension: '3gp', mimeType: 'video/3gpp' }, { mimetype: 'image/gif', extension: 'gif' },
{ extension: 'ari', mimeType: 'image/x-arriflex-ari' }, { mimetype: 'image/heic', extension: 'heic' },
{ extension: 'arw', mimeType: 'image/x-sony-arw' }, { mimetype: 'image/heif', extension: 'heif' },
{ extension: 'avif', mimeType: 'image/avif' }, { mimetype: 'image/jpeg', extension: 'jpeg' },
{ extension: 'cap', mimeType: 'image/x-phaseone-cap' }, { mimetype: 'image/jpeg', extension: 'jpg' },
{ extension: 'cin', mimeType: 'image/x-phantom-cin' }, { mimetype: 'image/jxl', extension: 'jxl' },
{ extension: 'cr2', mimeType: 'image/x-canon-cr2' }, { mimetype: 'image/png', extension: 'png' },
{ extension: 'cr3', mimeType: 'image/x-canon-cr3' }, { mimetype: 'image/tiff', extension: 'tiff' },
{ extension: 'crw', mimeType: 'image/x-canon-crw' }, { mimetype: 'image/webp', extension: 'webp' },
{ extension: 'dcr', mimeType: 'image/x-kodak-dcr' }, { mimetype: 'image/x-adobe-dng', extension: 'dng' },
{ extension: 'dng', mimeType: 'image/dng' }, { mimetype: 'image/x-arriflex-ari', extension: 'ari' },
{ extension: 'erf', mimeType: 'image/x-epson-erf' }, { mimetype: 'image/x-canon-cr2', extension: 'cr2' },
{ extension: 'fff', mimeType: 'image/x-hasselblad-fff' }, { mimetype: 'image/x-canon-cr3', extension: 'cr3' },
{ extension: 'heic', mimeType: 'image/heic' }, { mimetype: 'image/x-canon-crw', extension: 'crw' },
{ extension: 'heif', mimeType: 'image/heif' }, { mimetype: 'image/x-epson-erf', extension: 'erf' },
{ extension: 'iiq', mimeType: 'image/x-phaseone-iiq' }, { mimetype: 'image/x-fuji-raf', extension: 'raf' },
{ extension: 'insp', mimeType: 'image/jpeg' }, { mimetype: 'image/x-hasselblad-3fr', extension: '3fr' },
{ extension: 'insv', mimeType: 'video/mp4' }, { mimetype: 'image/x-hasselblad-fff', extension: 'fff' },
{ extension: 'jxl', mimeType: 'image/jxl' }, { mimetype: 'image/x-kodak-dcr', extension: 'dcr' },
{ extension: 'k25', mimeType: 'image/x-kodak-k25' }, { mimetype: 'image/x-kodak-k25', extension: 'k25' },
{ extension: 'kdc', mimeType: 'image/x-kodak-kdc' }, { mimetype: 'image/x-kodak-kdc', extension: 'kdc' },
{ extension: 'mrw', mimeType: 'image/x-minolta-mrw' }, { mimetype: 'image/x-leica-rwl', extension: 'rwl' },
{ extension: 'nef', mimeType: 'image/x-nikon-nef' }, { mimetype: 'image/x-minolta-mrw', extension: 'mrw' },
{ extension: 'orf', mimeType: 'image/x-olympus-orf' }, { mimetype: 'image/x-nikon-nef', extension: 'nef' },
{ extension: 'ori', mimeType: 'image/x-olympus-ori' }, { mimetype: 'image/x-olympus-orf', extension: 'orf' },
{ extension: 'pef', mimeType: 'image/x-pentax-pef' }, { mimetype: 'image/x-olympus-ori', extension: 'ori' },
{ extension: 'raf', mimeType: 'image/x-fuji-raf' }, { mimetype: 'image/x-panasonic-raw', extension: 'raw' },
{ extension: 'raw', mimeType: 'image/x-panasonic-raw' }, { mimetype: 'image/x-pentax-pef', extension: 'pef' },
{ extension: 'rwl', mimeType: 'image/x-leica-rwl' }, { mimetype: 'image/x-phantom-cin', extension: 'cin' },
{ extension: 'sr2', mimeType: 'image/x-sony-sr2' }, { mimetype: 'image/x-phaseone-cap', extension: 'cap' },
{ extension: 'srf', mimeType: 'image/x-sony-srf' }, { mimetype: 'image/x-phaseone-iiq', extension: 'iiq' },
{ extension: 'srw', mimeType: 'image/x-samsung-srw' }, { mimetype: 'image/x-samsung-srw', extension: 'srw' },
{ extension: 'x3f', mimeType: 'image/x-sigma-x3f' } { mimetype: 'image/x-sigma-x3f', extension: 'x3f' },
{ mimetype: 'image/x-sony-arw', extension: 'arw' },
{ mimetype: 'image/x-sony-sr2', extension: 'sr2' },
{ mimetype: 'image/x-sony-srf', extension: 'srf' },
{ mimetype: 'video/3gpp', extension: '3gp' },
{ mimetype: 'video/mp2t', extension: 'm2ts' },
{ mimetype: 'video/mp2t', extension: 'mts' },
{ mimetype: 'video/mp4', extension: 'mp4' },
{ mimetype: 'video/mpeg', extension: 'mpg' },
{ mimetype: 'video/quicktime', extension: 'mov' },
{ mimetype: 'video/webm', extension: 'webm' },
{ mimetype: 'video/x-flv', extension: 'flv' },
{ mimetype: 'video/x-matroska', extension: 'mkv' },
{ mimetype: 'video/x-ms-wmv', extension: 'wmv' },
{ mimetype: 'video/x-msvideo', extension: 'avi' }
]) { ]) {
it(`returns the mime type for ${extension}`, () => { it(`returns the mime type for ${extension}`, () => {
expect(getFileMimeType({ name: `filename.${extension}` } as File)).toEqual(mimeType); expect(getFileMimeType({ name: `filename.${extension}` } as File)).toEqual(mimetype);
}); });
} }

View File

@ -130,6 +130,7 @@ export function getFileMimeType(file: File): string {
'3gp': 'video/3gpp', '3gp': 'video/3gpp',
ari: 'image/x-arriflex-ari', ari: 'image/x-arriflex-ari',
arw: 'image/x-sony-arw', arw: 'image/x-sony-arw',
avi: 'video/x-msvideo',
avif: 'image/avif', avif: 'image/avif',
cap: 'image/x-phaseone-cap', cap: 'image/x-phaseone-cap',
cin: 'image/x-phantom-cin', cin: 'image/x-phantom-cin',
@ -137,28 +138,43 @@ export function getFileMimeType(file: File): string {
cr3: 'image/x-canon-cr3', cr3: 'image/x-canon-cr3',
crw: 'image/x-canon-crw', crw: 'image/x-canon-crw',
dcr: 'image/x-kodak-dcr', dcr: 'image/x-kodak-dcr',
dng: 'image/dng', dng: 'image/x-adobe-dng',
erf: 'image/x-epson-erf', erf: 'image/x-epson-erf',
fff: 'image/x-hasselblad-fff', fff: 'image/x-hasselblad-fff',
flv: 'video/x-flv',
gif: 'image/gif',
heic: 'image/heic', heic: 'image/heic',
heif: 'image/heif', heif: 'image/heif',
iiq: 'image/x-phaseone-iiq', iiq: 'image/x-phaseone-iiq',
insp: 'image/jpeg', insp: 'image/jpeg',
insv: 'video/mp4', insv: 'video/mp4',
jpeg: 'image/jpeg',
jpg: 'image/jpeg',
jxl: 'image/jxl', jxl: 'image/jxl',
k25: 'image/x-kodak-k25', k25: 'image/x-kodak-k25',
kdc: 'image/x-kodak-kdc', kdc: 'image/x-kodak-kdc',
m2ts: 'video/mp2t',
mkv: 'video/x-matroska',
mov: 'video/quicktime',
mp4: 'video/mp4',
mpg: 'video/mpeg',
mrw: 'image/x-minolta-mrw', mrw: 'image/x-minolta-mrw',
mts: 'video/mp2t',
nef: 'image/x-nikon-nef', nef: 'image/x-nikon-nef',
orf: 'image/x-olympus-orf', orf: 'image/x-olympus-orf',
ori: 'image/x-olympus-ori', ori: 'image/x-olympus-ori',
pef: 'image/x-pentax-pef', pef: 'image/x-pentax-pef',
png: 'image/png',
raf: 'image/x-fuji-raf', raf: 'image/x-fuji-raf',
raw: 'image/x-panasonic-raw', raw: 'image/x-panasonic-raw',
rwl: 'image/x-leica-rwl', rwl: 'image/x-leica-rwl',
sr2: 'image/x-sony-sr2', sr2: 'image/x-sony-sr2',
srf: 'image/x-sony-srf', srf: 'image/x-sony-srf',
srw: 'image/x-samsung-srw', srw: 'image/x-samsung-srw',
tiff: 'image/tiff',
webm: 'video/webm',
webp: 'image/webp',
wmv: 'video/x-ms-wmv',
x3f: 'image/x-sigma-x3f' x3f: 'image/x-sigma-x3f'
}; };
// Return the MIME type determined by the browser or the MIME type based on the file extension. // Return the MIME type determined by the browser or the MIME type based on the file extension.

View File

@ -47,8 +47,10 @@ export const openFileUploadDialog = async (
'.jxl', '.jxl',
'.k25', '.k25',
'.kdc', '.kdc',
'.m2ts',
'.mov', '.mov',
'.mrw', '.mrw',
'.mts',
'.nef', '.nef',
'.orf', '.orf',
'.ori', '.ori',