← Back to index

document_type: "demo_guide" service: "MOMENTRY_CORE" title: "M5API Pipeline Demo" date: "2026-05-16" version: "V1.0" status: "active" owner: "M5" created_by: "OpenCode" tags: - "demo" - "pipeline" - "api" - "m5api" ai_query_hints: - "M5API Pipeline demo" - "如何透過 M5 的 API 執行 Pipeline" related_documents: - "GUIDES/Demo_EndToEnd.md" - "GUIDES/API_ENDPOINTS.md"


Momentry Core — M5API Pipeline Demo

項目 內容
建立者 OpenCode
建立時間 2026-05-16
文件版本 V1.0
目標讀者 developer
預備知識 需有 API Key、M5 服務已啟動

Prerequisites

API="https://m5api.momentry.ddns.net"
KEY="muser_68600856036340bcafc01930eb4bd839_1774418104_97221b69"

Step 1: System Health Check

curl -sf "$API/health" | jq '{ip, port, status, version, build_git_hash}'

Response:

{
  "ip": "192.168.110.201",
  "port": 3002,
  "status": "ok",
  "version": "1.0.0",
  "build_git_hash": "c41f7e0c"
}

All core services verified:

curl -sf "$API/health/detailed" | jq '{
  services, schema: .schema.ok,
  scripts: .pipeline.scripts_count,
  integrity: .pipeline.scripts_integrity,
  procs: [.pipeline.processors | to_entries[] | select(.value==true and .key!="total_py_files") | .key]
}'

Response:

{
  "services": {
    "postgres": {"status": "ok"},
    "redis": {"status": "ok"},
    "qdrant": {"status": "ok"},
    "mongodb": {"status": "ok"}
  },
  "schema": true,
  "scripts": 286,
  "integrity": {"matched": 345, "total": 345, "ok": true},
  "procs": ["asr","yolo","face","pose","ocr","cut","caption","scene","story","asrx","probe","visual_chunk"]
}

Step 2: List Registered Files

curl -sf -H "X-API-Key: $KEY" "$API/api/v1/files?page=1&page_size=5" | \
  jq '{total, files: [.data[]? | {name: .file_name[0:50], status}]}'

Response:

{
  "total": 56,
  "files": [
    {"name": "Charade (1963) Cary Grant & Audrey Hepburn ...", "status": "completed"},
    {"name": "ExaSAN PCIe series - Director Ou Yu-Zhi ...", "status": "completed"},
    {"name": "Old_Time_Movie_Show_-_Charade_1963.HD.mov", "status": "completed"},
    {"name": "Old Felix the Cat Cartoon.mp4", "status": "unregistered"},
    {"name": "short_clip.mov", "status": "completed"}
  ]
}

Step 3: Register a New File

# POST with file_path (must exist on server filesystem)
curl -sf -X POST -H "X-API-Key: $KEY" -H "Content-Type: application/json" \
  -d '{"file_path": "/path/to/video.mp4"}' \
  "$API/api/v1/files/register" | jq '{success, file_uuid, file_name, file_type, duration, fps, already_exists}'

Response (new registration):

{
  "success": true,
  "file_uuid": "3abeee81d94597629ed8cb943f182e94",
  "file_name": "Charade (1963) Cary Grant & Audrey Hepburn ...mp4",
  "file_type": "video",
  "duration": 6785.014,
  "fps": 23.976,
  "already_exists": false
}

Response (duplicate content — SHA256 dedup):

{
  "success": true,
  "already_exists": true,
  "message": "Content already registered (identical file)"
}

Step 4: Probe (ffprobe Metadata)

UUID="3abeee81d94597629ed8cb943f182e94"

curl -sf -H "X-API-Key: $KEY" "$API/api/v1/file/${UUID}/probe" | \
  jq '{name: .file_name, video: "\(.width)x\(.height)", fps, duration, cached, streams: [.streams[] | {type: .codec_type, codec: .codec_name}]}'

