// 用真实编码的 MP4 验证 mov.js 升级（still-image-time 轨道）
import { readFileSync, writeFileSync } from 'fs';
import { pathToFileURL } from 'url';
import path from 'path';
import { fileURLToPath } from 'url';

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const movUrl = pathToFileURL(path.join(__dirname, 'js', 'mov.js')).href;
const { mp4ToLivePhotoMov, verifyLivePhotoMov } = await import(movUrl);

const mp4 = new Uint8Array(readFileSync(path.join(__dirname, '..', 'testdata', 'real.mp4')));
const uuid = 'TESTUUID-0000-0000-0000-000000000000';
const r = mp4ToLivePhotoMov(mp4, uuid, new Date('2026-05-01T09:30:00'));
console.log('warnings:', r.warnings);
console.log('stillTimeSeconds:', r.stillTimeSeconds);

const v = verifyLivePhotoMov(r.bytes);
console.log('verify:', JSON.stringify(v, null, 2));

const out = path.join(__dirname, '..', 'testdata', 'real_live.mov');
writeFileSync(out, Buffer.from(r.bytes));
console.log('written:', out, r.bytes.length, 'bytes');
