aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--stream/src/fragment.rs51
-rw-r--r--stream/src/stream_info.rs7
-rw-r--r--transcoder/src/fragment.rs4
3 files changed, 43 insertions, 19 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),
diff --git a/transcoder/src/fragment.rs b/transcoder/src/fragment.rs
index e64e690..3be7d39 100644
--- a/transcoder/src/fragment.rs
+++ b/transcoder/src/fragment.rs
@@ -35,7 +35,7 @@ pub async fn transcode(
}
.or(CONF.encoders.generic.as_ref())
.cloned()
- .unwrap_or("ffmpeg %i %f %e %o".to_owned());
+ .unwrap_or("ffmpeg %a".to_owned());
let filter = match kind {
TrackKind::Video => format!("-vf scale={}:-1", format.width.unwrap()),
@@ -58,8 +58,10 @@ pub async fn transcode(
};
let args = template
+ .replace("%a", "-hide_banner %i %f %e %o")
.replace("%i", "-f matroska -i pipe:0 -copyts")
.replace("%o", "-f matroska pipe:1")
+ .replace("%w", &format.width.unwrap_or_default().to_string())
.replace("%f", &filter)
.replace("%e", "-c:%t %c -b:%t %r")
.replace("%t", typechar)