Add new option force-yuv420p

This commit is contained in:
2022-07-19 23:18:28 +00:00
committed by GitHub
parent b2f1b5df07
commit eb1e42abf4
5 changed files with 57 additions and 1 deletions

View File

@@ -314,7 +314,10 @@ pub async fn download_artwork(
AVDict::new()
}
};
let options = AVDict::new();
let mut options = AVDict::new();
if helper.force_yuv420p() {
options.set("force_yuv420p", "1", None)?;
}
let frames = UgoiraFrames::from_json(&ugoira_data["frames"])?;
let output_file_name = base.join(format!("{}.mp4", id));
convert_ugoira_to_mp4(

View File

@@ -15,6 +15,8 @@ pub enum PixivDownloaderError {
HTTP(http::Error),
IOError(std::io::Error),
Fanbox(crate::fanbox::error::FanboxAPIError),
#[cfg(feature = "avdict")]
AVDict(crate::avdict::AVDictError),
}
impl From<&str> for PixivDownloaderError {

View File

@@ -135,6 +135,21 @@ impl OptHelper {
self.retry_interval()
}
#[cfg(feature = "ugoira")]
/// Return whether to force yuv420p as output pixel format when converting ugoira(GIF) to video.
pub fn force_yuv420p(&self) -> bool {
match self.opt.get_ref().force_yuv420p {
Some(r) => {
return r;
}
None => {}
}
if self.settings.get_ref().have_bool("force-yuv420p") {
return self.settings.get_ref().get_bool("force-yuv420p").unwrap();
}
false
}
/// return language
pub fn language(&self) -> Option<String> {
if self.opt.get_ref().language.is_some() {

View File

@@ -98,6 +98,9 @@ pub struct CommandOpts {
pub download_multiple_posts: Option<bool>,
/// The maximum number of tasks to download posts/artworks at the same time.
pub max_download_post_tasks: Option<usize>,
#[cfg(feature = "ugoira")]
/// Whether to force yuv420p as output pixel format when converting ugoira(GIF) to video.
pub force_yuv420p: Option<bool>,
}
impl CommandOpts {
@@ -129,6 +132,8 @@ impl CommandOpts {
max_download_tasks: None,
download_multiple_posts: None,
max_download_post_tasks: None,
#[cfg(feature = "ugoira")]
force_yuv420p: None,
}
}
@@ -455,6 +460,21 @@ pub fn parse_cmd() -> Option<CommandOpts> {
HasArg::Maybe,
getopts::Occur::Optional,
);
#[cfg(feature = "ugoira")]
opts.opt(
"",
"force-yuv420p",
format!(
"{} ({} {})",
gettext("Force yuv420p as output pixel format when converting ugoira(GIF) to video."),
gettext("Default:"),
"yes"
)
.as_str(),
"yes/no",
HasArg::Maybe,
getopts::Occur::Optional,
);
let result = match opts.parse(&argv[1..]) {
Ok(m) => m,
Err(err) => {
@@ -705,6 +725,20 @@ pub fn parse_cmd() -> Option<CommandOpts> {
return None;
}
}
#[cfg(feature = "ugoira")]
match parse_optional_opt(&result, "force-yuv420p", true, parse_bool) {
Ok(b) => re.as_mut().unwrap().force_yuv420p = b,
Err(e) => {
println!(
"{} {}",
gettext("Failed to parse <opt>:")
.replace("<opt>", "force-yuv420p")
.as_str(),
e
);
return None;
}
}
re
}

View File

@@ -43,6 +43,8 @@ pub fn get_settings_list() -> Vec<SettingDes> {
SettingDes::new("max-download-tasks", gettext("The maximum number of tasks to download files at the same time."), JsonValueType::Number, Some(check_nozero_usize)).unwrap(),
SettingDes::new("download-multiple-posts", gettext("Download multiple posts/artworks at the same time."), JsonValueType::Boolean, None).unwrap(),
SettingDes::new("max-download-post-tasks", gettext("The maximum number of tasks to download posts/artworks at the same time."), JsonValueType::Number, Some(check_nozero_usize)).unwrap(),
#[cfg(feature = "ugora")]
SettingDes::new("force-yuv420p", gettext("Force yuv420p as output pixel format when converting ugoira(GIF) to video."), JsonValueType::Boolean, None).unwrap(),
]
}