Response:

{
  "name": "Charade (1963) Cary Grant & Audrey Hepburn ...mp4",
  "video": "720x304",
  "fps": 23.976,
  "duration": 6785.014,
  "cached": true,
  "streams": [
    {"type": "video", "codec": "h264"},
    {"type": "audio", "codec": "aac"}
  ]
}

Error cases:

# Non-existent UUID
curl -sf "https://m5api.momentry.ddns.net/api/v1/file/bad_uuid/probe"
# → {"error":"Video not found","file_uuid":"bad_uuid"}  HTTP 404

# File deleted from disk
# → {"error":"File does not exist at registered path","file_uuid":"...","file_path":"..."}  HTTP 404

Step 5: Submit Processing Job

# Specific processors
curl -sf -X POST -H "X-API-Key: $KEY" -H "Content-Type: application/json" \
  -d '{"processors":["asr","cut","yolo","face","pose","ocr"]}' \
  "$API/api/v1/file/${UUID}/process" | jq '{job_id, file_uuid: .file_uuid[0:16], status}'

Response:

{
  "job_id": 167,
  "file_uuid": "3abeee81d9459762",
  "status": "PENDING"
}

All processors: Send {} (empty body) to run all 12 processors. Available: asr, cut, yolo, face, pose, ocr, asrx, visual_chunk, scene, story, caption


Step 6: Monitor Progress

while true; do
  PROGRESS=$(curl -sf -H "X-API-Key: $KEY" "$API/api/v1/progress/${UUID}")
  STATUS=$(echo "$PROGRESS" | jq -r '.status // "?"')
  PROCS=$(echo "$PROGRESS" | jq -r '[.processors[]? | "\(.name)=\(.status)(\(.frames_processed))"] | join("  ")')
  echo "$(date +%H:%M:%S): $PROCS"
  echo "$PROCS" | grep -q "completed" && break
  sleep 10
done

Typical output:

12:30:01: asr=pending(0)  cut=pending(0)  yolo=pending(0)  face=pending(0)  pose=pending(0)  ocr=pending(0)
12:30:11: asr=running(0)  cut=running(0)  yolo=pending(0)  face=pending(0)  pose=pending(0)  ocr=pending(0)
12:30:21: asr=running(0)  cut=completed(8951)  yolo=running(0)  face=pending(0)  pose=pending(0)  ocr=pending(0)
12:30:31: asr=running(0)  cut=completed(8951)  yolo=completed(8951)  face=running(0)  pose=pending(0)
12:30:41: asr=running(0)  cut=completed(8951)  yolo=completed(8951)  face=completed(8951)  pose=running(0)
12:30:51: asr=completed(8951)  cut=completed(8951)  yolo=completed(8951)  face=completed(8951)  pose=completed(8951)  ocr=running(0)
12:31:01: asr=completed(8951)  cut=completed(8951)  yolo=completed(8951)  face=completed(8951)  pose=completed(8951)  ocr=completed(8951)

Status transition chain: pending → running → completed

Check job state:

curl -sf -H "X-API-Key: $KEY" "$API/api/v1/jobs?uuid=${UUID}" | \
  jq '[.jobs[]? | {id, status}]'

Step 7: Verify Results

curl -sf -H "X-API-Key: $KEY" "$API/api/v1/progress/${UUID}" | \
  jq '{processors: [.processors[] | {name, status, frames: .frames_processed}]}'

Response:

{
  "processors": [
    {"name": "asr", "status": "completed", "frames": 162568},
    {"name": "cut", "status": "completed", "frames": 162568},
    {"name": "yolo", "status": "completed", "frames": 162568},
    {"name": "face", "status": "completed", "frames": 162568},
    {"name": "pose", "status": "completed", "frames": 162568},
    {"name": "ocr", "status": "completed", "frames": 162568}
  ]
}

