feat: add ability to choose video codec
This commit is contained in:
parent
8f3c7e4052
commit
299ad0c9dc
2 changed files with 61 additions and 16 deletions
|
@ -39,6 +39,23 @@ pub struct VideoMeta {
|
|||
pub duration_us: usize,
|
||||
}
|
||||
|
||||
#[derive(Default, Clone, Copy)]
|
||||
pub enum Codec {
|
||||
AV1,
|
||||
#[default]
|
||||
VP9,
|
||||
}
|
||||
|
||||
impl From<String> for Codec {
|
||||
fn from(value: String) -> Self {
|
||||
match value.as_str() {
|
||||
"AV1" => Self::AV1,
|
||||
"VP9" => Self::VP9,
|
||||
_ => Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn get_video_meta(path: &Path) -> Result<VideoMeta> {
|
||||
let output = Command::new("ffprobe")
|
||||
.args([
|
||||
|
@ -74,25 +91,26 @@ pub async fn get_video_meta(path: &Path) -> Result<VideoMeta> {
|
|||
})
|
||||
}
|
||||
|
||||
pub async fn convert_video(path: &Path, sender: Sender<ProgressMessage>) -> Result<PathBuf> {
|
||||
pub async fn convert_video(
|
||||
path: &Path,
|
||||
out_filename: Option<String>,
|
||||
out_codec: Codec,
|
||||
merge_tracks: bool,
|
||||
sender: Sender<ProgressMessage>,
|
||||
) -> Result<PathBuf> {
|
||||
let out_path = PathBuf::from("/tmp/out.webm");
|
||||
|
||||
let codec_args: &[&str] = match out_codec {
|
||||
Codec::AV1 => &["-c:v", "libsvtav1"],
|
||||
Codec::VP9 => &["-c:v", "libvpx-vp9", "-row-mt", "1"],
|
||||
};
|
||||
|
||||
let mut child = Command::new("ffmpeg")
|
||||
.arg("-i")
|
||||
.arg(path)
|
||||
.args([
|
||||
"-c:a",
|
||||
"libopus",
|
||||
"-b:a",
|
||||
"96k",
|
||||
"-c:v",
|
||||
"libsvtav1",
|
||||
"-loglevel",
|
||||
"error",
|
||||
"-progress",
|
||||
"-",
|
||||
"-nostats",
|
||||
])
|
||||
.args(["-c:a", "libopus", "-b:a", "96k"])
|
||||
.args(codec_args)
|
||||
.args(["-loglevel", "error", "-progress", "-", "-nostats"])
|
||||
.arg(&out_path)
|
||||
.stdout(Stdio::piped())
|
||||
.spawn()?;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue