how to mirror + add logo to video? - ffmpeg

how to mirror + add logo to video?
How to mirror video, then add logo to video using ffmpeg?

To flip a video horizontally, you can use -vf hflip (or vflip for vertical flipping).
To add a watermark of any image to a video is more complex, especially if you want to position it:
-i logo.png -filter_complex "overlay=x=(main_w-overlay_w)/2:y=(main_h-overlay_h)/2"
There are a lot of things you can do with the overlay filter, check the documentation. It gets extremely complex if you also want to scale the overlay, so make sure your logo file is the right size before that.
However, you cannot mix -vf and -filter_complex, so the flipping has to become part of the complex filter. So, for your desired result, you'd have to do this (assuming you want the logo to be at position 10/10):
ffmpeg -i input.mp4 -i logo.png -filter_complex "hflip[flipped];[flipped]overlay=x=10:y=10" out.mp4

Related

How to draw a text with perspective using ffmpeg

I need to add a text to a video using ffmpeg and it needs to be with perspective like in the image.
img
i have tried with perspective but i get perspective into the whole video not only the text.
How can i do this?
You want to add a text overlay, so your best option is to pick a perspective font and use that, with the drawtext filter.
Here's an example with the font Therp. It isn't perfect but might point you in the right direction.
ffmpeg -i input.mp4 -vf "drawtext=fontfile=./.fonts/Therp.ttf:text='Perspective': x=300: y=300:font='Therp Regular':fontsize=40:fontcolor=white:" -c:a copy -f matroska - | ffplay -autoexit -i -
Result:

Overlay image zoom out and move

I have a video with an image overlay. The picture is set nearly full screen for the first 10 seconds, and aftwerwards I need to zoom out the image to a smaller size and place it in the bottom left corner for the rest of the video.
At the moment I split the input image and overlay it twict to the video, without transitions, one for the "big" picture and one for the "small" picture and it works fine.
What I would like to make is a "zoom out and moove" effect to make it smoother from the big central picture to the small one.
This is my current complex filter:
-i "video.mp4"
-i "img.jpg"
-filter_complex "[1:v]split=2[img10][img20];[img10]scale=1469:856[img11];[img20]scale=293:171[img21];[0:v][img11]overlay=(main_w-overlay_w)/2:(main_h - overlay_h)/2:enable='between(t,0,10)',fade=out:st=9:d=1:alpha=1[vid];[vid][img21]overlay=10:(main_h-overlay_h-40):enable='gte(t,10)'"
-crf 18 -c:a copy "out.mp4"
How can I make it as a single image overlay with zoom out + move effect?
Using ffmpeg version 4.3 or newer, you can animate the scale parameter. And then animate the overlay parameter.
ffmpeg
-i "video.mp4"
-loop 1 -i "img.jpg"
-filter_complex "[1:v]scale=w='if(between(t,10,14),1469-(1469-293)*(t-10)/4,if(lt(t,10),1469,293))':h='if(between(t,10,14),856-(856-171)*(t-10)/4,if(lt(t,10),856,171))':eval=frame[img];[0:v][img]overlay=x='if(between(t,10,14),(W-w)/2-((W-w)/2-10)*(t-10)/4,if(lt(t,10),(W-w)/2,10))':y='if(between(t,10,14),(H-h)/2-((H-h)/2-(H-h-40))*(t-10)/4,if(lt(t,10),(H-h)/2,H-h-40))':shortest=1"
-crf 18 -c:a copy "out.mp4"

Adding an image in the padding area of the video instead of black color using FFMPEG

I have some videos of resolution 1280 X 720 with black padding area in both left and right side around the display area of all videos. I want to display a static image in padding area of video instead of solid black color. I am working with FFMPEG library but can't find any way to do so. Can you please help me regarding this?
Thank You!
Use the cropdetect filter to determine crop parameters to remove the black. See Remove black bars using ffmpeg for an example of how to get the crop parameters.
Crop the black area and overlay the video over the image:
ffmpeg -i video.mp4 -i background.jpg -filter_complex "[0]crop=404:720:438:0[vid];[1][vid]overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2" -c:a copy output.mp4
Well, after trying some commands I made a command to do so and its working for me.
ffmpeg -loop 1 -i image.jpg -i video.mp4 -filter_complex "[1:v]scale=1280:720:force_original_aspect_ratio=decrease:-1[fg];[0:v][fg]overlay=(W-w)/2:(H-h)/2:shortest=1" output.mp4

iPhone video thumbnail upside down

Quicktime can play it right. But ffmpeg will produce an upside-down thumbnail sometimes.
ffmpeg -i input.MOV -ss 00:00:00.002 -vframes 1 -y output.png
I like to generate thumbnails of correct positions. What are some good remedies?
Thanks
Videos recorded on mobile devices will have a rotation attribute in their metadata. Quicktime uses this to know if it need to rotate the video. Use "MediaInfo" to see your media's metadata, you can download it from here; https://mediaarea.net/en/MediaInfo/Download
If the video is rotated 90' use -vf 'transpose=1', for 180' use -vf 'hflip,vflip'

ffmpeg animated gif is blotchy

I am generating an animated gif from an mp4 ... but due (I think) to color reduction (gif requires -pix_fmt rgb24) the result is somewhat ... blotchy? like running an image through an oil paint (or maybe "posterize") special effect filter. I think that the quality could be better, but I don't know what to tweak.
Not sure about this ... but ooking at the color palette of the resulting gif in an image editor it does not even appear to have attempted to create a color palette specific to this clip, but instead is attempting to us a generic palette ... which wastes a lot of pixmap space. That is, if I am interpreting this correctly.
Any tips on preserving the original video image instead of getting a "posterized" animated gif?
To get better looking gifs, you can use generated palettes. palettegen filter will generate a png palette to use with the paletteuse filter.
ffmpeg -i input.mkv -vf palettegen palette.png
ffmpeg -i input.mkv -i palette.png -lavfi paletteuse output.gif
You can try using -vf format=rgb8,format=rgb24.

Resources