Step 8: Universal Search

# Search for a person name
curl -sf -X POST -H "X-API-Key: $KEY" -H "Content-Type: application/json" \
  -d "{\"query\":\"Audrey\",\"uuid\":\"${UUID}\",\"limit\":3}" \
  "$API/api/v1/search/universal" | \
  jq '{total, hits: [.results[]? | {chunk_id: .chunk_id[0:40], text: .text[0:80], score}]}'

Response:

{
  "total": 2,
  "hits": [
    {
      "chunk_id": "3abeee81d94597629ed8cb943f182e94_998192",
      "text": "Shorede stars two legends of classical Hollywood, Audrey Hepburn and Carrie Gran",
      "score": 0.9
    },
    {
      "chunk_id": "3abeee81d94597629ed8cb943f182e94_998193",
      "text": "Shorede stars two legends of classical Hollywood, Audrey Hepburn and Carrie Gran",
      "score": 0.9
    }
  ]
}
# Search Chinese text
curl -sf -X POST -H "X-API-Key: $KEY" -H "Content-Type: application/json" \
  -d "{\"query\":\"導演\",\"uuid\":\"${UUID}\",\"limit\":3}" \
  "$API/api/v1/search/universal" | jq '{total}'

Search modes: The universal search endpoint supports: - Text match (ILIKE on text_content and content columns) - Time range filtering (time_range: [start, end]) - Speaker/person ID filtering - Chunk type filtering - Visual content filtering (objects, density, classes)


Step 9: Get Chunk Detail

CHUNK_ID="3abeee81d94597629ed8cb943f182e94_998192"

curl -sf -H "X-API-Key: $KEY" "$API/api/v1/file/${UUID}/chunk/${CHUNK_ID}" | \
  jq '{chunk_id, chunk_type, text: .text_content, fps, start_frame, end_frame}'

Response:

{
  "chunk_id": "3abeee81d94597629ed8cb943f182e94_998192",
  "chunk_type": "sentence",
  "text": "Shorede stars two legends of classical Hollywood, Audrey Hepburn and Carrie Gran",
  "fps": 23.976,
  "start_frame": 2395281,
  "end_frame": 2395341
}

Step 10: Chunk Fallback (Stale Qdrant Compatibility)

Old integer-format chunk_ids from stale Qdrant payloads are automatically resolved via WHERE id = int(chunk_id):

# Integer format (old Qdrant payload)
curl -sf -H "X-API-Key: $KEY" "$API/api/v1/file/${UUID}/chunk/998192" | \
  jq '{chunk_id, text: .text_content}'

Response (same chunk as above):

{
  "chunk_id": "3abeee81d94597629ed8cb943f182e94_998192",
  "text": "Shorede stars two legends of classical Hollywood, Audrey Hepburn and Carrie Gran"
}

Both formats work: - chunk/{uuid}_{id} → exact chunk_id match - chunk/{id} → fallback by primary key id


Step 11: File Detail

curl -sf -H "X-API-Key: $KEY" "$API/api/v1/file/${UUID}" | \
  jq '{file_name, status, file_type, file_path}'

Response:

{
  "file_name": "Charade (1963) Cary Grant & Audrey Hepburn ...mp4",
  "status": "completed",
  "file_type": "video",
  "file_path": "/Users/accusys/momentry/var/sftpgo/data/demo/Charade..."
}

Step 12: File Identities

curl -sf -H "X-API-Key: $KEY" "$API/api/v1/file/${UUID}/identities" | \
  jq '{total, identities: [.data[]? | {name, face_count, confidence}]}'

Response:

{
  "total": 2,
  "identities": [
    {"name": "Audrey Hepburn", "face_count": 22082, "confidence": 0.93},
    {"name": "Cary Grant", "face_count": 15334, "confidence": 0.91}
  ]
}

Step 13: Identity Detail

