@@ -11,7 +11,7 @@ const replaceExtension = (fileName, extension) => {
11
11
* @param outputFormat
12
12
* @return {Promise<[]> } Promise of list of unsuccessful files
13
13
*/
14
- const transcodeMediaFiles = async ( files = [ ] , outputFormat ) => {
14
+ const transcodeMediaFiles = async ( files = [ ] , outputFormat , options = { } ) => {
15
15
const unsuccessfulFiles = [ ] ;
16
16
let _outputFormat = outputFormat ;
17
17
for ( const file of files ) {
@@ -22,7 +22,7 @@ const transcodeMediaFiles = async (files = [], outputFormat) => {
22
22
_outputFile = replaceExtension ( inputFile , outputFormat ) ;
23
23
}
24
24
try {
25
- await transcodeMediaFile ( inputFile , _outputFile , _outputFormat ) ;
25
+ await transcodeMediaFile ( inputFile , _outputFile , _outputFormat , options ) ;
26
26
} catch ( e ) {
27
27
console . error ( e ) ;
28
28
unsuccessfulFiles . push ( {
@@ -62,22 +62,36 @@ const transcodeMediaFile = (inputFile, outputFile, outputFormat, options = {}) =
62
62
throw `Third argument 'outputFormat' must be provided.`
63
63
}
64
64
65
- const { audioChannels, inputs = [ ] } = options ;
65
+ const { audioChannels, preserveChannelsAndLayout } = options ;
66
66
let _audioChannels = audioChannels || 1 ;
67
+
67
68
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
+ }
81
95
} ) ;
82
96
} ;
83
97
0 commit comments