zoriya / Kyoo

A portable and vast media library solution.
https://kyoo.zoriya.dev
GNU General Public License v3.0
1.76k stars 43 forks source link

Transcoder: Prevent error caused by buggy chapters parsing by mediainfo #485

Closed Arthi-chaud closed 6 months ago

Arthi-chaud commented 6 months ago

Error handling when parsing chapters' start time. MediaInfo can sometimes give the wrong info

zoriya commented 6 months ago

With the spirited away example file:

mediainfo --Output=JSON video/spirited_away\(1\).mp4 | jq '.media.track.[] | select(."@type" == "Menu")'
{
  "@type": "Menu",
  "StreamOrder": "2",
  "ID": "3",
  "Format": "Timed Text",
  "CodecID": "text",
  "Duration": "7476.552",
  "Language": "en",
  "extra": {
    "Encoded_Date": "2021-06-18 01:48:09 UTC",
    "Tagged_Date": "2021-06-18 01:48:09 UTC",
    "Menu_For": "1,2",
    "_00_00_00_000": "Chapter 1",
    "_00_12_29_916": "Chapter 2",
    "_00_20_18_843": "Chapter 3",
    "_00_30_05_804": "Chapter 4",
    "_00_41_08_633": "Chapter 5",
    "_00_51_34_508": "Chapter 6",
    "_01_06_37_952": "Chapter 7",
    "_01_16_39_553": "Chapter 8",
    "_01_24_54_339": "Chapter 9",
    "_01_31_15_261": "Chapter 10",
    "_01_37_45_651": "Chapter 11",
    "_01_41_06_018": "Chapter 12",
    "_01_45_19_104": "Chapter 13",
    "_01_52_50_389": "Chapter 14",
    "_01_55_12_239": "Chapter 15",
    "_02_00_53_580": "Chapter 16",
    "_02_04_34_717": "Chapter 17"
  }
}

our parsing:

{
  "sha": "v1.efcc141700e89ccd6ca6cd9bda60d15fe2f85400",
  "path": "/video/spirited_away(1).mp4",
  "extension": "mp4",
  "size": 606959685,
  "duration": 7476.63,
  "container": "MPEG-4",
  "video": {
    "codec": "AVC",
    "mimeCodec": "avc1.4D4028",
    "language": null,
    "quality": "480p",
    "width": 672,
    "height": 436,
    "bitrate": 478602
  },
  "videos": [
    {
      "codec": "AVC",
      "mimeCodec": "avc1.4D4028",
      "language": null,
      "quality": "480p",
      "width": 672,
      "height": 436,
      "bitrate": 478602
    }
  ],
  "audios": [
    {
      "index": 0,
      "title": "Stereo",
      "language": "en",
      "codec": "AAC",
      "mimeCodec": "mp4a.40.2",
      "isDefault": true,
      "isForced": false
    }
  ],
  "subtitles": [],
  "fonts": [],
  "chapters": [
    {
      "startTime": 0,
      "endTime": 749.916,
      "name": "Chapter 1"
    },
    {
      "startTime": 749.916,
      "endTime": 1218.843,
      "name": "Chapter 2"
    },
    {
      "startTime": 1218.843,
      "endTime": 1805.804,
      "name": "Chapter 3"
    },
    {
      "startTime": 1805.804,
      "endTime": 2468.633,
      "name": "Chapter 4"
    },
    {
      "startTime": 2468.633,
      "endTime": 3094.508,
      "name": "Chapter 5"
    },
    {
      "startTime": 3094.508,
      "endTime": 3997.952,
      "name": "Chapter 6"
    },
    {
      "startTime": 3997.952,
      "endTime": 4599.553,
      "name": "Chapter 7"
    },
    {
      "startTime": 4599.553,
      "endTime": 5094.339,
      "name": "Chapter 8"
    },
    {
      "startTime": 5094.339,
      "endTime": 5475.261,
      "name": "Chapter 9"
    },
    {
      "startTime": 5475.261,
      "endTime": 5865.651,
      "name": "Chapter 10"
    },
    {
      "startTime": 5865.651,
      "endTime": 6066.018,
      "name": "Chapter 11"
    },
    {
      "startTime": 6066.018,
      "endTime": 6319.104,
      "name": "Chapter 12"
    },
    {
      "startTime": 6319.104,
      "endTime": 6770.389,
      "name": "Chapter 13"
    }
  ]
}

So we are missing some chapters