{"record":{"id":"8b036a3c789e944d","repo":"jackwener/OpenCLI","slug":"instagram-private-publish-failed-to-read-video-met","errorCode":null,"errorMessage":"Instagram private publish failed to read video metadata for ${filePath}","messagePattern":"Instagram private publish failed to read video metadata for (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/instagram/_shared/private-publish.js","lineNumber":453,"sourceCode":"let asset = AVURLAsset(url: url)\nguard let track = asset.tracks(withMediaType: .video).first else {\n  fputs(\"{\\\\\"error\\\\\":\\\\\"missing-video-track\\\\\"}\", stderr)\n  exit(1)\n}\nlet transformed = track.naturalSize.applying(track.preferredTransform)\nlet width = Int(abs(transformed.width.rounded()))\nlet height = Int(abs(transformed.height.rounded()))\nlet durationMs = Int((CMTimeGetSeconds(asset.duration) * 1000.0).rounded())\nlet payload: [String: Int] = [\n  \"width\": width,\n  \"height\": height,\n  \"durationMs\": durationMs,\n]\nlet data = try JSONSerialization.data(withJSONObject: payload, options: [])\nFileHandle.standardOutput.write(data)\n`, [filePath], 'read video metadata');\n    if (!metadata.width || !metadata.height || !metadata.durationMs) {\n        throw new CommandExecutionError(`Instagram private publish failed to read video metadata for ${filePath}`);\n    }\n    return {\n        width: metadata.width,\n        height: metadata.height,\n        durationMs: metadata.durationMs,\n    };\n}\nfunction buildPrivateVideoCoverPath(filePath) {\n    const parsed = path.parse(filePath);\n    return path.join(os.tmpdir(), `opencli-instagram-private-video-cover-${parsed.name}-${crypto.randomUUID()}.jpg`);\n}\nfunction buildPrivateStoryVideoPath(filePath) {\n    const parsed = path.parse(filePath);\n    return path.join(os.tmpdir(), `opencli-instagram-story-video-${parsed.name}-${crypto.randomUUID()}${parsed.ext || '.mp4'}`);\n}\nfunction generateVideoCoverImage(filePath) {\n    if (process.platform !== 'darwin') {\n        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');","sourceCodeStart":435,"sourceCodeEnd":471,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/instagram/_shared/private-publish.js#L435-L471","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Verify the filePath points to an actual video file that macOS QuickTime can play","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`)","Check the file exists and is non-empty before publishing","If the Swift script printed 'missing-video-track', the container has no video stream — replace the asset"],"exampleFix":"// before\nconst meta = await metadata('cover.jpg'); // no video track\n// after\nif (!filePath.endsWith('.mp4')) throw new Error('expected an mp4 video');\nconst meta = await metadata(filePath);","handlingStrategy":"validation","validationCode":"const fs = require('fs');\nif (!fs.existsSync(filePath) || fs.statSync(filePath).size === 0) {\n  throw new Error(`not a readable video: ${filePath}`);\n}\nif (!/\\.(mp4|mov|m4v)$/i.test(filePath)) {\n  throw new Error('expected an mp4/mov video for private publish');\n}","typeGuard":"const looksLikeVideo = (p) => /\\.(mp4|mov|m4v)$/i.test(p) && fs.statSync(p).size > 0;","tryCatchPattern":"try { const meta = await metadata(videoPath); }\ncatch (e) {\n  if (/failed to read video metadata/.test(e.message)) {\n    console.error('Re-encode with ffmpeg -c:v libx264 -c:a aac and retry');\n  }\n  throw e;\n}","preventionTips":["Pre-validate the file exists, is non-empty, and has a video extension","Re-encode unusual codecs to H.264/AAC mp4 before publishing","Confirm the file opens in QuickTime, which uses the same AVFoundation stack","Never pass images or audio-only files to the video metadata path"],"tags":["video-metadata","avfoundation","invalid-input"],"backgroundTag":"invalid-media-file","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}