From 39dee6820db4581fa41cfac8bcfdd399a96f5319 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Wed, 16 Apr 2025 00:09:35 +0200 Subject: transcode impl but broken --- stream/src/fragment.rs | 32 ++++++++++++++++++++++++-------- stream/src/stream_info.rs | 13 +++++++++---- 2 files changed, 33 insertions(+), 12 deletions(-) (limited to 'stream') diff --git a/stream/src/fragment.rs b/stream/src/fragment.rs index 26746fc..2ce3c78 100644 --- a/stream/src/fragment.rs +++ b/stream/src/fragment.rs @@ -4,8 +4,9 @@ Copyright (C) 2025 metamuffin */ use crate::{stream_info, SMediaInfo}; -use anyhow::{anyhow, Result}; +use anyhow::{anyhow, bail, Result}; use jellybase::common::stream::StreamContainer; +use jellyremuxer::matroska_to_mpeg4; use jellytranscoder::fragment::transcode; use log::warn; use std::sync::Arc; @@ -55,14 +56,13 @@ pub async fn fragment_stream( &format!("{path:?} {track_num} {index} {format_num} {container}"), // TODO maybe not use the entire source track.kind, format, - container, move |b| { tokio::task::spawn_blocking(move || { if let Err(err) = jellyremuxer::write_fragment_into( SyncIoBridge::new(b), &path, track_num, - container == StreamContainer::WebM, + false, &info.name.unwrap_or_default(), index, ) { @@ -72,12 +72,28 @@ pub async fn fragment_stream( }, ) .await?; - let mut output = File::open(location.abs()).await?; - tokio::task::spawn(async move { - if let Err(err) = tokio::io::copy(&mut output, &mut b).await { - warn!("cannot write stream: {err}") + eprintln!("{:?}", location.abs()); + let mut frag = File::open(location.abs()).await?; + match container { + StreamContainer::WebM => {} + StreamContainer::Matroska => { + tokio::task::spawn(async move { + if let Err(err) = tokio::io::copy(&mut frag, &mut b).await { + warn!("cannot write stream: {err}") + } + }); } - }); + StreamContainer::MPEG4 => { + tokio::task::spawn_blocking(move || { + if let Err(err) = + matroska_to_mpeg4(SyncIoBridge::new(frag), SyncIoBridge::new(b)) + { + warn!("mpeg4 transmux failed: {err}"); + } + }); + } + _ => bail!("unsupported"), + } } Ok(()) diff --git a/stream/src/stream_info.rs b/stream/src/stream_info.rs index 43c536a..c3746c6 100644 --- a/stream/src/stream_info.rs +++ b/stream/src/stream_info.rs @@ -79,7 +79,12 @@ fn stream_formats(t: &TrackEntry) -> Vec { codec: t.codec_id.to_string(), remux: true, bitrate: 10_000_000., // TODO - containers: containers_by_codec(&t.codec_id), + containers: { + let mut x = containers_by_codec(&t.codec_id); + // TODO remove this + x.retain_mut(|x| *x != StreamContainer::MPEG4); + x + }, bit_depth: t.audio.as_ref().and_then(|a| a.bit_depth.map(|e| e as u8)), samplerate: t.audio.as_ref().map(|a| a.sampling_frequency), channels: t.audio.as_ref().map(|a| a.channels as usize), @@ -101,8 +106,8 @@ fn stream_formats(t: &TrackEntry) -> Vec { ("V_AV1", CONF.encoders.av1.is_some()), ("V_VP8", CONF.encoders.vp8.is_some()), ("V_VP9", CONF.encoders.vp9.is_some()), - ("V_AVC", CONF.encoders.avc.is_some()), - ("V_HEVC", CONF.encoders.hevc.is_some()), + ("V_MPEG4/ISO/AVC", CONF.encoders.avc.is_some()), + ("V_MPEGH/ISO/HEVC", CONF.encoders.hevc.is_some()), ] { if enable { formats.push(StreamFormatInfo { @@ -146,7 +151,7 @@ fn containers_by_codec(codec: &str) -> Vec { use StreamContainer::*; match codec { "V_VP8" | "V_VP9" | "V_AV1" | "A_OPUS" | "A_VORBIS" => vec![Matroska, WebM], - "V_AVC" | "A_AAC" => vec![Matroska, MPEG4], + "V_MPEG4/ISO/AVC" | "A_AAC" => vec![Matroska, MPEG4], "S_TEXT/UTF8" | "S_TEXT/WEBVTT" => vec![Matroska, WebVTT, WebM, JVTT], _ => vec![Matroska], } -- cgit v1.2.3-70-g09d2