test-helpers.js
1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import {isVideoCodec, isAudioCodec} from '../src/codecs.js';
const codecAliasMap = {
mp3: ['mp3', 'mp4a.40.34', 'mp4a.6b'],
aac: ['aac', 'mp4a.40.2', 'mp4a.40.5', 'mp4a.40.29']
};
Object.keys(codecAliasMap).forEach((alias) => {
// map aliases as keys so that everything is linked to each other
codecAliasMap[alias].forEach((subalias) => {
codecAliasMap[subalias] = codecAliasMap[alias];
});
});
export const doesCodecMatch = function(a, b) {
if (!a) {
return false;
}
if (codecAliasMap[b]) {
return codecAliasMap[a].indexOf(b) !== -1;
}
return a === b;
};
export const codecsFromFile = function(file) {
const codecs = {};
const extension = file.split('.').pop();
const codecStr = file.replace(`.${extension}`, '');
codecStr.split(',').forEach((codec) => {
if (isVideoCodec(codec)) {
codecs.video = codec;
} else if (isAudioCodec(codec)) {
codecs.audio = codec;
} else {
throw new Error(`${codec} is not detected as audio or video`);
}
});
return codecs;
};