无法为'-framerate 5'-framerate 5'找到合适的输出格式:参数无效

noj0wjuj  于 2021-07-03  发布在  Java
关注(0)|答案(0)|浏览(217)

我正在尝试从一组图像创建.ts文件。我的ffmpeg命令是

[/usr/bin/ffmpeg,  -framerate 5,  -re -f image2pipe ,  -i - ,  -pix_fmt yuv420p ,  -preset veryfast ,  -c:v libx264 ,  -profile:v main ,  -crf 20 ,  -sc_threshold 0 ,  -g 48 ,  -keyint_min 48 ,  -hls_time 5 ,  -hls_list_size 0 ,  -hls_flags append_list+omit_endlist+round_durations ,  -b 800k ,  -maxrate 1100k ,  -bufsize 2200k , /home/rashmi/Music/output.m3u8]

我从一个java函数调用它

List<String> command = new ArrayList<>();
            command.add(PATH);
            command.add(" -framerate " + streamInput.getVideoFPS());
            command.add(" -re -f image2pipe ");
            command.add(" -i - ");
            command.add(" -pix_fmt yuv420p ");
            command.add(" -preset veryfast ");
            command.add(" -c:v libx264 ");
            command.add(" -profile:v main ");
            command.add(" -crf 20 ");
            command.add(" -sc_threshold 0 ");
            command.add(" -g 48 ");
            command.add(" -keyint_min 48 ");
            command.add(" -hls_time " + streamInput.getSegmentLength() + " ");
            command.add(" -hls_list_size 0 ");
            command.add(" -hls_flags append_list+omit_endlist+round_durations ");
            command.add(" -b 800k ");
            command.add(" -maxrate 1100k ");
            command.add(" -bufsize 2200k ");
            command.add(streamInput.getManifestFilePath());

            System.out.println("FFMPEG COMMAND:\n"+ command.toString());
            ProcessBuilder pb = new ProcessBuilder(command);
            pb.redirectInput(ProcessBuilder.Redirect.PIPE);
            pb.directory(Paths.get(streamInput.getFolderPath()).toFile());
            Process ffmpegProcess = pb.inheritIO().start();

            OutputStream ffmpegInput = ffmpegProcess.getOutputStream();

            for(File frame: frames){
//                System.out.println(frame.getAbsolutePath());

                byte[] image;
                image = new byte[(int)frame.length()];

                FileInputStream fileInputStream = new FileInputStream(frame);
                fileInputStream.read(image);
                ImageInputStream iis = ImageIO.createImageInputStream(
                        new ByteArrayInputStream(image));
                BufferedImage img = ImageIO.read(iis);
                ImageIO.write(img, "PNG", ffmpegInput);

            }

我要走了

[/usr/bin/ffmpeg,  -framerate 5,  -re -f image2pipe ,  -i - ,  -pix_fmt yuv420p ,  -preset veryfast ,  -c:v libx264 ,  -profile:v main ,  -crf 20 ,  -sc_threshold 0 ,  -g 48 ,  -keyint_min 48 ,  -hls_time 5 ,  -hls_list_size 0 ,  -hls_flags append_list+omit_endlist+round_durations ,  -b 800k ,  -maxrate 1100k ,  -bufsize 2200k , /home/rashmi/Music/output.m3u8]
ffmpeg version 4.3-2~18.04.york0 Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 7 (Ubuntu 7.5.0-3ubuntu1~18.04)
  configuration: --prefix=/usr --extra-version='2~18.04.york0' --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-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-librabbitmq --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --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-pocketsphinx --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
  libavutil      56. 51.100 / 56. 51.100
  libavcodec     58. 91.100 / 58. 91.100
  libavformat    58. 45.100 / 58. 45.100
  libavdevice    58. 10.100 / 58. 10.100
  libavfilter     7. 85.100 /  7. 85.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  7.100 /  5.  7.100
  libswresample   3.  7.100 /  3.  7.100
  libpostproc    55.  7.100 / 55.  7.100
[NULL @ 0x55a3c18a3e40] Unable to find a suitable output format for ' -framerate 5'
 -framerate 5: Invalid argument
javax.imageio.IIOException: I/O error writing PNG file!
    at java.desktop/com.sun.imageio.plugins.png.PNGImageWriter.write(PNGImageWriter.java:1277)
    at java.desktop/javax.imageio.ImageWriter.write(ImageWriter.java:613)
    at java.desktop/javax.imageio.ImageIO.doWrite(ImageIO.java:1628)
    at java.desktop/javax.imageio.ImageIO.write(ImageIO.java:1594)
    at com.streaming.hls.utils.StreamSegmentGenerator.buildStreamSegmet(StreamSegmentGenerator.java:81)
    at com.streaming.hls.utils.StreamSegmentGenerator.main(StreamSegmentGenerator.java:110)
Caused by: java.io.IOException: Stream closed
    at java.base/java.lang.ProcessBuilder$NullOutputStream.write(ProcessBuilder.java:442)
    at java.base/java.io.OutputStream.write(OutputStream.java:162)
    at java.desktop/javax.imageio.stream.FileCacheImageOutputStream.flushBefore(FileCacheImageOutputStream.java:255)
    at java.desktop/com.sun.imageio.plugins.png.ChunkStream.finish(PNGImageWriter.java:142)
    at java.desktop/com.sun.imageio.plugins.png.PNGImageWriter.write_IHDR(PNGImageWriter.java:487)
    at java.desktop/com.sun.imageio.plugins.png.PNGImageWriter.write(PNGImageWriter.java:1244)
    ... 5 more

我尝试用-r替换-framerate,这也引发了同样的错误。但是当我直接在终端中运行命令时,它就工作了。我不确定出了什么问题[null@0x55a3c18a3e40]无法为'-framerate 5'-framerate 5'找到合适的输出格式:参数无效

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题