I would like to get a consistent ordering of tracks from mediainfo - in other words, for a given media file, the order should be the same every time the code is run, on any machine.
(Assuming for now the same library version is used, but if there is a way to get an ordering that won't change with future library versions, that would be excellent too).
I think mediainfo already tries to ensure a consistent order. I have read this helpful answer which says the order is
... video first, then audio, then text, then other (including timecode); inside each kind of track, it is in the ID ascending order
This is good information about the rationale/intended behaviour but I think it is outdated, because it doesn't seem to be sorted by track ID. Using this test mkv file from this repo, I can see the text streams are not in order of ID (the text track with id 7 comes last, after id 11). They do however seem to be sorted (within each track type) by "StreamOrder" property.
I noticed there is also "typeorder" attribute in the XML output (and "@typeorder" in the JSON output) which seems to also describe the ordering within each track type.
In pymediainfo there is a "stream_identifier" which seems to give the correct order.
I am wondering, to save having to figure out which property I should be using for the ordering/sequence number and test across different media files, handle edge cases, etc., if I can just rely on the index of the track within the list of tracks. E.g. in pymediainfo for i, track in enumerate(media_info.tracks): ..., and use the index i as a sequence number for ordering.
(Note: I'm using pymediainfo, but I think this question applies to mediainfo/libmediainfo generally because from the pymediainfo source code I can see it does not sort the tracks at all but uses the ordering outputted by the underlying library's "OLDXML" output).
Thank you.