music-metadata 7.13.4 → 7.13.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/mp4/MP4Parser.js +12 -3
  2. package/package.json +17 -17
@@ -178,7 +178,7 @@ class MP4Parser extends BasicParser_1.BasicParser {
178
178
  this.getTrackDescription().sampleToChunkTable = stsc.entries;
179
179
  },
180
180
  /**
181
- * time to sample
181
+ * time-to-sample table
182
182
  */
183
183
  stts: async (len) => {
184
184
  const stts = await this.tokenizer.readToken(new AtomToken.SttsAtom(len));
@@ -275,13 +275,22 @@ class MP4Parser extends BasicParser_1.BasicParser {
275
275
  });
276
276
  if (audioTracks.length >= 1) {
277
277
  const audioTrack = audioTracks[0];
278
- const duration = audioTrack.duration / audioTrack.timeScale;
279
- this.metadata.setFormat('duration', duration); // calculate duration in seconds
278
+ if (audioTrack.timeScale > 0) {
279
+ const duration = audioTrack.duration / audioTrack.timeScale; // calculate duration in seconds
280
+ this.metadata.setFormat('duration', duration);
281
+ }
280
282
  const ssd = audioTrack.soundSampleDescription[0];
281
283
  if (ssd.description) {
282
284
  this.metadata.setFormat('sampleRate', ssd.description.sampleRate);
283
285
  this.metadata.setFormat('bitsPerSample', ssd.description.sampleSize);
284
286
  this.metadata.setFormat('numberOfChannels', ssd.description.numAudioChannels);
287
+ if (audioTrack.timeScale === 0 && audioTrack.timeToSampleTable.length > 0) {
288
+ const totalSampleSize = audioTrack.timeToSampleTable
289
+ .map(ttstEntry => ttstEntry.count * ttstEntry.duration)
290
+ .reduce((total, sampleSize) => total + sampleSize);
291
+ const duration = totalSampleSize / ssd.description.sampleRate;
292
+ this.metadata.setFormat('duration', duration);
293
+ }
285
294
  }
286
295
  const encoderInfo = encoderDict[ssd.dataFormat];
287
296
  if (encoderInfo) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "music-metadata",
3
3
  "description": "Music metadata parser for Node.js, supporting virtual any audio and tag format.",
4
- "version": "7.13.4",
4
+ "version": "7.13.5",
5
5
  "author": {
6
6
  "name": "Borewit",
7
7
  "url": "https://github.com/Borewit"
@@ -92,30 +92,30 @@
92
92
  "token-types": "^4.2.1"
93
93
  },
94
94
  "devDependencies": {
95
- "@types/chai": "^4.3.4",
96
- "@types/chai-as-promised": "^7.1.5",
97
- "@types/debug": "^4.1.7",
95
+ "@types/chai": "^4.3.9",
96
+ "@types/chai-as-promised": "^7.1.7",
97
+ "@types/debug": "^4.1.10",
98
98
  "@types/file-type": "^10.9.1",
99
99
  "@types/mocha": "^9.1.1",
100
- "@types/node": "^18.15.11",
101
- "@typescript-eslint/eslint-plugin": "^5.57.0",
102
- "@typescript-eslint/parser": "^5.57.0",
103
- "chai": "^4.3.7",
100
+ "@types/node": "^20.8.9",
101
+ "@typescript-eslint/eslint-plugin": "^5.62.0",
102
+ "@typescript-eslint/parser": "^5.62.0",
103
+ "chai": "^4.3.10",
104
104
  "chai-as-promised": "^7.1.1",
105
- "del-cli": "5.0.0",
106
- "eslint": "^8.37.0",
107
- "eslint-config-prettier": "^8.8.0",
108
- "eslint-import-resolver-typescript": "^3.5.4",
109
- "eslint-plugin-import": "^2.27.5",
110
- "eslint-plugin-jsdoc": "^40.1.0",
105
+ "del-cli": "5.1.0",
106
+ "eslint": "^8.52.0",
107
+ "eslint-config-prettier": "^9.0.0",
108
+ "eslint-import-resolver-typescript": "^3.6.1",
109
+ "eslint-plugin-import": "^2.29.0",
110
+ "eslint-plugin-jsdoc": "^46.8.2",
111
111
  "eslint-plugin-node": "^11.1.0",
112
- "eslint-plugin-unicorn": "^46.0.0",
112
+ "eslint-plugin-unicorn": "^46.0.1",
113
113
  "mime": "^3.0.0",
114
114
  "mocha": "^9.2.2",
115
115
  "npm-run-all": "^4.1.5",
116
116
  "nyc": "^15.1.0",
117
- "remark-cli": "^11.0.0",
118
- "remark-preset-lint-recommended": "^6.1.2",
117
+ "remark-cli": "^12.0.0",
118
+ "remark-preset-lint-recommended": "^6.1.3",
119
119
  "source-map-support": "^0.5.21",
120
120
  "ts-node": "^10.9.1",
121
121
  "typescript": "^5.0.2"