Search code examples
androidffmpegandroid-ffmpeg

How to add rotate animation to overlay image over another image with an audio file using FFmpeg


I want to add rotation animation to overlay image to another image and create a video with audio file. below code is creating video file but the problem is it is rotating whole video rather then rotating the overlay image.

ffmpeg -loop,1,-i,input.jpeg,-i,overlay.png,-filter_complex,[1]scale=400:400[b];[0:v][b] overlay=(W-w)/2:(H-h)/2, rotate=a=0.39269908169872*t/2,-ss,00:00:00,-to,00:00:15,-i,audio.mp3,-c:v,mpeg4,-b:a,3M,-c:a,aac,-b:a,192k,-s,720x720,-pix_fmt,yuv420p,-shortest,output.mp4

I also tried below code

ffmpeg -loop,1,-i,input.jpg,-i,overlay.png,-filter_complex,[1]scale=400:400[b];[0:v][b] overlay=(W-w)/2:(H-h)/2[ovrly];[ovrly]rotate=a=0.39269908169872*t/2,-ss,00:00:00,-to,00:00:15,-i,audio.mp3,-c:v,mpeg4,-b:a,3M,-c:a,aac,-b:a,192k,-s,720x720,-pix_fmt,yuv420p,-shortest,output.mp4

But both command give the same result. Please help me to resolve this issue. Thanks in advance.


Solution

  • Apply rotate filter to overlay.png:

    ffmpeg -loop 1 -i input.jpg -loop 1 -i overlay.png -i audio.mp3 -filter_complex "[1]scale=400:400,rotate=a=0.39269908169872*t/2:ow='hypot(iw,ih)':oh=ow[b];[0:v][b]overlay=(W-w)/2:(H-h)/2,scale=720:720,format=yuv420p" -ss 00:00:00 -to 00:00:15 -c:v mpeg4 -b:v 3M -c:a aac -b:a 192k -shortest output.mp4