diff options
author | metamuffin <metamuffin@disroot.org> | 2025-04-19 11:48:19 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-04-19 11:48:19 +0200 |
commit | e799a338b8691837e88d1570158935d316c9efb0 (patch) | |
tree | 45a3067e011c6785db3b6e187ae94a1f8bf5fdba /stream | |
parent | 112dcf3009a09e87a619ce5729351c23b65e8d0d (diff) | |
download | jellything-e799a338b8691837e88d1570158935d316c9efb0.tar jellything-e799a338b8691837e88d1570158935d316c9efb0.tar.bz2 jellything-e799a338b8691837e88d1570158935d316c9efb0.tar.zst |
mpeg4 remux
Diffstat (limited to 'stream')
-rw-r--r-- | stream/src/fragment.rs | 51 | ||||
-rw-r--r-- | stream/src/stream_info.rs | 7 |
2 files changed, 40 insertions, 18 deletions
diff --git a/stream/src/fragment.rs b/stream/src/fragment.rs index 38987b9..0652df2 100644 --- a/stream/src/fragment.rs +++ b/stream/src/fragment.rs @@ -9,7 +9,10 @@ use jellybase::common::stream::StreamContainer; use jellyremuxer::{matroska_to_mpeg4, matroska_to_webm::matroska_to_webm}; use jellytranscoder::fragment::transcode; use log::warn; -use std::sync::Arc; +use std::{ + io::{Cursor, Seek, SeekFrom}, + sync::Arc, +}; use tokio::{fs::File, io::DuplexStream}; use tokio_util::io::SyncIoBridge; @@ -39,18 +42,42 @@ pub async fn fragment_stream( .ok_or(anyhow!("format not found"))?; if format.remux { - tokio::task::spawn_blocking(move || { - if let Err(err) = jellyremuxer::write_fragment_into( - SyncIoBridge::new(b), - &path, - track_num, - container == StreamContainer::WebM, - &info.name.unwrap_or_default(), - index, - ) { - warn!("segment stream error: {err}"); + match container { + StreamContainer::WebM | StreamContainer::Matroska => { + tokio::task::spawn_blocking(move || { + if let Err(err) = jellyremuxer::write_fragment_into( + SyncIoBridge::new(b), + &path, + track_num, + container == StreamContainer::WebM, + &info.name.unwrap_or_default(), + index, + ) { + warn!("segment stream error: {err}"); + } + }); + } + StreamContainer::MPEG4 => { + tokio::task::spawn_blocking(move || { + let mut buf = Cursor::new(Vec::new()); + if let Err(err) = jellyremuxer::write_fragment_into( + &mut buf, + &path, + track_num, + false, + &info.name.unwrap_or_default(), + index, + ) { + warn!("segment stream error: {err}"); + } + buf.seek(SeekFrom::Start(0)).unwrap(); + if let Err(err) = matroska_to_mpeg4(buf, SyncIoBridge::new(b)) { + warn!("mpeg4 transmux failed: {err}"); + } + }); } - }); + _ => bail!("not yet supported"), + } } else { let location = transcode( track.kind, diff --git a/stream/src/stream_info.rs b/stream/src/stream_info.rs index 38270b7..8592bc4 100644 --- a/stream/src/stream_info.rs +++ b/stream/src/stream_info.rs @@ -93,12 +93,7 @@ fn stream_formats(t: &TrackEntry, remux_bitrate: f64) -> Vec<StreamFormatInfo> { codec: t.codec_id.to_string(), remux: true, bitrate: remux_bitrate, - containers: { - let mut x = containers_by_codec(&t.codec_id); - // TODO remove this - x.retain_mut(|x| *x != StreamContainer::MPEG4); - x - }, + containers: containers_by_codec(&t.codec_id), 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), |