use java-ffmpeg wrapper, or simply use java runtime to execute ffmpeg?

前端 未结 8 2007
余生分开走
余生分开走 2020-11-28 21:37

I\'m pretty new to Java, need to write a program that listen to video conversion instructions and convert the video once an new instruction arrives (instructions is stored i

相关标签:
8条回答
  • 2020-11-28 22:41

    I wrote my own Java ffmpeg command line wrapper: Jaffree. It works with both ffprobe and ffmpeg and supports programmatic video production and consumption. Also it has in my opinion more convenient fluid API.

    Here is an ffprobe usage example:

    FFprobeResult result = FFprobe.atPath(BIN)
            .setInputPath(VIDEO_MP4)
            .setShowStreams(true)
            .setShowError(true)
            .execute();
    
    if (result.getError() != null) {
        //TODO handle ffprobe error message
        return;
    }
    
    for (Stream stream : probe.getStreams().getStream()) {
        //TODO analyze stream data
    }
    
    ProgressListener listener = new ProgressListener() {
        @Override
        public void onProgress(FFmpegProgress progress) {
            //TODO handle progress data
        }
    };
    

    And this is for ffmpeg:

    FFmpegResult result = FFmpeg.atPath(BIN)
            .addInput(Input.fromPath(VIDEO_MP4))
            .addOutput(Output.toPath(outputPath)
                    .addCodec(null, "copy")
            )
            .setProgressListener(listener)
            .execute();
    
    0 讨论(0)
  • 2020-11-28 22:43

    Also, as of Xuggler 3.3, Xuggler is LGPL meaning you don't need a commercial license.

    0 讨论(0)
提交回复
热议问题