Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Take into account rotation metadata to define video size #577

Merged
merged 5 commits into from
May 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed `clip.preview()` crashing at exit when running inside Jupyter Notebook in Windows [\#1537](https://github.com/Zulko/moviepy/pull/1537)
- Fixed rotate FX not being applied to mask images [\#1399](https://github.com/Zulko/moviepy/pull/1399)
- Fixed opacity error blitting VideoClips [\#1552](https://github.com/Zulko/moviepy/pull/1552)
- Fixed rotation metadata of input not being taken into account rendering VideoClips [\#577](https://github.com/Zulko/moviepy/pull/577)


## [v2.0.0.dev2](https://github.com/zulko/moviepy/tree/v2.0.0.dev2) (2020-10-05)
Expand Down
Binary file added media/rotated-90-degrees.mp4
Binary file not shown.
7 changes: 6 additions & 1 deletion moviepy/video/io/ffmpeg_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ def __init__(
)
self.fps = infos["video_fps"]
self.size = infos["video_size"]
self.rotation = infos.get("video_rotation", 0)

# ffmpeg automatically rotates videos if rotation information is
# available, so exchange width and height
self.rotation = abs(infos.get("video_rotation", 0))
if self.rotation in [90, 270]:
self.size = [self.size[1], self.size[0]]

if target_resolution:
if None in target_resolution:
Expand Down
22 changes: 22 additions & 0 deletions tests/test_ffmpeg_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
FFmpegInfosParser,
ffmpeg_parse_infos,
)
from moviepy.video.io.VideoFileClip import VideoFileClip
from moviepy.video.VideoClip import BitmapClip

from tests.test_helper import TMP_DIR
Expand Down Expand Up @@ -299,6 +300,27 @@ def test_ffmpeg_parse_infos_metadata_with_attached_pic():
assert len(d["metadata"].keys()) == 7


def test_ffmpeg_parse_video_rotation():
d = ffmpeg_parse_infos("media/rotated-90-degrees.mp4")
assert d["video_rotation"] == 90
assert d["video_size"] == [1920, 1080]


def test_correct_video_rotation():
"""See https://github.com/Zulko/moviepy/pull/577"""
clip = VideoFileClip("media/rotated-90-degrees.mp4").subclip(0.2, 0.4)

corrected_rotation_filename = os.path.join(
TMP_DIR,
"correct_video_rotation.mp4",
)
clip.write_videofile(corrected_rotation_filename)

d = ffmpeg_parse_infos(corrected_rotation_filename)
assert "video_rotation" not in d
assert d["video_size"] == [1080, 1920]


def test_ffmpeg_parse_infos_multiline_metadata():
"""Check that the parser can parse multiline metadata values."""
infos = """Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/home/110_PREV_FINAL.mov':
Expand Down