From b510ae9b29478fcb67a016e7c75d296d02327805 Mon Sep 17 00:00:00 2001 From: MattJackson <1085847+MattJackson@users.noreply.github.com> Date: Wed, 15 Apr 2026 04:50:19 +0000 Subject: [PATCH] Fix M2TS/Network output: write FMKV header for roundtrip compatibility MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - M2tsOutputStream writes FMKV metadata header before TS data - NetworkOutputStream sends FMKV header on connect - Enables M2TS→MKV and network roundtrip to work correctly --- src/mux/pesout.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/mux/pesout.rs b/src/mux/pesout.rs index e110af5..46ad158 100644 --- a/src/mux/pesout.rs +++ b/src/mux/pesout.rs @@ -16,7 +16,12 @@ impl M2tsOutputStream { pub fn create(path: &str, title: &DiscTitle) -> io::Result { let file = std::fs::File::create(path) .map_err(|e| io::Error::new(e.kind(), format!("m2ts://{}: {}", path, e)))?; - let writer = io::BufWriter::with_capacity(4 * 1024 * 1024, file); + let mut writer = io::BufWriter::with_capacity(4 * 1024 * 1024, file); + // Write FMKV metadata header so M2tsStream::open can read it back + if !title.streams.is_empty() { + let m = super::meta::M2tsMeta::from_title(title); + super::meta::write_header(&mut writer, &m)?; + } let pids = extract_pids(title); Ok(Self { muxer: TsMuxer::new(writer, &pids), title: title.clone() }) } @@ -82,7 +87,13 @@ pub struct NetworkOutputStream { impl NetworkOutputStream { pub fn connect(addr: &str, title: &DiscTitle) -> io::Result { let stream = std::net::TcpStream::connect(addr)?; - let writer = io::BufWriter::with_capacity(256 * 1024, stream); + let mut writer = io::BufWriter::with_capacity(256 * 1024, stream); + // Send FMKV metadata header immediately so receiver can read it + if !title.streams.is_empty() { + let m = super::meta::M2tsMeta::from_title(title); + super::meta::write_header(&mut writer, &m)?; + writer.flush()?; + } Ok(Self { writer, title: title.clone() }) } }