3939import java .io .FileInputStream ;
4040import java .io .IOException ;
4141import java .nio .file .Files ;
42- import java .util .Arrays ;
4342import java .util .List ;
44- import java .util .stream .Stream ;
4543import java .util .zip .GZIPInputStream ;
4644
4745public final class MediaHelper {
@@ -390,8 +388,9 @@ private static MultimediaInfo retrieveMultimediaInfo(File file) throws Corrupted
390388 * @throws MediaException if file conversion is not successful
391389 */
392390 private static File convertWithFfmpeg (File file ) throws MediaException {
393- var logPrefix = new File (System .getProperty ("java.io.tmpdir" ), "passlog-" + file .getName ()).getAbsolutePath ();
394- var baseFfmpegCommand = new String [] {
391+ var webmVideo = createTempFile ("webm" );
392+ var logPrefix = webmVideo .getAbsolutePath () + "-passlog" ;
393+ var baseCommand = new String [] {
395394 "ffmpeg" ,
396395 "-y" ,
397396 "-v" , "error" ,
@@ -405,27 +404,9 @@ private static File convertWithFfmpeg(File file) throws MediaException {
405404 "-passlogfile" , logPrefix
406405 };
407406
408- var pass1Options = new String [] {
409- "-pass" , "1" ,
410- "-f" , "webm" ,
411- IS_WINDOWS ? "NUL" : "/dev/null"
412- };
413-
414- try {
415- ProcessHelper .executeCommand (buildFfmpegCommand (baseFfmpegCommand , pass1Options ));
416- } catch (ProcessException e ) {
417- deleteLogFile (logPrefix );
418- throw new MediaException (e .getMessage ());
419- }
420-
421- var webmVideo = createTempFile ("webm" );
422- var pass2Options = new String [] {
423- "-pass" , "2" ,
424- webmVideo .getAbsolutePath ()
425- };
426-
427407 try {
428- ProcessHelper .executeCommand (buildFfmpegCommand (baseFfmpegCommand , pass2Options ));
408+ ProcessHelper .executeCommand (buildFfmpegCommand (baseCommand , "-pass" , "1" , "-f" , "webm" , IS_WINDOWS ? "NUL" : "/dev/null" ));
409+ ProcessHelper .executeCommand (buildFfmpegCommand (baseCommand , "-pass" , "2" , webmVideo .getAbsolutePath ()));
429410 } catch (ProcessException e ) {
430411 deleteFile (webmVideo );
431412 throw new MediaException (e .getMessage ());
@@ -443,8 +424,11 @@ private static File convertWithFfmpeg(File file) throws MediaException {
443424 * @param additionalOptions command specific options
444425 * @return the complete ffmpeg invocation command
445426 */
446- private static String [] buildFfmpegCommand (String [] baseCommand , String [] additionalOptions ) {
447- return Stream .concat (Arrays .stream (baseCommand ), Arrays .stream (additionalOptions )).toArray (String []::new );
427+ private static String [] buildFfmpegCommand (String [] baseCommand , String ... additionalOptions ) {
428+ var commands = new String [baseCommand .length + additionalOptions .length ];
429+ System .arraycopy (baseCommand , 0 , commands , 0 , baseCommand .length );
430+ System .arraycopy (additionalOptions , 0 , commands , baseCommand .length , additionalOptions .length );
431+ return commands ;
448432 }
449433
450434 /**
0 commit comments