Skip to content

Commit a001b98

Browse files
authored
Merge pull request #5 from symblai/arjun-09-patch-1
Added preserveChannelLayout to transcodeMediaFile
2 parents 8e7d9fc + b9acc32 commit a001b98

File tree

1 file changed

+30
-16
lines changed

1 file changed

+30
-16
lines changed

lib/media/index.js

+30-16
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const replaceExtension = (fileName, extension) => {
1111
* @param outputFormat
1212
* @return {Promise<[]>} Promise of list of unsuccessful files
1313
*/
14-
const transcodeMediaFiles = async (files = [], outputFormat) => {
14+
const transcodeMediaFiles = async (files = [], outputFormat, options = {}) => {
1515
const unsuccessfulFiles = [];
1616
let _outputFormat = outputFormat;
1717
for (const file of files) {
@@ -22,7 +22,7 @@ const transcodeMediaFiles = async (files = [], outputFormat) => {
2222
_outputFile = replaceExtension(inputFile, outputFormat);
2323
}
2424
try {
25-
await transcodeMediaFile(inputFile, _outputFile, _outputFormat);
25+
await transcodeMediaFile(inputFile, _outputFile, _outputFormat, options);
2626
} catch (e) {
2727
console.error(e);
2828
unsuccessfulFiles.push({
@@ -62,22 +62,36 @@ const transcodeMediaFile = (inputFile, outputFile, outputFormat, options = {}) =
6262
throw `Third argument 'outputFormat' must be provided.`
6363
}
6464

65-
const {audioChannels, inputs = []} = options;
65+
const {audioChannels, preserveChannelsAndLayout} = options;
6666
let _audioChannels = audioChannels || 1;
67+
6768
return new Promise((resolve, reject) => {
68-
ffmpeg(inputFile)
69-
.format(outputFormat)
70-
.inputOptions(inputs)
71-
.audioChannels(_audioChannels)
72-
.on('end', () => {
73-
resolve({
74-
outPath: outputFile
75-
});
76-
})
77-
.on('error', (err) => {
78-
reject(err);
79-
})
80-
.save(outputFile);
69+
if (!preserveChannelsAndLayout) {
70+
ffmpeg(inputFile)
71+
.format(outputFormat)
72+
.audioChannels(_audioChannels)
73+
.on('end', () => {
74+
resolve({
75+
outPath: outputFile
76+
});
77+
})
78+
.on('error', (err) => {
79+
reject(err);
80+
})
81+
.save(outputFile);
82+
} else {
83+
ffmpeg(inputFile)
84+
.format(outputFormat)
85+
.on('end', () => {
86+
resolve({
87+
outPath: outputFile
88+
});
89+
})
90+
.on('error', (err) => {
91+
reject(err);
92+
})
93+
.save(outputFile);
94+
}
8195
});
8296
};
8397

0 commit comments

Comments
 (0)