jackwener/OpenCLI · error · CommandExecutionError

Instagram private publish failed to read video metadata for

Error message

Instagram private publish failed to read video metadata for ${filePath}

What it means

After the Swift AVFoundation helper runs, readVideoMetadata validates that width, height, and durationMs are all truthy (clis/instagram/_shared/private-publish.js:453). If any is missing or zero it throws, because the private publisher needs valid dimensions and duration to build the media payload. This usually means the file is not a readable video or has no video track.

Source

Thrown at clis/instagram/_shared/private-publish.js:453

let asset = AVURLAsset(url: url)
guard let track = asset.tracks(withMediaType: .video).first else {
  fputs("{\\"error\\":\\"missing-video-track\\"}", stderr)
  exit(1)
}
let transformed = track.naturalSize.applying(track.preferredTransform)
let width = Int(abs(transformed.width.rounded()))
let height = Int(abs(transformed.height.rounded()))
let durationMs = Int((CMTimeGetSeconds(asset.duration) * 1000.0).rounded())
let payload: [String: Int] = [
  "width": width,
  "height": height,
  "durationMs": durationMs,
]
let data = try JSONSerialization.data(withJSONObject: payload, options: [])
FileHandle.standardOutput.write(data)
`, [filePath], 'read video metadata');
    if (!metadata.width || !metadata.height || !metadata.durationMs) {
        throw new CommandExecutionError(`Instagram private publish failed to read video metadata for ${filePath}`);
    }
    return {
        width: metadata.width,
        height: metadata.height,
        durationMs: metadata.durationMs,
    };
}
function buildPrivateVideoCoverPath(filePath) {
    const parsed = path.parse(filePath);
    return path.join(os.tmpdir(), `opencli-instagram-private-video-cover-${parsed.name}-${crypto.randomUUID()}.jpg`);
}
function buildPrivateStoryVideoPath(filePath) {
    const parsed = path.parse(filePath);
    return path.join(os.tmpdir(), `opencli-instagram-story-video-${parsed.name}-${crypto.randomUUID()}${parsed.ext || '.mp4'}`);
}
function generateVideoCoverImage(filePath) {
    if (process.platform !== 'darwin') {
        throw new CommandExecutionError(`Instagram private mixed-media publish does not support generating video covers on ${process.platform}`, 'Use macOS for private mixed-media publishing, or rely on the UI fallback');

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Verify the filePath points to an actual video file that macOS QuickTime can play
  2. Re-encode the video to a standard H.264/AAC mp4 (e.g. `ffmpeg -i in.mov -c:v libx264 -c:a aac out.mp4`)
  3. Check the file exists and is non-empty before publishing
  4. If the Swift script printed 'missing-video-track', the container has no video stream — replace the asset

Example fix

// before
const meta = await metadata('cover.jpg'); // no video track
// after
if (!filePath.endsWith('.mp4')) throw new Error('expected an mp4 video');
const meta = await metadata(filePath);
Defensive patterns

Strategy: validation

Validate before calling

const fs = require('fs');
if (!fs.existsSync(filePath) || fs.statSync(filePath).size === 0) {
  throw new Error(`not a readable video: ${filePath}`);
}
if (!/\.(mp4|mov|m4v)$/i.test(filePath)) {
  throw new Error('expected an mp4/mov video for private publish');
}

Type guard

const looksLikeVideo = (p) => /\.(mp4|mov|m4v)$/i.test(p) && fs.statSync(p).size > 0;

Try / catch

try { const meta = await metadata(videoPath); }
catch (e) {
  if (/failed to read video metadata/.test(e.message)) {
    console.error('Re-encode with ffmpeg -c:v libx264 -c:a aac and retry');
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling metadata on a file whose Swift script returns partial/empty JSON: the file is corrupt, is an audio-only or image file, uses a codec AVFoundation cannot decode, or the path is wrong so the asset has no video track (the helper exits 1 with 'missing-video-track', surfaced through 1910's stage wrapper, or returns zeros).

Common situations: Pointing the publisher at a thumbnail .jpg instead of the video; videos encoded with unsupported codecs (e.g. some HEVC/AV1 variants); truncated downloads; files on unmounted volumes so AVURLAsset fails to read them.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/8b036a3c789e944d. Report an issue: GitHub.