From aa6681a64de41a18a23f277e510ab3ad75712498 Mon Sep 17 00:00:00 2001 From: Neur0toxine Date: Sat, 25 May 2024 21:43:09 +0300 Subject: [PATCH] wip: transcoder (now it works, but the code is still very bad) --- src/dto.rs | 1 + src/server.rs | 1 + src/task.rs | 7 +++++-- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/dto.rs b/src/dto.rs index 012617f..51102ec 100644 --- a/src/dto.rs +++ b/src/dto.rs @@ -16,6 +16,7 @@ pub struct ConvertResponse { #[derive(TryFromMultipart)] #[try_from_multipart(rename_all = "camelCase")] pub struct ConvertRequest { + pub format: String, pub codec: String, pub codec_opts: Option, pub bit_rate: usize, diff --git a/src/server.rs b/src/server.rs index 61eda9f..13ce28f 100644 --- a/src/server.rs +++ b/src/server.rs @@ -76,6 +76,7 @@ async fn enqueue_file( let task = Task::new( task_id, + req.format, req.codec, req.codec_opts, req.bit_rate, diff --git a/src/task.rs b/src/task.rs index 00a5fa8..6106d77 100644 --- a/src/task.rs +++ b/src/task.rs @@ -8,6 +8,7 @@ use tracing::{debug, error}; pub struct Task { id: uuid::Uuid, codec: String, + format: String, codec_opts: Option, bit_rate: usize, max_bit_rate: usize, @@ -21,6 +22,7 @@ pub struct Task { impl Task { pub fn new( id: uuid::Uuid, + format: String, codec: String, codec_opts: Option, bit_rate: usize, @@ -33,6 +35,7 @@ impl Task { ) -> Self { Task { id, + format, codec, codec_opts, bit_rate, @@ -62,11 +65,11 @@ impl Task { if self.codec_opts.is_some() { octx = format::output_as_with( &self.output_path, - &self.codec, + &self.format, params_to_avdictionary(&self.codec_opts.unwrap_or_default()), ); } else { - octx = format::output_as(&self.output_path, &self.codec); + octx = format::output_as(&self.output_path, &self.format); } let mut octx = match octx {