From 763683d9b3b3d2bdd67d68541b9b81454a8e86b8 Mon Sep 17 00:00:00 2001 From: Muaz Ahmad Date: Thu, 12 Oct 2023 15:10:53 +0500 Subject: [PATCH] basic encoder commands to output to file --- src/encode/codecs/audio.rs | 15 ++++++++++++++- src/encode/codecs/video.rs | 18 +++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/encode/codecs/audio.rs b/src/encode/codecs/audio.rs index 5c2bcef..6b4293a 100644 --- a/src/encode/codecs/audio.rs +++ b/src/encode/codecs/audio.rs @@ -1,6 +1,7 @@ use std::error::Error; use std::process::{Child, Command, Stdio, ChildStdin, ChildStdout}; use std::sync::Arc; +use std::fs::File; use crate::util; use crate::encode::codecs::Encoder; @@ -12,6 +13,18 @@ pub struct OpusEncoder { impl Encoder for OpusEncoder {} pub fn new_opus(metadata: Arc) -> Result> { - 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}); } diff --git a/src/encode/codecs/video.rs b/src/encode/codecs/video.rs index 183efa6..c9fcd7a 100644 --- a/src/encode/codecs/video.rs +++ b/src/encode/codecs/video.rs @@ -1,6 +1,7 @@ use std::error::Error; use std::process::{Child, Command, Stdio, ChildStdin, ChildStdout}; use std::sync::Arc; +use std::fs::File; use crate::util; use crate::encode::codecs::Encoder; @@ -12,5 +13,20 @@ pub struct VP9Encoder { impl Encoder for VP9Encoder {} pub fn new_vp9(metadata: Arc) -> Result> { - 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}); }