ffmpeg rotating source video and applying overlay images

3

I'm having some trouble with this, I've got a source video that has been recorded upside down. I need this video to be rotated and have a couple of transparent PNG files overlayed on top of it. I'm using this command:

ffmpeg -i Upside_Down.mov -r 1 -i overlays_%d.png -c:v libx264 -r 30 -pix_fmt yuv420p -filter_complex "overlay=0:0" output.mkv

The above command works perfectly but keeps my source video upside down obviously, I know rotation can be achieved by -vf vflip:hflip but that doesn't seem to work. Is there a way to achieve this goal or is the only option to flip the source video and apply the overlay in a second run i.e. first do ffmpeg -i Upside_Down.mov -vf vflip:hflip then run the code code above upon completion?

Drime

Posted 2014-01-22T16:45:16.690

Reputation: 31

Answers

3

You just need to create a filterchain consisting of your additional filters:

ffmpeg -i Upside_Down.mov -r 1 -i overlays_%d.png -c:v libx264 -c:a copy -filter_complex "[0:v][1:v]overlay,vflip,hflip,format=yuv420p[out]" -map "[out]" -map 0:a output.mkv
  • I like to explicitly label the filter input and output link labels so you know exactly what is going on instead of relying on possibly unknown defaults. [0:v] refers to the video stream(s) of the first input (Upside_Down.mov), and [1:v] refers to the video stream(s) of the second input (overlays_%d.png).

  • I added -c:a copy to stream copy the audio instead of re-encoding it, but I'm unsure if Upside_Down.mov contains audio. This is one reason why you should always include the complete ffmpeg console output from your command.

  • Since changing the pixel format can be performed via filtering I changed from -pix_fmt to the format video filter so any potential conversion can occur exactly when you want it to. I did the same with -r and the fps video filter (but I'm not sure why you potentially change the frame rate: the console output would have been useful).

  • Also see: How to flip a video 180° (vertical/upside down) with FFmpeg?

llogan

Posted 2014-01-22T16:45:16.690

Reputation: 31 929