aboutsummaryrefslogtreecommitdiff
path: root/remuxer/src/matroska_to_mpeg4.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-04-16 17:24:08 +0200
committermetamuffin <metamuffin@disroot.org>2025-04-16 17:24:08 +0200
commitcdf95d7b80bd2b78895671da8f462145bb5db522 (patch)
treef7f8377ee6352b313a45cb13362bbd7143fddccd /remuxer/src/matroska_to_mpeg4.rs
parentad8016d8014af1e8dfb267fcdb51da63ab8ca4a9 (diff)
downloadjellything-rewrite-stream.tar
jellything-rewrite-stream.tar.bz2
jellything-rewrite-stream.tar.zst
webm and mpeg4 fragments semi fixedrewrite-stream
Diffstat (limited to 'remuxer/src/matroska_to_mpeg4.rs')
-rw-r--r--remuxer/src/matroska_to_mpeg4.rs36
1 files changed, 36 insertions, 0 deletions
diff --git a/remuxer/src/matroska_to_mpeg4.rs b/remuxer/src/matroska_to_mpeg4.rs
new file mode 100644
index 0000000..e8268e7
--- /dev/null
+++ b/remuxer/src/matroska_to_mpeg4.rs
@@ -0,0 +1,36 @@
+/*
+ This file is part of jellything (https://codeberg.org/metamuffin/jellything)
+ which is licensed under the GNU Affero General Public License (version 3); see /COPYING.
+ Copyright (C) 2025 metamuffin <metamuffin.org>
+*/
+use anyhow::Result;
+use std::{
+ fs::{remove_file, File},
+ io::{copy, Read, Write},
+ process::{Command, Stdio},
+ random::random,
+};
+
+pub fn matroska_to_mpeg4(
+ mut input: impl Read + Send + 'static,
+ mut output: impl Write,
+) -> Result<()> {
+ let path = format!("/tmp/jellything-tc-hack-{:016x}", random::<u64>());
+ let args = format!(
+ "-hide_banner -loglevel warning -f matroska -i pipe:0 -copyts -c copy -f mp4 -movflags frag_keyframe+empty_moov {path}"
+ );
+ let mut child = Command::new("ffmpeg")
+ .args(args.split(" "))
+ .stdin(Stdio::piped())
+ .stderr(Stdio::inherit())
+ .spawn()?;
+
+ let mut stdin = child.stdin.take().unwrap();
+ copy(&mut input, &mut stdin)?;
+ drop(stdin);
+ child.wait()?.exit_ok()?;
+ copy(&mut File::open(&path)?, &mut output)?;
+ remove_file(path)?;
+
+ Ok(())
+}