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] How to obtain InfoElement::title (mkv segment title)? #273

Open
hasezoey opened this issue Mar 24, 2024 · 5 comments
Open

[mkv] How to obtain InfoElement::title (mkv segment title)? #273

hasezoey opened this issue Mar 24, 2024 · 5 comments

Comments

@hasezoey
Copy link

hasezoey commented Mar 24, 2024

Currently in symphonia 0.5.4 there does not seem to be a way to obtain mkv's InfoElement's title (ie the title that is directly stored in the segment, and not as a metadata element), or is there some way that i didnt find?

ffmpeg for example treats both the same and prints the element's title as a metadata title (unless there is also a metadata title)

some outputs:

$ cargo run --bin=symphonia-play -- /test/out.mka
|
| // Tracks //
|     [01] Codec:           Vorbis (vorbis)
|          Sample Rate:     48000
|          Duration:        0:01:29.599 (89599)
|          Time Base:       1000000/1000000000
|          Sample Format:   S32
|          Bits per Sample: 32
|          Channel Layout:  Stereo
|          Language:        und
|
| // Tags //
|     [01] ENCODER                      : Lavf60.16.100
|     [02] DURATION                     : 00:01:29.599000000
:

$ ffprobe out.mka                                         
Input #0, matroska,webm, from 'out.mka':
  Metadata:
    title           : Test title
    ENCODER         : Lavf60.16.100
  Duration: 00:01:29.60, start: 0.000000, bitrate: 108 kb/s
  Stream #0:0: Audio: vorbis, 48000 Hz, stereo, fltp
    Metadata:
      DURATION        : 00:01:29.599000000

$ hexdump -C out.mka| grep "Test"
000000e0  2a d7 b1 83 0f 42 40 7b  a9 8a 54 65 73 74 20 74  |*....B@{..Test t|

if the TITLE metadata is set, symphonia finds it:

$ cargo run --bin=symphonia-play -- /test/test_title.mka
|
| // Tracks //
|     [01] Codec:           Vorbis (vorbis)
|          Sample Rate:     48000
|          Duration:        0:01:29.599 (89599)
|          Time Base:       1000000/1000000000
|          Sample Format:   S32
|          Bits per Sample: 32
|          Channel Layout:  Stereo
|          Language:        und
|
| // Tags //
|     [01] ENCODER                      : Lavf60.16.100
|     [02] TITLE                        : Test title
|     [03] DURATION                     : 00:01:29.599000000
:

$ ffprobe test_title.mka 
Input #0, matroska,webm, from 'test_title.mka':
  Metadata:
    ENCODER         : Lavf60.16.100
    TITLE           : Test title
  Duration: 00:01:29.60, start: 0.000000, bitrate: 108 kb/s
  Stream #0:0: Audio: vorbis, 48000 Hz, stereo, fltp
    Metadata:
      DURATION        : 00:01:29.599000000

$ hexdump -C test_title.mka| grep "Test"
00129580  45 44 87 8a 54 65 73 74  20 74 69 74 6c 65 44 7b  |ED..Test titleD{|

and if both are set (on segment and metadata), then ffmpeg prefers the metadata tag and symphonia also shows the metadata tag

cargo run --bin=symphonia-play -- /test/out_title.mka
|
| // Tracks //
|     [01] Codec:           Vorbis (vorbis)
|          Sample Rate:     48000
|          Duration:        0:01:29.599 (89599)
|          Time Base:       1000000/1000000000
|          Sample Format:   S32
|          Bits per Sample: 32
|          Channel Layout:  Stereo
|          Language:        und
|
| // Tags //
|     [01] ENCODER                      : Lavf60.16.100
|     [02] TITLE                        : Test title
|     [03] DURATION                     : 00:01:29.599000000
:

$ ffprobe out_title.mka                                                                                     9s
Input #0, matroska,webm, from 'out_title.mka':
  Metadata:
    ENCODER         : Lavf60.16.100
    TITLE           : Test title
  Duration: 00:01:29.60, start: 0.000000, bitrate: 108 kb/s
  Stream #0:0: Audio: vorbis, 48000 Hz, stereo, fltp
    Metadata:
      DURATION        : 00:01:29.599000000

$ hexdump -C out_title.mka| grep "Test"
000000e0  2a d7 b1 83 0f 42 40 7b  a9 8a 54 65 73 74 20 74  |*....B@{..Test t|
00129590  8a 54 65 73 74 20 74 69  74 6c 65 44 7b 83 75 6e  |.Test titleD{.un|

also good to know is that if the metadata title is set, ffmpeg on convert will write that as the segment title (and output no metadata title, maybe unless explicitly told to also write the metadata tag)

@dedobbin
Copy link
Contributor

Hey thanks for the report. I do find it a bit odd how ffmpeg approaches the title tag, but regardless

In Symphonia, it seems the title from InfoElement is not properly used, removing #[allow(dead_code)] from https://github.com/pdeljanov/Symphonia/blob/master/symphonia-format-mkv/src/segment.rs#L272 reveals as much.

Even though it seems in the realm of MKV metadata usually only refers to the TagsElement, i would argue this title from the InfoElement could also be considered metadata, so we can store it in the metadata structure.

I think this would automatically prioritize the title of the TagsElement since it shows up later in the file and would probably overwrite the title entry by InfoElement, same behavior as ffmpeg.

Do you think this is a good way to approach it @pdeljanov ?

@pdeljanov
Copy link
Owner

pdeljanov commented Apr 1, 2024

Hey @dedobbin, @hasezoey,

The title provided in the Info element is like a general title for the segment. Within the segment, more detailed tags may be provided via the Tags element.

I don't really like the idea of overwriting one title with the other, so here are two possible solutions:

  1. Since the Info element would come first, if a title is present, create a MetadataRevision and add the title to it. Push the revision to the MetadataLog. Then, add the tags from the Tags element to a new MetadataRevision, and push it to the MetadataLog. In this way, both titles are accessible with a logical order (Info element, then Tags).
  2. Use the same MetadataRevision for both the Info and Tags element tags, but use a hardcoded tag name of SEGMENT_TITLE (v.s., the regular TITLE) for the Info element segment title.

I'm leaning towards 2 because it's easier for the end-user, but 1 has some perks too (the end-user doesn't need to look for two different tag names).

@hasezoey
Copy link
Author

hasezoey commented Apr 1, 2024

i am personally fine with either way, as long as it is available as a Metadata tag in some way (and not some out-of-the-way function) and is documented what the difference with the normal TITLE would be.

@pdeljanov
Copy link
Owner

Yeah, it'd be a bespoke tag for MKV. We can document it in the symphonia-format-mkv crate, but it wouldn't be particularly obvious unless one looks there. In this regard, solution 1 is marginally better because we could just use the typical TITLE tag name and assign the a StandardTagKey to it.

@dedobbin, any thoughts?

@dedobbin
Copy link
Contributor

@pdeljanov Sorry for late response. Holiday happened haha.

Hmm yeah i think solution 1 is the cleanest. Solution 2 was also something i had in mind because it's simpler but feels bit arbitrary to map it to a specific key for Symphonia.

Yeah my vote goes to solution 1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants