Skip to content

Commit

Permalink
Merge pull request #121 from jamebal/recycle
Browse files Browse the repository at this point in the history
perf: 优化nvidia生成vtt缩略图
  • Loading branch information
jamebal authored Jul 7, 2024
2 parents c87c53c + 96293fd commit 5bf0ed8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/main/java/com/jmal/clouddisk/video/FFMPEGCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 5bf0ed8

Please sign in to comment.