mirror of
https://git.asonix.dog/asonix/pict-rs
synced 2024-11-09 22:14:59 +00:00
Only include -b:v 0 for VP9
also simplify building arguments
This commit is contained in:
parent
3aecef3a9e
commit
496bcc5dc1
3 changed files with 65 additions and 105 deletions
|
@ -235,6 +235,13 @@ impl VideoFormat {
|
|||
}
|
||||
|
||||
impl OutputVideoFormat {
|
||||
pub(crate) const fn is_vp9(&self) -> bool {
|
||||
match self {
|
||||
Self::Webm { video_codec, .. } => video_codec.is_vp9(),
|
||||
Self::Mp4 { .. } => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) const fn from_parts(
|
||||
video_codec: VideoCodec,
|
||||
audio_codec: Option<AudioCodec>,
|
||||
|
@ -374,6 +381,10 @@ impl Mp4Codec {
|
|||
}
|
||||
|
||||
impl WebmAlphaCodec {
|
||||
const fn is_vp9(&self) -> bool {
|
||||
matches!(self, Self::Vp9)
|
||||
}
|
||||
|
||||
const fn ffmpeg_codec(self) -> &'static str {
|
||||
match self {
|
||||
Self::Vp8 => "vp8",
|
||||
|
@ -383,6 +394,13 @@ impl WebmAlphaCodec {
|
|||
}
|
||||
|
||||
impl WebmCodec {
|
||||
const fn is_vp9(self) -> bool {
|
||||
match self {
|
||||
Self::Av1 => false,
|
||||
Self::Alpha(AlphaCodec { codec, .. }) => codec.is_vp9(),
|
||||
}
|
||||
}
|
||||
|
||||
const fn ffmpeg_codec(self) -> &'static str {
|
||||
match self {
|
||||
Self::Av1 => "av1",
|
||||
|
|
|
@ -60,66 +60,43 @@ async fn transcode_files(
|
|||
output_format: OutputVideoFormat,
|
||||
crf: u8,
|
||||
) -> Result<(), FfMpegError> {
|
||||
let mut args = vec![
|
||||
"-hide_banner",
|
||||
"-v",
|
||||
"warning",
|
||||
"-f",
|
||||
input_format.ffmpeg_format(),
|
||||
"-i",
|
||||
input_path,
|
||||
"-pix_fmt",
|
||||
output_format.pix_fmt(),
|
||||
"-vf",
|
||||
"scale=trunc(iw/2)*2:trunc(ih/2)*2",
|
||||
];
|
||||
|
||||
if let Some(audio_codec) = output_format.ffmpeg_audio_codec() {
|
||||
Process::run(
|
||||
"ffmpeg",
|
||||
&[
|
||||
"-hide_banner",
|
||||
"-v",
|
||||
"warning",
|
||||
"-f",
|
||||
input_format.ffmpeg_format(),
|
||||
"-i",
|
||||
input_path,
|
||||
"-pix_fmt",
|
||||
output_format.pix_fmt(),
|
||||
"-vf",
|
||||
"scale=trunc(iw/2)*2:trunc(ih/2)*2",
|
||||
"-c:a",
|
||||
audio_codec,
|
||||
"-c:v",
|
||||
output_format.ffmpeg_video_codec(),
|
||||
"-b:v",
|
||||
"0",
|
||||
"-crf",
|
||||
&crf.to_string(),
|
||||
"-f",
|
||||
output_format.ffmpeg_format(),
|
||||
output_path,
|
||||
],
|
||||
)?
|
||||
.wait()
|
||||
.await?;
|
||||
args.extend(["-c:a", audio_codec]);
|
||||
} else {
|
||||
Process::run(
|
||||
"ffmpeg",
|
||||
&[
|
||||
"-hide_banner",
|
||||
"-v",
|
||||
"warning",
|
||||
"-f",
|
||||
input_format.ffmpeg_format(),
|
||||
"-i",
|
||||
input_path,
|
||||
"-pix_fmt",
|
||||
output_format.pix_fmt(),
|
||||
"-vf",
|
||||
"scale=trunc(iw/2)*2:trunc(ih/2)*2",
|
||||
"-an",
|
||||
"-c:v",
|
||||
output_format.ffmpeg_video_codec(),
|
||||
"-b:v",
|
||||
"0",
|
||||
"-crf",
|
||||
&crf.to_string(),
|
||||
"-f",
|
||||
output_format.ffmpeg_format(),
|
||||
output_path,
|
||||
],
|
||||
)?
|
||||
.wait()
|
||||
.await?;
|
||||
args.push("-an")
|
||||
}
|
||||
|
||||
args.extend(["-c:v", output_format.ffmpeg_video_codec()]);
|
||||
|
||||
if output_format.is_vp9() {
|
||||
args.extend(["-b:v", "0"]);
|
||||
}
|
||||
|
||||
let crf = crf.to_string();
|
||||
|
||||
args.extend([
|
||||
"-crf",
|
||||
&crf,
|
||||
"-f",
|
||||
output_format.ffmpeg_format(),
|
||||
output_path,
|
||||
]);
|
||||
|
||||
Process::run("ffmpeg", &args)?.wait().await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -79,56 +79,21 @@ async fn convert(
|
|||
|
||||
let input_arg = format!("{input}:{input_file_str}");
|
||||
let output_arg = format!("{output}:-");
|
||||
let quality = quality.map(|q| q.to_string());
|
||||
|
||||
let process = if coalesce {
|
||||
if let Some(quality) = quality {
|
||||
Process::run(
|
||||
"magick",
|
||||
&[
|
||||
"convert",
|
||||
"-strip",
|
||||
"-auto-orient",
|
||||
&input_arg,
|
||||
"-quality",
|
||||
&quality.to_string(),
|
||||
"-coalesce",
|
||||
&output_arg,
|
||||
],
|
||||
)?
|
||||
} else {
|
||||
Process::run(
|
||||
"magick",
|
||||
&[
|
||||
"convert",
|
||||
"-strip",
|
||||
"-auto-orient",
|
||||
&input_arg,
|
||||
"-coalesce",
|
||||
&output_arg,
|
||||
],
|
||||
)?
|
||||
}
|
||||
} else if let Some(quality) = quality {
|
||||
Process::run(
|
||||
"magick",
|
||||
&[
|
||||
"convert",
|
||||
"-strip",
|
||||
"-auto-orient",
|
||||
&input_arg,
|
||||
"-quality",
|
||||
&quality.to_string(),
|
||||
&output_arg,
|
||||
],
|
||||
)?
|
||||
} else {
|
||||
Process::run(
|
||||
"magick",
|
||||
&["convert", "-strip", "-auto-orient", &input_arg, &output_arg],
|
||||
)?
|
||||
};
|
||||
let mut args = vec!["convert", "-strip", "-auto-orient", &input_arg];
|
||||
|
||||
let reader = process.read();
|
||||
if let Some(quality) = &quality {
|
||||
args.extend(["-quality", quality]);
|
||||
}
|
||||
|
||||
if coalesce {
|
||||
args.push("-coalesce");
|
||||
}
|
||||
|
||||
args.push(&output_arg);
|
||||
|
||||
let reader = Process::run("magick", &args)?.read();
|
||||
|
||||
let clean_reader = crate::tmp_file::cleanup_tmpfile(reader, input_file);
|
||||
|
||||
|
|
Loading…
Reference in a new issue