Skip to content
This repository has been archived by the owner on Jul 4, 2024. It is now read-only.

Commit

Permalink
Add ffmpeg amd hardware acceleration presets (#324)
Browse files Browse the repository at this point in the history
  • Loading branch information
bytedream authored Feb 25, 2024
1 parent 6a50567 commit 6a7aa25
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions crunchy-cli-core/src/utils/ffmpeg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ ffmpeg_enum! {
ffmpeg_enum! {
enum FFmpegHwAccel {
Nvidia,
Amd,
Apple
}
}
Expand Down Expand Up @@ -101,7 +102,11 @@ impl FFmpegPreset {
FFmpegHwAccel::all(),
FFmpegQuality::all(),
),
(FFmpegCodec::Av1, vec![], FFmpegQuality::all()),
(
FFmpegCodec::Av1,
vec![FFmpegHwAccel::Amd],
FFmpegQuality::all(),
),
];

let mut return_values = vec![];
Expand Down Expand Up @@ -285,6 +290,10 @@ impl FFmpegPreset {
crf_quality();
output.extend(["-c:v", "h264_nvenc", "-c:a", "copy"])
}
FFmpegHwAccel::Amd => {
crf_quality();
output.extend(["-c:v", "h264_amf", "-c:a", "copy"])
}
FFmpegHwAccel::Apple => {
// Apple's Video Toolbox encoders ignore `-crf`, use `-q:v`
// instead. It's on a scale of 1-100, 100 being lossless. Just
Expand Down Expand Up @@ -332,8 +341,12 @@ impl FFmpegPreset {
"hvc1",
])
}
FFmpegHwAccel::Amd => {
crf_quality();
output.extend(["-c:v", "hevc_amf", "-c:a", "copy"])
}
FFmpegHwAccel::Apple => {
// See the comment that starts on line 287.
// See the comment for apple h264 hwaccel
match quality {
FFmpegQuality::Lossless => output.extend(["-q:v", "61"]),
FFmpegQuality::Normal => (),
Expand All @@ -356,12 +369,17 @@ impl FFmpegPreset {
}
}
FFmpegCodec::Av1 => {
output.extend(["-c:v", "libsvtav1", "-c:a", "copy"]);

match quality {
let mut crf_quality = || match quality {
FFmpegQuality::Lossless => output.extend(["-crf", "22"]),
FFmpegQuality::Normal => (),
FFmpegQuality::Low => output.extend(["-crf", "35"]),
};

crf_quality();
if let Some(FFmpegHwAccel::Amd) = hwaccel_opt {
output.extend(["-c:v", "av1_amf", "-c:a", "copy"]);
} else {
output.extend(["-c:v", "libsvtav1", "-c:a", "copy"]);
}
}
}
Expand Down

0 comments on commit 6a7aa25

Please sign in to comment.