basic encoder commands to output to file

This commit is contained in:
Muaz Ahmad 2023-10-12 15:10:53 +05:00
parent 1023bfdee5
commit 763683d9b3
2 changed files with 31 additions and 2 deletions

View file

@ -1,6 +1,7 @@
use std::error::Error; use std::error::Error;
use std::process::{Child, Command, Stdio, ChildStdin, ChildStdout}; use std::process::{Child, Command, Stdio, ChildStdin, ChildStdout};
use std::sync::Arc; use std::sync::Arc;
use std::fs::File;
use crate::util; use crate::util;
use crate::encode::codecs::Encoder; use crate::encode::codecs::Encoder;
@ -12,6 +13,18 @@ pub struct OpusEncoder {
impl Encoder for OpusEncoder {} impl Encoder for OpusEncoder {}
pub fn new_opus(metadata: Arc<util::Metadata>) -> Result<OpusEncoder, Box<dyn Error>> { pub fn new_opus(metadata: Arc<util::Metadata>) -> Result<OpusEncoder, Box<dyn Error>> {
todo!(); let f = File::create("dump.opus")?;
let channels = metadata.audio.channels.to_string();
let samplerate = metadata.audio.samplerate.to_string();
let cmd = Command::new("opusenc")
.args([
"--quiet",
"--raw",
"--raw-bits", "16",
"--raw-rate", samplerate.as_str(),
"--raw-chan", channels.as_str(),
"--raw-endianness", "1"
]).stdin(Stdio::piped()).stdout(f).spawn()?;
return Ok(OpusEncoder {cmd: cmd});
} }

View file

@ -1,6 +1,7 @@
use std::error::Error; use std::error::Error;
use std::process::{Child, Command, Stdio, ChildStdin, ChildStdout}; use std::process::{Child, Command, Stdio, ChildStdin, ChildStdout};
use std::sync::Arc; use std::sync::Arc;
use std::fs::File;
use crate::util; use crate::util;
use crate::encode::codecs::Encoder; use crate::encode::codecs::Encoder;
@ -12,5 +13,20 @@ pub struct VP9Encoder {
impl Encoder for VP9Encoder {} impl Encoder for VP9Encoder {}
pub fn new_vp9(metadata: Arc<util::Metadata>) -> Result<VP9Encoder, Box<dyn Error>> { pub fn new_vp9(metadata: Arc<util::Metadata>) -> Result<VP9Encoder, Box<dyn Error>> {
todo!(); let f = File::create("dump.av1")?;
let width = metadata.video.width.to_string();
let height = metadata.video.height.to_string();
let fps_num = ((metadata.video.framerate * 1000.0) as u32).to_string();
let cmd = Command::new("SvtAv1EncApp")
.args([
"--errlog", "/dev/null",
"--progress", "0",
"-w", width.as_str(),
"-h", height.as_str(),
"--fps-num", fps_num.as_str(),
"--preset", "12",
"-i", "-",
"-b", "-"
]).stdin(Stdio::piped()).stdout(f).spawn()?;
return Ok(VP9Encoder {cmd: cmd});
} }