mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2025-01-11 03:35:26 +00:00
fmp4mux: Write tref
box for ONVIF timed metadata tracks to reference the first video track
This commit is contained in:
parent
6edb188899
commit
0a02d8c096
1 changed files with 51 additions and 1 deletions
|
@ -385,7 +385,29 @@ fn write_moov(v: &mut Vec<u8>, cfg: &super::HeaderConfiguration) -> Result<(), E
|
||||||
write_mvhd(v, cfg, creation_time)
|
write_mvhd(v, cfg, creation_time)
|
||||||
})?;
|
})?;
|
||||||
for (idx, caps) in cfg.caps.iter().enumerate() {
|
for (idx, caps) in cfg.caps.iter().enumerate() {
|
||||||
write_box(v, b"trak", |v| write_trak(v, cfg, idx, caps, creation_time))?;
|
write_box(v, b"trak", |v| {
|
||||||
|
let mut references = vec![];
|
||||||
|
|
||||||
|
// Reference the video track for ONVIF metadata tracks
|
||||||
|
if cfg.variant == super::Variant::ONVIF
|
||||||
|
&& caps.structure(0).unwrap().name() == "application/x-onvif-metadata"
|
||||||
|
{
|
||||||
|
// Find the first video track
|
||||||
|
for (idx, caps) in cfg.caps.iter().enumerate() {
|
||||||
|
let s = caps.structure(0).unwrap();
|
||||||
|
|
||||||
|
if matches!(s.name(), "video/x-h264" | "video/x-h265" | "image/jpeg") {
|
||||||
|
references.push(TrackReference {
|
||||||
|
reference_type: *b"cdsc",
|
||||||
|
track_ids: vec![idx as u32 + 1],
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
write_trak(v, cfg, idx, caps, creation_time, &references)
|
||||||
|
})?;
|
||||||
}
|
}
|
||||||
write_box(v, b"mvex", |v| write_mvex(v, cfg))?;
|
write_box(v, b"mvex", |v| write_mvex(v, cfg))?;
|
||||||
|
|
||||||
|
@ -472,12 +494,18 @@ const TKHD_FLAGS_TRACK_ENABLED: u32 = 0x1;
|
||||||
const TKHD_FLAGS_TRACK_IN_MOVIE: u32 = 0x2;
|
const TKHD_FLAGS_TRACK_IN_MOVIE: u32 = 0x2;
|
||||||
const TKHD_FLAGS_TRACK_IN_PREVIEW: u32 = 0x4;
|
const TKHD_FLAGS_TRACK_IN_PREVIEW: u32 = 0x4;
|
||||||
|
|
||||||
|
struct TrackReference {
|
||||||
|
reference_type: [u8; 4],
|
||||||
|
track_ids: Vec<u32>,
|
||||||
|
}
|
||||||
|
|
||||||
fn write_trak(
|
fn write_trak(
|
||||||
v: &mut Vec<u8>,
|
v: &mut Vec<u8>,
|
||||||
cfg: &super::HeaderConfiguration,
|
cfg: &super::HeaderConfiguration,
|
||||||
idx: usize,
|
idx: usize,
|
||||||
caps: &gst::CapsRef,
|
caps: &gst::CapsRef,
|
||||||
creation_time: u64,
|
creation_time: u64,
|
||||||
|
references: &[TrackReference],
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
write_full_box(
|
write_full_box(
|
||||||
v,
|
v,
|
||||||
|
@ -492,6 +520,10 @@ fn write_trak(
|
||||||
|
|
||||||
write_box(v, b"mdia", |v| write_mdia(v, cfg, caps, creation_time))?;
|
write_box(v, b"mdia", |v| write_mdia(v, cfg, caps, creation_time))?;
|
||||||
|
|
||||||
|
if !references.is_empty() {
|
||||||
|
write_box(v, b"tref", |v| write_tref(v, cfg, references))?;
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -598,6 +630,24 @@ fn write_mdia(
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn write_tref(
|
||||||
|
v: &mut Vec<u8>,
|
||||||
|
_cfg: &super::HeaderConfiguration,
|
||||||
|
references: &[TrackReference],
|
||||||
|
) -> Result<(), Error> {
|
||||||
|
for reference in references {
|
||||||
|
write_box(v, &reference.reference_type, |v| {
|
||||||
|
for track_id in &reference.track_ids {
|
||||||
|
v.extend(track_id.to_be_bytes());
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
})?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
fn language_code(lang: impl std::borrow::Borrow<[u8; 3]>) -> u16 {
|
fn language_code(lang: impl std::borrow::Borrow<[u8; 3]>) -> u16 {
|
||||||
let lang = lang.borrow();
|
let lang = lang.borrow();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue