From dfd96f3781827bf23ba3a85d118fc8823c65d962 Mon Sep 17 00:00:00 2001 From: Neur0toxine Date: Sun, 26 May 2024 14:39:42 +0300 Subject: [PATCH] remove last unwraps --- src/main.rs | 1 - src/transcoder.rs | 28 ++++++++++++++++++++-------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/main.rs b/src/main.rs index 70f6c0c..0d9f6d4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,4 @@ use std::env; -use tracing::Instrument; use tracing_subscriber::EnvFilter; diff --git a/src/transcoder.rs b/src/transcoder.rs index 4f3e037..3d510e7 100644 --- a/src/transcoder.rs +++ b/src/transcoder.rs @@ -228,10 +228,22 @@ fn filter_graph( decoder.channel_layout().bits() ); - filter.add(&filter::find("abuffer").unwrap(), "in", &args)?; - filter.add(&filter::find("abuffersink").unwrap(), "out", "")?; + let abuffer_filter = match filter::find("abuffer") { + Some(filter) => filter, + None => return Err(ffmpeg::Error::Unknown), + }; + filter.add(&abuffer_filter, "in", &args)?; - let mut out = filter.get("out").unwrap(); + let abuffersink_filter = match filter::find("abuffersink") { + Some(filter) => filter, + None => return Err(ffmpeg::Error::Unknown), + }; + filter.add(&abuffersink_filter, "out", "")?; + + let mut out = match filter.get("out") { + Some(filter) => filter, + None => return Err(ffmpeg::Error::Unknown), + }; out.set_sample_format(encoder.format()); out.set_channel_layout(encoder.channel_layout()); out.set_sample_rate(encoder.rate()); @@ -244,11 +256,11 @@ fn filter_graph( .capabilities() .contains(codec::capabilities::Capabilities::VARIABLE_FRAME_SIZE) { - filter - .get("out") - .unwrap() - .sink() - .set_frame_size(encoder.frame_size()); + if let Some(mut out_filter) = filter.get("out") { + out_filter + .sink() + .set_frame_size(encoder.frame_size()); + } } }