diff --git a/src/main/java/com/jmal/clouddisk/video/FFMPEGCommand.java b/src/main/java/com/jmal/clouddisk/video/FFMPEGCommand.java index 3064a79f..9ed2f808 100644 --- a/src/main/java/com/jmal/clouddisk/video/FFMPEGCommand.java +++ b/src/main/java/com/jmal/clouddisk/video/FFMPEGCommand.java @@ -243,8 +243,20 @@ static ProcessBuilder useNvencCuda(String fileId, Path fileAbsolutePath, int bit "-hls_segment_filename", Paths.get(videoCacheDir, fileId + "-%03d.ts").toString(), "-hls_playlist_type", "vod", "-hls_list_size", "0", - outputPath, + outputPath + ); + } + + static ProcessBuilder useNvencCudaVtt(Path fileAbsolutePath, int vttInterval, String thumbnailPattern) { + // 使用CUDA硬件加速和NVENC编码器 + return new ProcessBuilder( + Constants.FFMPEG, + "-init_hw_device", "cuda=cu:0", + "-filter_hw_device", "cu", + "-i", fileAbsolutePath.toString(), + "-y", "-vf", String.format("scale=%s:-2,fps=1/%d", thumbnailWidth, vttInterval), + "-vsync", "vfr", thumbnailPattern ); } diff --git a/src/main/java/com/jmal/clouddisk/video/VideoProcessService.java b/src/main/java/com/jmal/clouddisk/video/VideoProcessService.java index 76afdd40..ce7233a3 100644 --- a/src/main/java/com/jmal/clouddisk/video/VideoProcessService.java +++ b/src/main/java/com/jmal/clouddisk/video/VideoProcessService.java @@ -546,6 +546,12 @@ private void videoToM3U8(String fileId, String username, String relativePath, St if (!onlyCPU && FFMPEGCommand.checkNvidiaDrive()) { log.info("use NVENC hardware acceleration"); processBuilder = FFMPEGCommand.useNvencCuda(fileId, fileAbsolutePath, bitrate, targetHeight, videoCacheDir, outputPath, vttInterval, thumbnailPattern, frameRate); + // 生成vtt缩略图, nvidia加速时要单独生成vtt缩略图 + ProcessBuilder proVtt = FFMPEGCommand.useNvencCudaVtt(fileAbsolutePath, vttInterval, thumbnailPattern); + printSuccessInfo(proVtt); + // 等待处理结果 + Process process = proVtt.start(); + getWaitingForResults(vttPath.toString(), proVtt, process); } if (!onlyCPU && FFMPEGCommand.checkMacAppleSilicon()) { log.info("use videotoolbox hardware acceleration");