Reputation: 582
Does anyone know how to rotate an image to its start point (top-left corner) instead of the center point (default) with the FFmpeg -vf rotate?
In this example I try to rotate a red squared image (test_sq.png) 30 degrees from its start point on in.png placed at coord 423:259 resulting in out.png.
This is my command:
ffmpeg -y -i in.png -pix_fmt bgra -strict experimental -vf movie=test_sq.png scale=279:279 rotate=30*PI/180:c=none:oh=ow [sticker]; [in][sticker] overlay=423:259 [out] -s 1280x720 out.png
To visualize it:
As you can see it rotates from its center point and also clips the original image, not really good. Anyone have suggestions or ideas how to achieve what i need?
Upvotes: 3
Views: 4460
Reputation: 93221
Your output width and height in the rotate filter are initialized to the input W/H and not auto-calculated to show the entire image after rotation. Use this instead,
ffmpeg -y -i in.png -i test_sq.png \
-filter_complex "[1]scale=279:279,setsar=1,rotate=PI/6:c=none:ow=rotw(PI/6):oh=roth(PI/6)[s];
[0][s]overlay=423-w*sin(PI/6)/(sin(PI/6)+cos(PI/6)):259,scale=hd720[out]" \
-map "[out]"-pix_fmt bgra out.png
For a non-square image,
ffmpeg -y -i in.png -i test_sq.png \
-filter_complex "[1]scale=279:279,setsar=1,rotate=PI/6:c=none:ow=rotw(PI/6):oh=roth(PI/6)[s];
[0][s]overlay=423-ih*sin(PI/6):259,scale=hd720[out]" \
-map "[out]"-pix_fmt bgra out.png
(You'll have to manually supply the value of ih
(height of original image).
For a non-square image, with a negative rotation
ffmpeg -y -i in.png -i test_sq.png \
-filter_complex "[1]scale=279:279,setsar=1,rotate=-PI/6:c=none:ow=rotw(-PI/6):oh=roth(-PI/6)[s];
[0][s]overlay=423:259-iw*sin(PI/6),scale=hd720[out]" \
-map "[out]"-pix_fmt bgra out.png
(You'll have to manually supply the value of iw
(width of original image).
For images without in-built alpha, insert format=bgra
before the rotate
filter.
Upvotes: 7