<p>pad, rotate animation</p>
<pre><code>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 &quot;
[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
&quot; output.mp4
</code></pre>
<p><code>t/0.5</code> → where 0.5 is duration of second part of input</p>

CC BY-SA 4.0
2024-02-07T23:00:32.210Z
Thanks for your help. Can you give me a little more explanation of what your command does?
user1045680
CC BY-SA 4.0
2024-02-08T03:26:34.730Z
Split input to 3 parts: normal, rotation from 0° to 90°, rotated. Concat them.
Баяр Гончикжапов
CC BY-SA 4.0
2024-02-08T04:31:36.337Z
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`
Баяр Гончикжапов
CC BY-SA 4.0
2024-02-07T03:06:35.323Z
2024-02-07T03:06:35.323Z
Баяр Гончикжапов
<p>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.</p>
<p>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?</p>
<p>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.</p>
<p>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.</p>
<p>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?</p>

<ffmpeg><editing>
How to fix an mp4 when 1/4 of the video is in one orientation and the other 3/4 is rotated 90 degrees?
user1045680
# How to fix an mp4 when 1/4 of the video is in one orientation and the other 3/4 is rotated 90 degrees?

(Asked by: username_0 on 2024-02-06)

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?

**Tags:** ffmpeg, editing


---

## 1 answers

### Answer by username_1 on 2024-02-07. Score: 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

> **Comments:**
> **username_0**: Thanks for your help. Can you give me a little more explanation of what your command does?  
> **username_1**: Split input to 3 parts: normal, rotation from 0° to 90°, rotated. Concat them.  
> **username_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`  

---

