When making a VideoFileClip, as such video = editor.VideoFileClip(video_file), with a video_file that's portrait sized (video_file size is [1080, 1920]), Moviepy converts to landscape, video = [1920, 1080]), video.rotation = 90.
I found this workaround (below), but seems like that's something that shouldn't happen.
```python
if video.rotation == 90:
video = video.resize(video.size[::-1])
video.rotation = 0
Thanks for this! The video.rotation is a new feature, recently implemented, and I have thought it would be nice to have another parameter for VideoFileClip to do with rotation, for instance, a default_rotation parameter, which if True would rotate the video depending on the value of video.rotation.
For now, though, this is working as expected.
Also, for better readability, I'd replace video.resize(...) with video.rotate(90).
A default_rotation as described would definitely be useful! Thanks for the response @tburrows13
I'll look at getting it in soon! I'll leave this open until then.
Awesome! Thank you @tburrows13. To clarify, the problem is that video = editor.VideoFileClip(video_file) returns a portrait input as a landscape, automatically (i.e. the portrait video is stretched out to fit into a landscape frame, which distorts everything, though the video is still the right side up).
To your point above, replacing video.resize(...) with video.rotate(90) did not fix the problem for me. When I tried video.rotate(90) without resizing, the video simply turned on its side (i.e. I would have had to turn my computer around 90 degrees to view the video the right side up). The workaround above seemed to be the only way I could fix the 'stretching out' of the video, and still have the video display the right side up.
Thank you so much for looking into this! We're big fans of Moviepy here at BuzzFeed!
@angyangie Oh, I didn't realise the picture was being distorted! I hadn't looked closely at what you were doing with the resize, and assumed it was just a way to rotate it. I'll label this as a bug then. I haven't experienced this with my own portrait videos though.
Hi,
Bug, not auto-resize with good ratio when video metadata rotate is 90潞 or 270潞, portrait.
While... you can to use the param target_resolution=[420,700] that is work to ffmpeg direct, but this not relation aspect ratio if there rotation. See https://zulko.github.io/moviepy/_modules/moviepy/video/io/VideoFileClip.html#VideoFileClip
Thanks!
I have a PR that addresses this issue, #683. My solution is to detect if ffmpeg is autorotating the video and swap the dimensions automatically. I'd welcome any and all feedback.
Thanks that helped us a lot :)
It was a good solution.It worked.
I've been using this workaround in one of my projects, with one small modification:
if video.rotation in (90, 270):
video = video.resize(video.size[::-1])
video.rotation = 0
Without the modification some videos were still suffering from the stretching issue.
I was previously using the above work around but after a few days the video produced was rotated. I tried this vfx.rotate to fix the issue
from moviepy import *
def video_rotation(video):
"""
Rotate the video based on orientation
"""
rotation = video.rotation
if rotation == 90: # If video is in portrait
video = vfx.rotate(video, -90)
elif rotation == 270: # Moviepy can only cope with 90, -90, and 180 degree turns
video = vfx.rotate(video, 90) # Moviepy can only cope with 90, -90, and 180 degree turns
elif rotation == 180:
video = vfx.rotate(video, 180)
return video
Here is a minimal video that demonstrates the problem.
https://photos.app.goo.gl/v7Y58mjg1k9RL8tq8
just download the video and then try
from moviepy.editor import *
concatenate_videoclips(VideoFileClip("VID_20190803_230713.mp4")).write_videofile("bad.mp4")
Are there any updates regarding this situation ?
Hello there, things can get even more complicated. With camera held badly in hand at the beginning of video causing "wrong" metadata of rotaion. This cannot be fixed by workaround above, nor clip.rotate(90) which is pawned by another bug #1278 . This case can be fixed by setting the metadata of rotation to zero $ avconv -i bad_metadata.mp4 -vcodec copy -metadata:s:v:0 rotate=0 -acodec copy new_metadata_rot_0.mp4
@KiLLAAA thanks for the comment. If the video has the wrong metadata, then there's nothing that moviepy can do about it. You'll just have to manually rotate it. #1278 has now got a fix in #1335, so it will be fixed in v2.0.0.dev3.
This doesn't address the original issue (which #683 might be a fix for, but needs a bit of cleaning up if it is to be merged).
There is another example file with this behaviour here, from issue #682.
Most helpful comment
I've been using this workaround in one of my projects, with one small modification:
Without the modification some videos were still suffering from the stretching issue.