created: 2020-08-12T09:34:01.000Z

mp4dumpでmp4ファイルのメタデータ(atom)をJSONで取得する

mp4dumpを使うとJSON形式で取得できる

$ mp4dump ./test.mp4 --format json > /tmp/_
$ mp4dump ./test.mp4 --format json | jq . | head -30
[
  {
    "name": "ftyp",
    "header_size": 8,
    "size": 28,
    "major_brand": "mp42",
    "minor_version": 0,
    "compatible_brand": "avc1"
  },
  {
    "name": "moov",
    "header_size": 8,
    "size": 9187,
    "children": [
      {
        "name": "mvhd",
        "header_size": 12,
        "size": 108,
        "timescale": 10000,
        "duration": 150400,
        "duration(ms)": 15040
      },
      {
        "name": "trak",
        "header_size": 8,
        "size": 5341,
        "children": [
          {
            "name": "tkhd",
            "header_size": 12,
            
  ...

インストールはbrewでできる

$ brew install bento4

JSONをnodejsで処理するならこんな感じ

#!/usr/bin/env node
const { execFileSync } = require('child_process');
const [nodeExecutable, thisScriptPath, filename] = process.argv;
const stdout = execFileSync('/usr/local/bin/mp4dump', [filename, '--format', 'json']);
const atoms = JSON.parse(stdout);

参考