ffmpeg delogo works not good when delogo at boundary - ffmpeg

I am trying using ffmpeg delogo filter to hide the logo, but I found when the logo is appears at boundary, delogo filter seems works not good. please check following images.
I also read a bit of source, seems the algorithm need subtract 1 pixel boundary. in the second image, the delogo result is looks strange, bottom is white. I want to make it invisible, is it possible?
thanks

Try
ffmpeg -i video
-filter_complex
"[0]split[m][b];
[b]crop=iw:144:0:174,vflip[a];
[m][a]vstack,delogo=794:689:134:40:1,crop=iw:720:0:0" out.mp4
The video is split in two. The 2nd feed is cropped to the bottom 20% but ending at a height just above the logo. This is then flipped and vertically stacked with the main stream. delogo is applied making sure that the height of the logo covers the whole logo. Then the excess portion at the bottom is cropped off.
Result:

Related

ffmpeg - zoompan causing stretching

I have two images as input, both are 1600x1066. I am vertically stacking them. Then I am drawing a box and vertically stacking that box under both of the image. Inside of the box I write text, then I output a video that is 1080x1920. Everything works well, until I use zoompan to zoom in on the images, I get a weird behavior (see images included below). basically all input images including the box stretchs (shrink) vertically and no longer fit the entire height of the video which is 1920.
The command (removed some drawtext commands from it):
-filter_complex
"color=s=1600x1066:color=blue, drawtext=fontfile=font.otf: text='My Text':fontcolor=white: fontsize=30: x=50: y=50[box];
[0]scale=4000x4000,zoompan=z='min(zoom+0.0015,1.5)':x='iw/2-(iw/zoom/2)':y='ih/2-(ih/zoom/2)':d=125:s=1600x1066[z0];
[1]scale=4000x4000,zoompan=z='min(zoom+0.0015,1.5)':x='iw/2-(iw/zoom/2)':y='ih/2-(ih/zoom/2)':d=125:s=1600x1066[z1];
[z0][z1][box]vstack=inputs=3"
How do I fix this? I want to zoom in without stretching the images.
Video before using zoompan: https://i.stack.imgur.com/kTBto.jpg
Video after using zoompan: https://i.stack.imgur.com/7faNn.png
The problem was the scaling done before the zoompan ("scale=4000x4000") to remove the jiggly zoom effect. the scaling ration was not equal to the ratio of the image.
Ratio of image: 1600/1066 = 1.5
Ratio of scaling: 4000/4000 = 1
So scaling had to be changed to 6000/4000 = 1.5, which solved the problem.

perspective correction example

I have some videos taken of a display, with the camera not perfectly oriented, so that the result shows a strong trapezoidal effect.
I know that there is a perspective filter in ffmpeg https://ffmpeg.org/ffmpeg-filters.html#perspective, but I'm too dumb to understand how it works from the docs - and I cannot find a single example.
Somebody can show me how it works?
The following example extracts a trapezoidal perspective section from an input Matroska video to an output video.
An estimated coordinate had to be inserted to complete the trapezoidal pattern (out-of-frame coordinate x2=-60,y2=469).
Input video frame was 1280x720. Pixel interpolation was specified linear, however that is the default if not specified at all. Cubic interpolation bloats the output with NO apparent improvement in video quality. Output video frame size will be of the input video's frame size.
Video output was viewable but rough quality due to sampling error.
ffmpeg -hide_banner -i input.mkv -lavfi "perspective=x0=225:y0=0:x1=715:y1=385:x2=-60:y2=469:x3=615:y3=634:interpolation=linear" output.mkv
You can also make use of ffplay (or any player which lets you access ffmpeg filters, like mpv) to preview the effect, or if you want to keystone-correct a display surface.
For example, if you have your TV above your fireplace mantle and you're sitting on the floor looking up at it, this will un-distort the image to a large extent:
ffplay video.mkv -vf 'perspective=W*.1:0:W*.9:0:-W*.1:H:W*1.1:H'
The above expands the top by 20% and compresses the bottom by 20%, cropping the top and infilling the bottom with the edge pixels.
Also handy for playing back video of a building you're standing in front of with the camera pointed up around 30 degrees.

How to crop and scale correctly with FFMPEG?

I'm trying to remove the TOP AND BOTTOM black bars of a video.
Image sample from video
What i'm trying to achieve
The video itself is 1280x720 16:9, but the portion that's image information is at 4:3 since it's been captured from a VHS. I want to somehow stretch it until the top bars disappear without deforming the image. I don't care about the left and right bars.
I tried using crop and scale with no luck.
By using this code the top and bottom black bars disappeared on VLC when on normal screen but when going Full Screen the bars appeared again.
ffmpeg -i test.avi -filter:v "crop=1280:670" output_video.mp4
I thought it had something to do with the Scale of the video but honestly every scale code I tried to use deformed the image a lot.
I hope someone can help me, fairly new to FFMPEG but really enjoying it this far.
I got your image, resized it to 720p, made a 30 second video to test.
In my example I've also cropped the edges (left/right) because as #LordNeckbeard mentioned, when they hit the side of your screen, they may prevent the top/bottom of the video from reaching the top/bottom of the screen, which will again, look like black bars at the top/bottom, whether they are there or not.
This worked for me:
ffmpeg -y -hide_banner -i "test.avi" -filter:v "crop=iw-400:ih-40,scale=960:720" -pix_fmt yuv420p output_video.mp4
Quick explanation:
crop=iw-400:ih-40
Cropping 400 from the input width (iw) (2x200 left/right)
Cropping 40 from the input height (ih) (2x20 top/bottom)
You can cut a little more off if you want a 'crisper' edge.
scale=960:720
Scaling the video slightly to bring it back to your original 720p, the 960 is to keep it at a nice 4x3 ratio.
This scaling is not needed, your preference.
Let me know if it worked for you.

Overlay video with moving images FFMPEG

I have a video and few images. I know two places in the video where I want to paste these images. But they shouldn't have fixed position and size. On the contrary, images should move, change their tilt angle and scale. For example you may imagine closed book and you want to overlay its name when the book is slowly opens.
I read FFMPEG documentation but didn't found anything about this. Can FFMPEG do this? If not, which libraries or methodics can do that?
The FFMPEG overlay filter can overlay one stream atop another.
It takes an expression which is evaluated per frame to determine the position.
https://ffmpeg.org/ffmpeg-filters.html#overlay-1
You may consider creating a filter chain to do the following.
1) Create a transparent image with the title of your book.
2) Use a 3D rotate filter to convert the single image into an animated sequence
3) Use the overlay filter to apply the animated stream atop your book video.

Resize to a specific width and height using ffmpeg

I need to generate thumbnails for videos, automatically. I cannot predict the format of the video, but I need the thumbnail to be 220x120 pixels, always. Using -s 220x120 produces a weird stretch, just like -vf "scale=220:120". I'd like the stretching to be uniform, either cutting away top and bottom if the video is too high or adding black borders.
This is an example using a picture, same filter can be applied to video:
ow=220
oh=120
ffmpeg -i foo.png \
-vf "scale=max($ow\,a*$oh):max($oh\,$ow/a),crop=$ow:$oh" bar.png
Regardless of aspect ratio, this will:
scale down until width or height fits "the box"
crop down the other until it fits as well
The commas inside needs to be escaped so they aren't interpreted as filter separators.
§ Crop
§ Scale

Resources