Skip to content

Fix distorted people in iPhone videos with rotation metadata #36

@hugleecool

Description

@hugleecool

Issue
When processing iPhone videos with rotation metadata (especially rotation=-90), people appear horizontally compressed in the output frames. This affects primarily videos recorded with iPhone's front camera in portrait mode.
Root Cause
The current implementation ignores rotation metadata in video files. iPhone videos are stored in landscape format (e.g., 1280×720) with rotation=-90 metadata. While media players automatically apply this rotation, the current code doesn't account for it.
To verify, check any iPhone portrait video metadata:

Image

Solution
Modified video2frames function in preprocess_video.py to:
Detect rotation metadata using ffprobe
For rotation=-90 videos, let ffmpeg handle rotation automatically
Calculate output dimensions correctly based on rotation

Key Changes

# Check for rotation metadata
cmd = f"ffprobe -v error -select_streams v:0 -show_entries stream=side_data_list -of json {video_path}"
result = subprocess.run(cmd, shell=True, capture_output=True, text=True)
info = json.loads(result.stdout)

# For rotation=-90 (iPhone portrait videos)
if rotation == -90:
    # Let ffmpeg handle rotation automatically
    w = H // n_downsample  # Use H as width since ffmpeg will auto-rotate
    h = W // n_downsample  # Use W as height

This ensures proper aspect ratio is maintained for all videos with rotation metadata, especially from mobile devices.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions