ffmpeg drawbox heigth from drawtext - filter

I want to create a background for my text in my video, I use this command:
ffmpeg -i in.mp4 -filter_complex "[0:v]drawtext=font='arial.ttf': text='This is text line 1':x=(w-tw)/2:y=((h-text_h)/2)-(text_h): fontsize=55: fontcolor=red,drawbox=y=(h/2):color=black#0.4:width=iw:height=40:t=max" out.mp4
but I do not know how to get the text height for the drawbox. I tried the box property for drawtext but this just have the width of the text and I want the width of the video. Is there a way to get the height of the text and use in the height property of the drawbox?
Thanks so much

Related

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

add an image as water mark for video with opacity size adjustment and opacity

I'm trying to add watermark for video but as any video editor I also want options of all opacity size and position I found for both opacity and position the below command does it but I missing with scaling the image
ffmpeg -i test.mp4 -i test1.png -filter_complex "[1]format=rgba,colorchannelmixer=aa=0.25[logo];[0][logo]overlay=50:50" -c:a copy output.mp4
Insert a scale filter after the ccm filter.
format=rgba,colorchannelmixer=aa=0.25,scale=W:H

FFMPEG vertically stack three elements, two images and a box

Using ffmpeg I want to stack three elements vertically. The the first two elements are images, while the third is a box I want to draw using the drawbox command. Is it possible to do so? What I was able to do was to stack two images vertically and draw a box on the image in the bottom, but this is not what I want.
Any help would be really appreciated
vstack + pad
You can stack with vstack and then add the box with pad:
ffmpeg -i image0.jpg -i image1.png -filter_complex "[0][1]vstack=inputs=2,pad=iw:ih+200:color=red" -frames:v 1 output.png
color filter + vstack
You can use the color filter to make a colored box, then stack with vstack:
ffmpeg -i image0.jpg -i image1.png -filter_complex "color=s=1280x360:color=blue[box];[0][1][box]vstack=inputs=3" -frames:v 1 output.jpg
Each input must have the same width. If they do not then add the scale, pad, or crop filters.
See syntax and color names for color options.

FFMPEG scaling watermark

I'm currently using a command to add a watermark + scrolling text and some extra encoding options to a video.
The watermark + scrolling text are made to fit correctly when the video is 1280px (width) but when the original video is any other size (for example 1920px) the watermark + scrolling text gets tiny so i need to scale this.
watermark size= 400x48
Current code i'm using
-i logo.png -filter_complex "[0:v][1:v] overlay=x=(main_w-overlay_w):y=(main_h-overlay_h-4)[out];[out]drawtext=fontsize=20:font=tahoma:alpha=0.5:fontcolor=white:borderw=0.8:bordercolor=black:text=THIS IS MY SCROLLING TEXT :y=line_h-4:x=w-(t-300)*w/40" -keyint_min 20 -vcodec libx264 -c:a copy -b:v 1700k -movflags +faststart
I think that this piece of code scale2ref=400*iw/1280:48*iw/1280 might do the work but i have no clue where exactly to paste this in. I keep on getting errors.
The correct syntax is,
"[1:v][0:v]scale2ref=400*iw/1280:48*iw/1280[wm][vid];[vid][wm]overlay=x=(main_w-overlay_w):y=(main_h-overlay_h-4),drawtext=fontsize=20:font=tahoma:alpha=0.5:fontcolor=white:borderw=0.8:bordercolor=black:text=THIS IS MY SCROLLING TEXT :y=line_h-4:x=w-(t-300)*w/40"
For fontsize, if 20 is acceptable for width 1280, then use expression fontsize='20*main_w/1280'

Anyone know how to alter an FFMPEG command to output at half the size?

I have an FMPEG command to scale down a video and add a blur to the background to fill the remaining height to 1136, plus add an overlay image, but it comes out at double the size I want. I am trying to get the whole video down to a 640 width without the overlay video being cropped or sized up. I've tried switching around every number but can't seem to get it to work with a width of 640. Thank you for any help.
ffmpeg -i '/z.mp4' -i '/a.png' -filter_complex "[0:v]scale=128/81*iw:128/41*ih,boxblur=luma_radius=min(h\,w)/40:luma_power=3:chroma_radius=min(cw\,ch)/40:chroma_power=1[bg];[bg][0:v]scale=1280:720,overlay=(W-w)/2:(H-h)/2,setsar=1,crop=w=iw*81/128[bg];[bg][1:v]overlay=82.8:118.8" '/h.mp4';
Use
ffmpeg -i '/z.mp4' -i '/a.png'
-filter_complex
"[0:v]scale=-1:1136,
boxblur=lr=min(h\,w)/40:lp=3:cr=min(cw\,ch)/40:cp=1,crop=640:1136[bg];
[0:v]scale=640:-1[vid];
[bg][vid]overlay=(W-w)/2:(H-h)/2[bg];
[bg][1:v]overlay=82.8:118.8,setsar=1" '/h.mp4'

Resources