Unrecognized option ‘crf 21’ in ffmpeg

huangapple go评论78阅读模式
英文:

Unrecognized option 'crf 21' in ffmpeg

问题

我正在尝试在一个简单的JAR应用程序中使用ffmpeg转换视频,但是我遇到了以下错误:Unrecognized option Error splitting the argument list: Option not found.

我正在执行以下操作:

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();

之后,我只是使用缓冲读取器读取命令的输出,并将其放入调试记录器。我得到了以下输出:

ffmpeg版本4.2.4-1ubuntu0.1版权所有(c)2000-2020年FFmpeg开发人员
使用gcc 9(Ubuntu 9.3.0-10ubuntu2)构建
配置:--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
未识别的选项'crf 21'。
分割参数列表时出错:找不到选项

有趣的是,当我在终端中执行command.toString().replaceAll(",", "")中的内容时,命令可以正常执行,没有任何错误。问题只发生在Java应用程序中。

我看到有类似的帖子建议更新ffmpeg(我认为这不是问题所在),并且分割参数已经完成。我尝试过仅删除crf配置,但是错误信息变成了“At least one output file must be specified”。

这表明问题确实是参数分割错误,但我已经没有更多的想法了。
英文:

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 &lt;String&gt; command = new ArrayList&lt;String&gt;();
command.add(&quot;ffmpeg&quot;);
command.add(&quot;-y&quot;);
command.add(&quot;-i&quot;); 
command.add(myCustomFileClass.getInputFileName()); 
command.add(&quot;-c:v libx264&quot;);
command.add(&quot;-preset slower&quot;);
command.add(&quot;-crf 21&quot;);
command.add(&quot;-c:a aac&quot;); 
command.add(myCustomFileClass.getOutputFileName());
logger.debug(command.toString().replaceAll(&quot;,&quot;, &quot;&quot;));
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 &#39;crf 21&#39;.
Error splitting the argument list: Option not found

What's curious is that when I execute what's inside command.toString().replaceAll(&quot;,&quot;, &quot;&quot;) 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.

答案1

得分: 1

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());
英文:

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 ... &#39;-crf 21&#39; ... (note the single quotes).

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

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

huangapple
  • 本文由 发表于 2020年8月18日 07:17:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/63459810.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定