Structure of MKV tracks lost in JSON output

Started by DennisDerichs, October 28, 2020, 03:55:25 AM

Previous topic - Next topic

DennisDerichs

First of all: Thanks for building and maintaining exiftool, Phil!  :)

System type: MacOS
ExifTool version: 12.00
Command line: exiftool -a -g -struct -j my_movie.mkv
Abbreviated output:

{
  "SourceFile": "my_movie.mkv",
  "ExifTool": {
    "ExifToolVersion": 12.00
  },
  "Matroska": {
    "EBMLVersion": 1,
    "EBMLReadVersion": 1,
    "DocType": "matroska",
    "DocTypeVersion": 4,
    "DocTypeReadVersion": 2,
    "TimecodeScale": "1 ms",
    "MuxingApp": "Lavf58.29.100",
    "WritingApp": "HandBrake 1.3.3 2020061300",
    "DateTimeOriginal": "2020:10:26 14:43:34Z",
    "Duration": "1:31:51",
    "VideoFrameRate": 25,
    "ImageWidth": 702,
    "ImageHeight": 462,
    "DisplayWidth": 832,
    "DisplayHeight": 385,
    "DisplayUnit": "Unknown (3)",
    "VideoCodecID": "A_AAC",
    "AudioChannels": 2,
    "AudioSampleRate": 48000,
    "AudioCodecID": "S_VOBSUB",
    "TrackNumber": 6,
    "TrackName": "Deutsch",
    "TrackLanguage": "ger",
    "TrackDefault": "No",
    "CodecID": "S_VOBSUB",
    "TrackType": "Subtitle",
    "TagName": "DURATION",
    "TagString": "01:31:50.060000000"
  },
}


I'm trying to export track details of a Matroska video as JSON. Despite several attempts using combinations of command line options such as -struct, -g and -a, exiftool keeps flattening the track details. Since there are multiple tracks, flattening them is obvious not ideal. Looking at Matroska.pm around line 866, I see that the group name gets set to "Track#", which I do see in the XML output. But in the JSON output the tags related to tracks still seem to go into the "Matroska" group and thus get flattened.

Phil Harvey

Hi Dennis,

Try using -g1 instead of -g in your command.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

DennisDerichs

Thanks a lot! Somehow I didn't realize the relevance of the number from the command line argument help.
Now that that's out of the way, I noticed that the key names for codec for each track is shifted by one track. Here's the output of my example movie with one video track, two audio tracks and two subtitle tracks:

  "Track1": {
    "TrackNumber": 1,
    "TrackLanguage": "und",
    "CodecID": "V_MPEG4/ISO/AVC",
    "TrackType": "Video",
    "VideoFrameRate": 25,
    "ImageWidth": 720,
    "ImageHeight": 552,
    "DisplayWidth": 1024,
    "DisplayHeight": 552,
    "DisplayUnit": "Unknown (3)"
  },
  "Track2": {
    "TrackNumber": 2,
    "TrackName": "Stereo",
    "TrackLanguage": "eng",
    "VideoCodecID": "A_AAC",
    "TrackType": "Audio",
    "AudioChannels": 2,
    "AudioSampleRate": 48000
  },
  "Track3": {
    "TrackNumber": 3,
    "TrackName": "Stereo",
    "TrackLanguage": "ger",
    "TrackDefault": "No",
    "AudioCodecID": "A_AAC",
    "TrackType": "Audio",
    "AudioChannels": 2,
    "AudioSampleRate": 48000
  },
  "Track4": {
    "TrackNumber": 4,
    "TrackLanguage": "eng",
    "TrackDefault": "No",
    "AudioCodecID": "S_VOBSUB",
    "TrackType": "Subtitle"
  },
  "Track5": {
    "TrackNumber": 5,
    "TrackLanguage": "ger",
    "TrackDefault": "No",
    "CodecID": "S_VOBSUB",
    "TrackType": "Subtitle"
  },

The codec for track 2, which is type audio, is named VideoCodecID. The previous track was a video track.
The codec for track 4, which is type subtitle, is named AudioCodecID. The previous track was an audio track.
Could this be an off-by-one error in the parser?

Phil Harvey

Quote from: DennisDerichs on October 28, 2020, 10:25:51 AM
The codec for track 2, which is type audio, is named VideoCodecID. The previous track was a video track.
The codec for track 4, which is type subtitle, is named AudioCodecID. The previous track was an audio track.
Could this be an off-by-one error in the parser?

Ah, yes.  Unfortunately the TrackType tag comes after the CodecID tag.  I'll have to figure out how to handle this situation.

What I think I may have to do is just extract this as CodecID in this case.

Good catch.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).