I like to capture videos of scenery while I am driving. I do that with the help of my phone mounted on a car cell phone holder. The phone keeps recording and later I edit out the boring parts. Now, this works very well when the phone is already mounted in the horizontal position when the recording starts and as well when it ends. However, if for any reason I pick up the phone anytime during recording the video gets saved in a vertical format. So I have to rotate those videos a lot. They can also be rotated in a video editing software like Kdenlive by applying the "Rotate" effect. However, then the video gets chopped off from the sides. I find it easier to rotate the videos before importing them to the video editing software. Since a lot of videos might end up being vertical when they should be horizontal I have to rotate a lot of videos. So I wrote a batch script to rotate a bunch of videos at once. The script runs on every mp4 file in the directory. The script needs to be edited to run on other video types in the videos are in other formats. Since the script runs on all video files it is best to segregate all the videos files that need to be edited in a separate folder and copy the script to that folder. Running the script in the folder which contains all video files might have the undesirable effect of rotating the files which do not need to be rotated.
The script is very simple. It is a for loop wrapped around a ffmpeg command.
The script is very simple. It is a for loop wrapped around a ffmpeg command.
for i in `ls -1 *.mp4`; do echo $i "======================================================================" j="rotated-"$i ffmpeg -i $i -vf "transpose=2" $j done
transpose takes the following values
0 = 90 degrees CounterCLockwise and Vertical Flip (default)
1 = 90 degrees Clockwise
2 = 90 degrees CounterClockwise
3 = 90 degrees Clockwise and Vertical Flip
Comments