A file can pass decode and match the requested aspect ratio while the image itself gets hard to read. Here is a quick local check for 16:9, 1:1 and 9:16 files rendered from the same edit. It decodes one grayscale frame at 0.5 seconds and reports how much of the frame height is occupied by rows containing picture.
Run FFmpeg and Python 3 locally. Prepare three exports from the same timeline, with fit and padding applied as needed. Use the same shot and start time in each file. Then run python check-picture-height.py wide.mp4 square.mp4 vertical.mp4. The script reads one grayscale image from FFmpeg. A row counts as bright when at least 5% of its pixels have a grayscale value above 24. The span runs from the first qualifying row to the last, inclusive.
In our check, two excerpts from the same public interview went through one saved edit plan. Each file was 14 seconds, and both audio and video decoded throughout. The sample output at 0.5 seconds was:
wide.mp4: 1280x720, 720/720 rows, 100.0%
square.mp4: 720x720, 406/720 rows, 56.4%
vertical.mp4: 720x1280, 406/1280 rows, 31.7%
The square and vertical exports contained the same 406-row picture band. The larger vertical canvas put more space around it. Test a frame with small text or a second speaker's reaction, then inspect the files on a phone. Dark scenes, fades, edge graphics and captions can change the measurement. Use it as a cue for a manual check and inspect additional timecodes for a complete review.
Save the script
"""Compare the visible picture height at the same time in several exports.
Requires Python 3 and FFmpeg. No input files are modified or uploaded.
Example: python check-picture-height.py wide.mp4 square.mp4 vertical.mp4
"""
import argparse
import math
import subprocess
from io import BytesIO
from pathlib import Path
def decode_frame(ffmpeg, video, seconds):
command = [
ffmpeg, "-nostdin", "-v", "error", "-ss", str(seconds), "-i", str(video),
"-map", "0:v:0", "-frames:v", "1", "-c:v", "pgm", "-f", "image2pipe", "pipe:1",
]
data = subprocess.run(command, capture_output=True, check=True).stdout
frame = BytesIO(data)
if frame.readline().strip() != b"P5":
raise ValueError(f"Could not decode a grayscale image from {video.name}")
width, height = map(int, frame.readline().split())
if frame.readline().strip() != b"255":
raise ValueError("Expected an 8-bit grayscale image")
pixels = frame.read()
if len(pixels) != width * height:
raise ValueError("Decoded frame is incomplete")
return width, height, pixels
def bright_row_span(width, height, pixels):
# Ignore isolated bright pixels in the padding. Very dark imagery can still fool the check.
bright_lookup = bytes(value > 24 for value in range(256))
min_bright_pixels = math.ceil(width * 0.05)
bright_rows = []
for row in range(height):
start = row * width
if pixels[start:start + width].translate(bright_lookup).count(1) >= min_bright_pixels:
bright_rows.append(row)
if not bright_rows:
return 0
return bright_rows[-1] - bright_rows[0] + 1
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("video", nargs="+", type=Path)
parser.add_argument("--seconds", type=float, default=0.5)
parser.add_argument("--ffmpeg", default="ffmpeg")
args = parser.parse_args()
if not math.isfinite(args.seconds) or args.seconds < 0:
parser.error("--seconds must be a finite, nonnegative value")
for video in args.video:
try:
width, height, pixels = decode_frame(args.ffmpeg, video, args.seconds)
rows = bright_row_span(width, height, pixels)
except (OSError, subprocess.CalledProcessError, ValueError) as error:
parser.exit(1, f"{video}: {error}\n")
print(f"{video}: {width}x{height}, {rows}/{height} rows, {rows / height:.1%}")
if __name__ == "__main__":
main()
Footage by DelwarHossain and Rocky, excerpted, resized and padded under CC BY 4.0. Original footage and attribution ยท License
AI-assisted drafting. The command and results were checked against the three local exports.
Top comments (0)