Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mkv: get metadata from info element #277

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions symphonia-format-mkv/src/demuxer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ impl FormatReader for MkvReader {
}
ElementType::Info => {
info = Some(it.read_element_data::<InfoElement>()?);
info.as_ref().unwrap().copy_metadata_into(&mut metadata);
}
ElementType::Cues => {
let cues = it.read_element_data::<CuesElement>()?;
Expand Down
24 changes: 22 additions & 2 deletions symphonia-format-mkv/src/segment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

use symphonia_core::errors::{Error, Result};
use symphonia_core::io::{BufReader, ReadBytes};
use symphonia_core::meta::{MetadataBuilder, MetadataRevision, Tag, Value};
use symphonia_core::meta::{
MetadataBuilder, MetadataLog, MetadataRevision, StandardTagKey, Tag, Value,
};

use crate::ebml::{read_unsigned_vint, Element, ElementData, ElementHeader};
use crate::element_ids::ElementType;
Expand Down Expand Up @@ -269,13 +271,14 @@ impl Element for EbmlHeaderElement {
}
}

#[allow(dead_code)]
#[derive(Debug)]
pub(crate) struct InfoElement {
pub(crate) timestamp_scale: u64,
pub(crate) duration: Option<f64>,
title: Option<Box<str>>,
#[allow(dead_code)]
muxing_app: Box<str>,
#[allow(dead_code)]
writing_app: Box<str>,
}

Expand Down Expand Up @@ -323,6 +326,23 @@ impl Element for InfoElement {
}
}

impl InfoElement {
pub fn copy_metadata_into(&self, metadata_log: &mut MetadataLog) {
match &self.title {
Some(title) => {
let mut metadata = MetadataBuilder::new();
metadata.add_tag(Tag::new(
Some(StandardTagKey::TrackTitle),
"TITLE",
Value::String(title.to_string()),
));
metadata_log.push(metadata.metadata());
}
None => return,
}
}
}

#[allow(dead_code)]
#[derive(Debug)]
pub(crate) struct CuesElement {
Expand Down
Loading