From a7513d5f0db18570cc7db405810ce66cab6475e4 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Mon, 2 Oct 2023 13:45:30 +0200 Subject: broken transcode --- transcoder/src/lib.rs | 1 + transcoder/src/snippet.rs | 36 ++++++++++++++++++++++-------------- 2 files changed, 23 insertions(+), 14 deletions(-) (limited to 'transcoder') diff --git a/transcoder/src/lib.rs b/transcoder/src/lib.rs index 167303d..240d37a 100644 --- a/transcoder/src/lib.rs +++ b/transcoder/src/lib.rs @@ -4,5 +4,6 @@ Copyright (C) 2023 metamuffin */ #![feature(async_closure)] +#![feature(exit_status_error)] pub mod image; pub mod snippet; diff --git a/transcoder/src/snippet.rs b/transcoder/src/snippet.rs index 56bd523..5afeb15 100644 --- a/transcoder/src/snippet.rs +++ b/transcoder/src/snippet.rs @@ -4,10 +4,14 @@ Copyright (C) 2023 metamuffin */ -use jellybase::{cache::async_cache_file, AssetLocationExt}; +use jellybase::cache::async_cache_file; use jellycommon::AssetLocation; +use log::info; use std::process::Stdio; -use tokio::{fs::File, process::Command}; +use tokio::{ + io::copy, + process::{ChildStdin, Command}, +}; #[derive(Debug)] pub enum Encoding { @@ -19,16 +23,15 @@ pub enum Encoding { }, } -pub async fn transcode(asset: AssetLocation, enc: Encoding) -> anyhow::Result { - let original_path = asset.path(); - let asset = asset.clone(); +pub async fn transcode( + key: &str, + enc: Encoding, + input: impl FnOnce(ChildStdin), +) -> anyhow::Result { Ok(async_cache_file( - &[ - "snip-tc", - original_path.as_os_str().to_str().unwrap(), - &format!("{enc:?}"), - ], - move |output| async move { + &["snip-tc", key, &format!("{enc:?}")], + move |mut output| async move { + info!("transcoding snippet {key}"); let args = match enc { Encoding::Video { codec, @@ -50,14 +53,19 @@ pub async fn transcode(asset: AssetLocation, enc: Encoding) -> anyhow::Result