I'm using moviepy to import some videos, but the videos that should be in portrait mode are imported in landscape. I need to check whether the rotation has been changed, and if it has, rotate it back.
Is this functionality built into moviepy? If not, how else can I check it?
I have now worked out a solution to the question.
Moviepy, for some reason, rotates portrait videos to landscape when it imports them. In order to automatically import them back, you need to find the video metadata that records its rotation, then rotate the video as needed. The way I did this is with ffprobe, which can be installed for windows using this youtube tutorial. Note that you will need to delete the ffmpeg.exe file in ffmpeg/bin, as you only need ffprobe.exe. If you don't delete ffmpeg.exe, moviepy will use that one instead of the one it is supposed to be using. This led to some strange problems on my system.
Once ffprobe is installed, you can run the following python function for each video being imported:
This calls the ffprobe command
ffprobe -loglevel error -select_streams v:0 -show_entries stream_tags=rotate -of default=nw=1:nk=1 your_file_name.mp4
, then returns the rotation metadata for that file.Then call the following function which calls the above function, and rotates the clip you pass to it. Note that the argument
clip
is a movie VideoFileClip object, and the argumentfile_path
is the complete path to the file thatclip
is (e.g.file_path
could be/usr/local/documents/mymovie.mp3
)