{"slug": "check-ai-generated-video-files-before-editing-with-ffprobe-and-python", "title": "Check AI-Generated Video Files Before Editing with FFprobe and Python", "summary": "A tutorial published by ZMS outlines a local inspection step that uses FFprobe and Python to read a downloaded AI-generated video file's metadata and compare it against an explicit delivery policy before editing. The script, saved as inspect_video.py, checks for exactly one video stream excluding attached cover images, stored dimensions of 1920 by 1080, a container-reported duration between 4.8 and 5.2 seconds, and no audio streams, using only Python standard-library modules and requiring Python 3.10 or later. The tutorial cites the Kling 4.0 AI Video Generator on ZMS, which lists output settings of 3–30 seconds and 720p or 1080p, and notes the method also applies to footage from other generators, screen recorders, and cameras.", "body_md": "A video-generation task finishes successfully. The preview plays, and the downloaded file has the expected name.\n\nThat does not tell an editor everything they need to know.\n\nThe file may have different dimensions from the editing sequence, an unexpected audio track, or a duration that needs checking before delivery. Discovering these details after building an edit creates avoidable work.\n\nThis tutorial introduces a small local inspection step using FFprobe and Python. It reads the downloaded file, summarizes selected metadata, and compares it with an explicit delivery policy.\n\nIt does not evaluate visual quality or call a generation API.\n\n## 1. Keep requested settings separate from file properties\n\nWhen documenting a generation task, distinguish between:\n\n- Requested settings: the duration, resolution, and framing selected before generation.\n- File properties: what the downloaded asset reports.\n- Delivery requirements: what the editing or publishing workflow accepts.\n\nFor example, the [Kling 4.0 AI Video Generator](https://zms.com/kling/kling-4-0) on ZMS provides text, reference, and keyframe workflows, with listed output settings of 3–30 seconds and 720p or 1080p.\n\nThose settings describe the generation request. The downloaded file should still be inspected before it enters an editing workflow.\n\nThis inspection method also applies to footage from other generators, screen recorders, and cameras.\n\n## 2. Install the prerequisites\n\nYou need:\n\n- Python 3.10 or later.\n- FFprobe, available through an FFmpeg installation.\n- A downloaded video file.\n\nConfirm FFprobe is available:\n\n```\nffprobe -version\n```\n\nIf the command is not found, install an FFmpeg distribution appropriate for your operating system and ensure its executable directory is on your PATH.\n\nThe Python example uses only standard-library modules.\n\nKeep the original video unchanged. Inspection should not require re-encoding it.\n\n## 3. Inspect a file manually first\n\nRun:\n\n```\nffprobe -v error -show_format -show_streams -of json \"clip.mp4\"\n```\n\nThis produces JSON containing container and stream information.\n\nFields worth examining include:\n\n- `codec_type` : whether a stream contains video, audio, or another type.\n- `codec_name` : the reported codec.\n- `width` and`height` : stored video dimensions.\n- `avg_frame_rate` : the reported average frame-rate value.\n- `sample_aspect_ratio` : relevant when interpreting display proportions.\n- `duration` : a reported duration, when available.\n\nDo not assume every field exists for every file.\n\nAlso distinguish stored dimensions from displayed orientation. Rotation metadata and non-square pixels can affect how a player presents the image.\n\n## 4. Add a small policy checker\n\nThe following example assumes a particular editing workflow expects:\n\n- Exactly one video stream, excluding attached cover images.\n- Stored dimensions of 1920 by 1080.\n- A container-reported duration between 4.8 and 5.2 seconds.\n- No audio streams.\n\nThese are example delivery requirements. They are not universal requirements for generated video.\n\nSave the script as `inspect_video.py`:\n\n``` python\nimport argparse\nimport json\nimport math\nimport subprocess\nimport sys\nfrom pathlib import Path\n\ndef inspect(path):\n    completed = subprocess.run(\n        [\n            \"ffprobe\",\n            \"-v\", \"error\",\n            \"-show_format\",\n            \"-show_streams\",\n            \"-of\", \"json\",\n            str(path.resolve()),\n        ],\n        capture_output=True,\n        text=True,\n        check=True,\n        timeout=30,\n    )\n    return json.loads(completed.stdout)\n\ndef evaluate(data):\n    streams = data.get(\"streams\", [])\n\n    videos = [\n        stream for stream in streams\n        if stream.get(\"codec_type\") == \"video\"\n        and not stream.get(\"disposition\", {}).get(\n            \"attached_pic\", 0\n        )\n    ]\n    audio = [\n        stream for stream in streams\n        if stream.get(\"codec_type\") == \"audio\"\n    ]\n\n    problems = []\n    video = videos[0] if len(videos) == 1 else {}\n\n    if len(videos) != 1:\n        problems.append(\"Expected exactly one video stream\")\n\n    width = video.get(\"width\")\n    height = video.get(\"height\")\n\n    if video and (width, height) != (1920, 1080):\n        problems.append(\"Stored dimensions are not 1920x1080\")\n\n    raw_duration = data.get(\"format\", {}).get(\"duration\")\n    duration = None\n\n    try:\n        value = float(raw_duration)\n        if math.isfinite(value) and value > 0:\n            duration = value\n    except (TypeError, ValueError):\n        pass\n\n    if duration is None:\n        problems.append(\"Container duration is unavailable\")\n    elif not 4.8 <= duration <= 5.2:\n        problems.append(\"Duration is outside 4.8-5.2 seconds\")\n\n    if audio:\n        problems.append(\"Audio exists; this policy expects none\")\n\n    summary = {\n        \"video_streams\": len(videos),\n        \"stored_width\": width,\n        \"stored_height\": height,\n        \"codec\": video.get(\"codec_name\"),\n        \"avg_frame_rate\": video.get(\"avg_frame_rate\"),\n        \"sample_aspect_ratio\": video.get(\"sample_aspect_ratio\"),\n        \"container_duration_seconds\": duration,\n        \"audio_streams\": len(audio),\n        \"policy_passed\": not problems,\n        \"problems\": problems,\n    }\n\n    return summary\n\ndef main():\n    parser = argparse.ArgumentParser()\n    parser.add_argument(\"file\", type=Path)\n    args = parser.parse_args()\n\n    if not args.file.is_file():\n        parser.error(\"Provide an existing local video file\")\n\n    try:\n        summary = evaluate(inspect(args.file))\n    except (\n        OSError,\n        ValueError,\n        subprocess.SubprocessError,\n    ) as error:\n        print(f\"Inspection failed: {error}\", file=sys.stderr)\n        return 2\n\n    print(json.dumps(summary, indent=2))\n    return 0 if summary[\"policy_passed\"] else 1\n\nif __name__ == \"__main__\":\n    sys.exit(main())\n```\n\nThe subprocess receives an argument list without a shell. An absolute local path also prevents a filename beginning with a dash from being interpreted as an option.\n\n## 5. Run the inspection\n\nUse:\n\n```\npython inspect_video.py \"clip.mp4\"\n```\n\nAn illustrative result could look like this:\n\n```\n{\n  \"video_streams\": 1,\n  \"stored_width\": 1920,\n  \"stored_height\": 1080,\n  \"codec\": \"h264\",\n  \"avg_frame_rate\": \"24/1\",\n  \"sample_aspect_ratio\": \"1:1\",\n  \"container_duration_seconds\": 5.0,\n  \"audio_streams\": 0,\n  \"policy_passed\": true,\n  \"problems\": []\n}\n```\n\nThis is an example response, not a measurement from a particular generation task.\n\nThe exit codes are:\n\n- `0` : inspected properties satisfy the example policy.\n- `1` : inspection succeeded, but a policy requirement was not met.\n- `2` : inspection could not complete.\n\nA policy mismatch does not necessarily mean the video is defective. It means the file needs a decision before proceeding.\n\n## 6. Interpret mismatches before modifying the file\n\nIf the dimensions differ, first check whether the delivery requirement is correct. Do not automatically stretch the image.\n\nIf audio is present, determine whether it belongs in the final edit. An audio stream can exist even when playback sounds silent; stream presence is not a loudness measurement.\n\nIf duration is outside the chosen range, inspect the clip and its timeline. The example uses container duration, which may reflect more than the selected video stream.\n\nFrame-rate values also need care. A value such as `30000/1001` represents a rational rate. A reported average alone does not establish that every frame has a constant interval.\n\nThe checker intentionally reports the frame-rate string without treating it as a pass/fail condition.\n\n## 7. Add checks appropriate to the delivery\n\nThis script is a starting point. Depending on the target workflow, further checks may include:\n\n- Display orientation and rotation metadata.\n- Pixel format and color metadata.\n- Codec compatibility with the target editor.\n- Individual stream durations.\n- Audio channels and sample rates.\n- Frame timestamps for variable-frame-rate analysis.\n\nSuccessful metadata inspection does not prove the entire file decodes correctly. A separate decode check is needed for that.\n\nNor can metadata identify a changing product shape, incorrect lettering, misleading functionality, or poor composition. Watch the complete clip and inspect important moments manually.\n\n## 8. Keep the report with the asset\n\nStore the inspection report alongside the source file, requested settings, and review notes.\n\nFor a repeatable workflow, also record the FFprobe version and a file hash so the report can be associated with a particular file version.\n\nUse the technical check before importing footage, then perform visual review in the actual edit. This makes it easier to distinguish a file mismatch from a creative problem and choose the appropriate correction.", "url": "https://wpnews.pro/news/check-ai-generated-video-files-before-editing-with-ffprobe-and-python", "canonical_source": "https://zyvop.com/check-ai-generated-video-files-before-editing-with-ffprobe-and-python-pwosv", "published_at": "2026-11-26 05:54:24+00:00", "updated_at": "2026-11-26 06:12:46.070472+00:00", "lang": "en", "topics": ["ai-tools", "generative-ai"], "entities": ["ZMS", "Kling 4.0 AI Video Generator", "FFprobe", "FFmpeg", "Python"], "also_reported_by": [], "takeaway": "Run FFprobe with -show_format -show_streams -of json on each downloaded AI-generated clip and compare codec_type, width/height, avg_frame_rate and duration against the edit's delivery policy before building the edit, since a successful generation task does not guarantee matching dimensions, duration", "recommendation": {"advice": "Inspect every downloaded AI-generated video with FFprobe's JSON output and validate stream count, dimensions, duration and audio against your delivery policy before importing it into an edit.", "playbook": "production-ops", "playbook_url": "https://wpnews.pro/playbooks/production-ops"}, "alternates": {"html": "https://wpnews.pro/news/check-ai-generated-video-files-before-editing-with-ffprobe-and-python", "markdown": "https://wpnews.pro/news/check-ai-generated-video-files-before-editing-with-ffprobe-and-python.md", "text": "https://wpnews.pro/news/check-ai-generated-video-files-before-editing-with-ffprobe-and-python.txt", "jsonld": "https://wpnews.pro/news/check-ai-generated-video-files-before-editing-with-ffprobe-and-python.jsonld"}}