# List all global identities
curl -sf -H "X-API-Key: $KEY" "$API/api/v1/identities?page=1&page_size=3" | \
  jq '{total, identities: [.data[]? | {name, type: .identity_type, source}]}'
# Get identity files (cross-file faces)
IDENTITY_UUID="c3545906-c82d-4b66-aa1d-150bc02decce"
curl -sf -H "X-API-Key: $KEY" "$API/api/v1/identity/${IDENTITY_UUID}/files" | \
  jq '{total, files: [.data[]? | {file_uuid: .file_uuid[0:16], face_count}]}'

Step 14: Schema & Integrity Verification

curl -sf "$API/health/detailed" | jq '{
  ip, port,
  schema: .schema.ok,
  migrations: [.schema.applied[]?.filename],
  integrity: .pipeline.scripts_integrity
}'

Response:

{
  "ip": "192.168.110.201",
  "port": 3002,
  "schema": true,
  "migrations": [
    "migrate_add_content_hash.sql",
    "migrate_add_registered_status.sql",
    "migrate_add_schema_version.sql",
    "migrate_cleanup_inactive_identities.sql",
    "migrate_public_schema_v4_tables.sql",
    "migrate_public_schema_v4.sql",
    "migrate_public_v4_complete.sql",
    "migrate_fix_chunk_id_format.sql",
    "migrate_add_identity_indexes.sql"
  ],
  "integrity": {"matched": 345, "total": 345, "ok": true}
}

Full Automation Script

#!/bin/bash
set -euo pipefail

API="${API:-https://m5api.momentry.ddns.net}"
KEY="${KEY:-muser_68600856036340bcafc01930eb4bd839_1774418104_97221b69}"

# 1. Health
echo "=== Health ==="
curl -sf "$API/health" | jq '{status, version, build_git_hash}'

# 2. Register file (argument: file path)
FILE_PATH="${1:?Usage: $0 <file_path>}"
echo "=== Register ==="
REG=$(curl -sf -X POST -H "X-API-Key: $KEY" -H "Content-Type: application/json" \
  -d "{\"file_path\":\"$FILE_PATH\"}" "$API/api/v1/files/register")
echo "$REG" | jq '{success, file_uuid, file_name}'
UUID=$(echo "$REG" | jq -r '.file_uuid')
[ -z "$UUID" ] && { echo "Registration failed"; exit 1; }

# 3. Probe
echo "=== Probe ==="
curl -sf -H "X-API-Key: $KEY" "$API/api/v1/file/${UUID}/probe" | \
  jq '{name, fps, duration}'

# 4. Submit job
echo "=== Process ==="
curl -sf -X POST -H "X-API-Key: $KEY" -H "Content-Type: application/json" \
  -d '{}' "$API/api/v1/file/${UUID}/process" | jq '{job_id, status}'

# 5. Poll progress
echo "=== Waiting for pipeline... ==="
while true; do
  PROGRESS=$(curl -sf -H "X-API-Key: $KEY" "$API/api/v1/progress/${UUID}")
  STATUS=$(echo "$PROGRESS" | jq -r '.status // "?"')
  echo "$(date +%H:%M:%S): $(echo "$PROGRESS" | jq -r '[.processors[]? | "\(.name)=\(.status)(\(.frames_processed))"] | join("  ")')"
  echo "$PROGRESS" | jq -e '[.processors[]? | select(.status == "pending")] | length == 0' >/dev/null && break
  sleep 10
done

# 6. Search
echo "=== Search ==="
curl -sf -X POST -H "X-API-Key: $KEY" -H "Content-Type: application/json" \
  -d "{\"query\":\"test\",\"uuid\":\"${UUID}\",\"limit\":3}" \
  "$API/api/v1/search/universal" | jq '{total, hits: [.results[]? | {chunk_id: .chunk_id[0:30], text: .text[0:60]}]}'

echo ""
echo "✅ Done: $UUID"