--- title: "Check AI-Generated Video Files Before Editing with FFprobe and Python" author: "sarah wilson" published: "2026-11-26T05:54:24.034Z" updated: "2026-11-26T05:54:24.034Z" url: "https://zyvop.com/check-ai-generated-video-files-before-editing-with-ffprobe-and-python-pwosv" canonical: "https://zyvop.com/check-ai-generated-video-files-before-editing-with-ffprobe-and-python-pwosv" tags: ["Python","developer tools","FFmpeg","Video Processing"] --- # Check AI-Generated Video Files Before Editing with FFprobe and Python Inspect downloaded AI video files with FFprobe and Python. Check dimensions, duration, and audio against an explicit editing policy. ![Cover image]() A video-generation task finishes successfully. The preview plays, and the downloaded file has the expected name. That does not tell an editor everything they need to know. The 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. This 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. It does not evaluate visual quality or call a generation API. ## 1\. Keep requested settings separate from file properties When documenting a generation task, distinguish between: - Requested settings: the duration, resolution, and framing selected before generation. - File properties: what the downloaded asset reports. - Delivery requirements: what the editing or publishing workflow accepts. For example, the [Kling 4.0 AI Video Generator]() on ZMS provides text, reference, and keyframe workflows, with listed output settings of 3–30 seconds and 720p or 1080p. Those settings describe the generation request. The downloaded file should still be inspected before it enters an editing workflow. This inspection method also applies to footage from other generators, screen recorders, and cameras. ## 2\. Install the prerequisites You need: - Python 3.10 or later. - FFprobe, available through an FFmpeg installation. - A downloaded video file. Confirm FFprobe is available: ```bash ffprobe -version ``` If the command is not found, install an FFmpeg distribution appropriate for your operating system and ensure its executable directory is on your PATH. The Python example uses only standard-library modules. Keep the original video unchanged. Inspection should not require re-encoding it. ## 3\. Inspect a file manually first Run: ```bash ffprobe -v error -show_format -show_streams -of json "clip.mp4" ``` This produces JSON containing container and stream information. Fields worth examining include: - `codec_type`: whether a stream contains video, audio, or another type. - `codec_name`: the reported codec. - `width` and `height`: stored video dimensions. - `avg_frame_rate`: the reported average frame-rate value. - `sample_aspect_ratio`: relevant when interpreting display proportions. - `duration`: a reported duration, when available. Do not assume every field exists for every file. Also distinguish stored dimensions from displayed orientation. Rotation metadata and non-square pixels can affect how a player presents the image. ## 4\. Add a small policy checker The following example assumes a particular editing workflow expects: - 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. - No audio streams. These are example delivery requirements. They are not universal requirements for generated video. Save the script as `inspect_video.py`: ```python import argparse import json import math import subprocess import sys from pathlib import Path def inspect(path): completed = subprocess.run( [ "ffprobe", "-v", "error", "-show_format", "-show_streams", "-of", "json", str(path.resolve()), ], capture_output=True, text=True, check=True, timeout=30, ) return json.loads(completed.stdout) def evaluate(data): streams = data.get("streams", []) videos = [ stream for stream in streams if stream.get("codec_type") == "video" and not stream.get("disposition", {}).get( "attached_pic", 0 ) ] audio = [ stream for stream in streams if stream.get("codec_type") == "audio" ] problems = [] video = videos[0] if len(videos) == 1 else {} if len(videos) != 1: problems.append("Expected exactly one video stream") width = video.get("width") height = video.get("height") if video and (width, height) != (1920, 1080): problems.append("Stored dimensions are not 1920x1080") raw_duration = data.get("format", {}).get("duration") duration = None try: value = float(raw_duration) if math.isfinite(value) and value > 0: duration = value except (TypeError, ValueError): pass if duration is None: problems.append("Container duration is unavailable") elif not 4.8 <= duration <= 5.2: problems.append("Duration is outside 4.8-5.2 seconds") if audio: problems.append("Audio exists; this policy expects none") summary = { "video_streams": len(videos), "stored_width": width, "stored_height": height, "codec": video.get("codec_name"), "avg_frame_rate": video.get("avg_frame_rate"), "sample_aspect_ratio": video.get("sample_aspect_ratio"), "container_duration_seconds": duration, "audio_streams": len(audio), "policy_passed": not problems, "problems": problems, } return summary def main(): parser = argparse.ArgumentParser() parser.add_argument("file", type=Path) args = parser.parse_args() if not args.file.is_file(): parser.error("Provide an existing local video file") try: summary = evaluate(inspect(args.file)) except ( OSError, ValueError, subprocess.SubprocessError, ) as error: print(f"Inspection failed: {error}", file=sys.stderr) return 2 print(json.dumps(summary, indent=2)) return 0 if summary["policy_passed"] else 1 if __name__ == "__main__": sys.exit(main()) ``` The 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. ## 5\. Run the inspection Use: ```bash python inspect_video.py "clip.mp4" ``` An illustrative result could look like this: ```json { "video_streams": 1, "stored_width": 1920, "stored_height": 1080, "codec": "h264", "avg_frame_rate": "24/1", "sample_aspect_ratio": "1:1", "container_duration_seconds": 5.0, "audio_streams": 0, "policy_passed": true, "problems": [] } ``` This is an example response, not a measurement from a particular generation task. The exit codes are: - `0`: inspected properties satisfy the example policy. - `1`: inspection succeeded, but a policy requirement was not met. - `2`: inspection could not complete. A policy mismatch does not necessarily mean the video is defective. It means the file needs a decision before proceeding. ## 6\. Interpret mismatches before modifying the file If the dimensions differ, first check whether the delivery requirement is correct. Do not automatically stretch the image. If 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. If 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. Frame-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. The checker intentionally reports the frame-rate string without treating it as a pass/fail condition. ## 7\. Add checks appropriate to the delivery This script is a starting point. Depending on the target workflow, further checks may include: - Display orientation and rotation metadata. - Pixel format and color metadata. - Codec compatibility with the target editor. - Individual stream durations. - Audio channels and sample rates. - Frame timestamps for variable-frame-rate analysis. Successful metadata inspection does not prove the entire file decodes correctly. A separate decode check is needed for that. Nor can metadata identify a changing product shape, incorrect lettering, misleading functionality, or poor composition. Watch the complete clip and inspect important moments manually. ## 8\. Keep the report with the asset Store the inspection report alongside the source file, requested settings, and review notes. For a repeatable workflow, also record the FFprobe version and a file hash so the report can be associated with a particular file version. Use 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. ## References - [FFprobe documentation]() - [FFmpeg downloads]() - [Python subprocess documentation]()