@@ -175,13 +175,24 @@ function setAudioFilters(options) {
175175 return af . join ( ',' ) ;
176176}
177177
178- function set2Pass ( flags ) {
178+ function set2Pass ( flags , options ) {
179179 const op = '/dev/null &&' ; // For Windows use `NUL && \`
180180 const copy = flags . slice ( ) ; // Array clone for pass 2.
181181
182182 // Rewrite command with 1 and 2 pass flags and append to flags array.
183- flags . push ( ...[ '-pass' , '1' , op ] ) ;
184- copy . push ( ...[ '-pass' , '2' ] ) ;
183+ if ( options . vcodec === 'libx265' && options . codecOptions ) {
184+ // Add pass param if the -x265-params flag is already present.
185+ const idx = flags . indexOf ( '-x265-params' ) ;
186+ // eslint-disable-next-line no-param-reassign
187+ flags [ idx + 1 ] += ':pass=1' ;
188+ copy [ idx + 1 ] += ':pass=2' ;
189+ } else if ( options . vcodec === 'libx265' ) {
190+ flags . push ( ...[ '-x265-params' , 'pass=1' , op ] ) ;
191+ copy . push ( ...[ '-x265-params' , 'pass=2' ] ) ;
192+ } else {
193+ flags . push ( ...[ '-pass' , '1' , op ] ) ;
194+ copy . push ( ...[ '-pass' , '2' ] ) ;
195+ }
185196 return copy ;
186197}
187198
@@ -274,7 +285,7 @@ function build(opt) {
274285
275286 // Set 2 pass output if option is set.
276287 if ( options . pass === '2' ) {
277- const copy = set2Pass ( flags ) ;
288+ const copy = set2Pass ( flags , options ) ;
278289 flags . push ( ...copy ) ;
279290 }
280291
0 commit comments