0

Hi I want to run ffmpeg -f concat -i test.txt -c copy output.mp4 in java. My FFmpegBuilder :

        FFmpeg ffmpeg = new FFmpeg("C:\\ffmpeg\\bin\\ffmpeg.exe");
        FFprobe ffprobe = new FFprobe("C:\\ffmpeg\\bin\\ffprobe.exe");

        FFmpegBuilder builder = new FFmpegBuilder()
                .setInput(path + fileName)
                .addExtraArgs("-f", "CONCAT")
                .addExtraArgs("-i", path+ "test.txt")
                .addExtraArgs("-c", "copy")
                .addOutput("outjava.mp4")
                //.setAudioCodec("COPY")
               // .setVideoCodec("COPY")
                .done();


        FFmpegExecutor executor = new FFmpegExecutor(ffmpeg, ffprobe);
        executor.createJob(builder).run();

But I get always the error:

Unknown decoder 'copy'
Exception in thread "main" java.lang.RuntimeException: java.io.IOException: C:\ffmpeg\bin\ffmpeg.exe returned non-zero exit status. Check stdout.
    at net.bramp.ffmpeg.job.SinglePassFFmpegJob.run(SinglePassFFmpegJob.java:46)
    at Main.main(Main.java:47)
Caused by: java.io.IOException: C:\ffmpeg\bin\ffmpeg.exe returned non-zero exit status. Check stdout.
    at net.bramp.ffmpeg.FFcommon.throwOnError(FFcommon.java:51)
    at net.bramp.ffmpeg.FFcommon.run(FFcommon.java:113)
    at net.bramp.ffmpeg.FFmpeg.run(FFmpeg.java:184)
    at net.bramp.ffmpeg.FFmpeg.run(FFmpeg.java:202)
    at net.bramp.ffmpeg.job.SinglePassFFmpegJob.run(SinglePassFFmpegJob.java:39)
    ... 1 more

Why is it possible to wrap all args into .addExtraArgs, but the -c copy argument is failing? What is my mistake? .setVideoCodec("COPY") is also failing

CampingCow
  • 120
  • 10

1 Answers1

0

-c copy is an output argument.

Place .addExtraArgs("-c", "copy") after addOutput("outjava.mp4"):

FFmpegBuilder builder = new FFmpegBuilder()
        .setInput(path + fileName)
        .addExtraArgs("-f", "concat")
        .addExtraArgs("-i", path+ "test.txt")
        .addOutput("outjava.mp4")
        .addExtraArgs("-c", "copy")
        .done();

Note: I didn't had the chance to test my answer.
According to the following examples, it should work.

Please note that concat demuxers with -c copy only works when all the input files have the same characteristics.

Rotem
  • 30,366
  • 4
  • 32
  • 65
  • Thanks. Now it works fine! Do you know why the Windows command "copy /b *.ts output.mp4" has a much better perfomance than "ffmpeg -f concat -i test.txt -c copy output.mp4"? It should be the same process, but copy /b feels like 5 -10 times faster. – CampingCow Jan 29 '22 at 14:18
  • `-f concat` works at stream level, so it's not equivalent to `copy /b`. I assume [concat protocol](https://trac.ffmpeg.org/wiki/Concatenate#protocol) is equivalent to `copy /b`. For example: `concat demuxer` works with MP4 input files, but `concat protocol` is not going to work with MP4 input files. – Rotem Jan 29 '22 at 16:46
  • ah okay, now I got the difference Thank you!! But when I am using the concat protocoll im limited in the count of files. ffmpeg gets an error when -f "concat: a.ts|...." is too long. Is there a way to use a file as input or incease the count of files? – CampingCow Jan 30 '22 at 10:39
  • I don't think there is a way to use a text file as an input. I don't know the source of the string length limitation. Are you executing from console or from JAVA? You may try executing from PowerShell. In case the limitation is in FFmpeg the solution is concatenating to few groups and concatenating the groups at the end. You may also try updating FFmpeg version... – Rotem Jan 30 '22 at 11:57
  • I tried it with ffmpeg-java-wrapper and in windows cmd and it failed both times. In powershell it works. My ffmpeg version is latest ( 2022-01-27-git-3c831847a8). Thanks for the groups-merge idea, I will check if it performs better than a single demuxer merge – CampingCow Jan 30 '22 at 12:58