Spring Bootとffmpegを統合する方法

Spring BootでFFmpegを使用するための統合手順は以下の通りです。

  1. pom.xml
  2. エクグラー
<dependency>
    <groupId>com.xuggle</groupId>
    <artifactId>xuggle-xuggler</artifactId>
    <version>5.4</version>
</dependency>
  1. FFmpegサービス
@Service
public class FFmpegService {

    public void executeCommand(String command) throws IOException {
        Process process = Runtime.getRuntime().exec(command);
        process.waitFor();
    }

    // 其他FFmpeg相关方法...
}
  1. FFmpegサービス
@Service
public class MyService {

    private final FFmpegService ffmpegService;

    public MyService(FFmpegService ffmpegService) {
        this.ffmpegService = ffmpegService;
    }

    public void convertVideo(String inputPath, String outputPath) {
        String command = "ffmpeg -i " + inputPath + " -c:v libx264 -crf 23 " + outputPath;
        try {
            ffmpegService.executeCommand(command);
        } catch (IOException | InterruptedException e) {
            // 处理异常...
        }
    }

    // 其他使用FFmpeg的方法...
}

これにより、Spring Bootで音 vidéo ファイルを処理するためにFFmpegを使用できます。もちろん、これは簡単な例にすぎません。独自のニーズに合わせて、より多くのFFmpeg機能を定義して使用できます。

bannerAds