1

I have an mp4 video shot on an iPhone. Part way through the video the user rotated the camera 90 degrees and kept shooting. The first 1/4 of the video is right side up, there is a small section where the camera rotates, and then the last 3/4 of the video is rotated by 90 degrees. All one video clip.

Is there a way to fix the video without using an iPhone? I don't have an iPhone, just an Ubuntu 22.04 computer. ffmpeg? VLC media player? Openshot? Do I have to use an iPhone?

There are lots of tutorials for rotating an entire video using these tools, but I can't find anything that shows how to rotate the video starting at a certain time stamp.

I could add the video to Openshot, cut the clip into three pieces, the good stuff, the frames showing the rotation, and the rotated stuff. Then rotate the rotated clip correctly, and then join the first and third clips together and throw out the frames showing the rotation in progress. There would be a rough transition from one clip to the other.

Is there any open source program that can read each frame's metadata and correct the rotation angle on each frame? Can ffmpeg do that?

1 Answer 1

1

pad, rotate animation

ffmpeg \
-ss 0.0 -to 2.5 -i input.mp4 \
-ss 2.5 -to 3.0 -i input.mp4 \
-ss 3.0 -to 5.5 -i input.mp4 \
-filter_complex "
[0:v]pad='max(iw,ih)':'max(iw,ih)':-1:-1[a];
[1:v]pad='max(iw,ih)':'max(iw,ih)':-1:-1,rotate='lerp(0,PI/2,t/0.5)'[b];
[2:v]pad='max(iw,ih)':'max(iw,ih)':-1:-1,rotate=PI/2[c];
[a][0:a][b][1:a][c][2:a]concat=n=3:v=1:a=1
" output.mp4

t/0.5 → where 0.5 is duration of second part of input

3
  • Thanks for your help. Can you give me a little more explanation of what your command does? Feb 7 at 23:00
  • Split input to 3 parts: normal, rotation from 0° to 90°, rotated. Concat them. Feb 8 at 3:26
  • 1
    or you can try this way: ffmpeg -i input.mp4 -filter_complex " [0:v]pad='max(iw,ih)':'max(iw,ih)':-1:-1, rotate='if(lt(t,2.0),0,if(between(t,2.0,2.5),lerp(0,PI/2,(t-2.0)/0.5),PI/2))' " -c:a copy output.mp4 Feb 8 at 4:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.