Gustavo Borba
Gustavo Borba

Reputation: 33

Unrecognized option 'crf 21' in ffmpeg

I'm trying to convert a video with ffmpeg in a simple jar application, but I'm getting this Unrecognized option Error splitting the argument list: Option not found.

I'm doing the following:

List <String> command = new ArrayList<String>();
command.add("ffmpeg");
command.add("-y");
command.add("-i"); 
command.add(myCustomFileClass.getInputFileName()); 
command.add("-c:v libx264");
command.add("-preset slower");
command.add("-crf 21");
command.add("-c:a aac"); 
command.add(myCustomFileClass.getOutputFileName());
logger.debug(command.toString().replaceAll(",", ""));
ProcessBuilder builder = new ProcessBuilder(command);
process = builder.start();

After that, I just read the output from the command with a buffered reader and put it on the debug logger. I'm getting this output:

ffmpeg version 4.2.4-1ubuntu0.1 Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 9 (Ubuntu 9.3.0-10ubuntu2)
configuration: --prefix=/usr --extra-version=1ubuntu0.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
libavutil      56. 31.100 / 56. 31.100
libavcodec     58. 54.100 / 58. 54.100
libavformat    58. 29.100 / 58. 29.100
libavdevice    58.  8.100 / 58.  8.100
libavfilter     7. 57.100 /  7. 57.100
libavresample   4.  0.  0 /  4.  0.  0
libswscale      5.  5.100 /  5.  5.100
libswresample   3.  5.100 /  3.  5.100
libpostproc    55.  5.100 / 55.  5.100
Unrecognized option 'crf 21'.
Error splitting the argument list: Option not found

What's curious is that when I execute what's inside command.toString().replaceAll(",", "") in my terminal, the command executes without any error. It's only ocurring in the java application.

I saw similar posts of people suggesting updating ffmpe (which I don't think it's the case) and splitting the arguments, but it's alredy done. I tried to just eliminate the crf config, but it just changes the error to At least one output file must be specified.

This suggests that the problem is indeed a bad splitting, but I'm out of ideas.

Upvotes: 3

Views: 4921

Answers (1)

Hern&#225;n Alarc&#243;n
Hern&#225;n Alarc&#243;n

Reputation: 4109

Every command argument must be a different element in the list (command in your example), but you are joining two arguments (-crf and 21) as a single argument (-crf 21). That is equivalent to trying to run this command in the terminal: ffmpeg ... '-crf 21' ... (note the single quotes).

You have to separate your arguments correctly. According to your code, it would be like this:

command.add("ffmpeg");
command.add("-y");
command.add("-i"); 
command.add(myCustomFileClass.getInputFileName()); 
command.add("-c:v");
command.add("libx264");
command.add("-preset");
command.add("slower");
command.add("-crf");
command.add("21");
command.add("-c:a");
command.add("aac")
command.add(myCustomFileClass.getOutputFileName());

Upvotes: 1

Related Questions