Answers.Body: <p>geq, overlay</p>
  <pre><code>ffmpeg -i input.mp4 -lavfi &quot;
  color=black:size=100x100,geq=r=0:g=0:b='lerp(255,127,Y/H)'[o];
  [0:v][o]overlay=100:100:shortest=1
  &quot; -y out.mp4
  </code></pre>
  <p>drawtext, geq, overlay</p>
  <pre><code>ffmpeg -i &quot;in 1.mp4&quot; -lavfi &quot;
  color=black@0:size=1280x720,
  drawtext=text='Some text'
  :box=1
  :boxborderw=30
  :boxcolor=blue
  :borderw=5
  :bordercolor=red
  :fontsize=h/4
  :fontcolor=white
  :x=(w-text_w)/2
  :y=(h-text_h)/2,
  format=rgba,geq=
  r='if(eq(r(X,Y),0)*eq(g(X,Y),0)*eq(b(X,Y),255),0,r(X,Y))'
  :g='if(eq(r(X,Y),0)*eq(g(X,Y),0)*eq(b(X,Y),255),0,g(X,Y))'
  :b='if(eq(r(X,Y),0)*eq(g(X,Y),0)*eq(b(X,Y),255),lerp(63,255,Y/H),b(X,Y))'
  :a='if(eq(r(X,Y),0)*eq(g(X,Y),0)*eq(b(X,Y),0),0,255)'[t];
  [0][t]overlay=(W-w)/2:(H-h)/2
  &quot; -c:a copy out.mp4 -y
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-04-17T07:07:14.617Z
Answers.Text: Thank you! It works!
Answers.UserDisplayName: Keisuke Toyoda
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-04-20T08:28:42.980Z
Answers.Text: Actually, I want to use the box above as a background for the text. Is it possible to resize the box to fit the width of the text?
Answers.UserDisplayName: Keisuke Toyoda
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-04-20T10:03:23.313Z
Answers.Text: added drawtext. not tested as well
Answers.UserDisplayName: Баяр Гончикжапов
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-04-20T10:41:40.040Z
Answers.Text: Thank you very much! You have just made it possible for me to achieve exactly what I wanted to do.
Answers.UserDisplayName: Keisuke Toyoda
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-04-16T08:54:10.733Z
Answers.LastActivityDate: 2023-04-20T10:00:31.840Z
Answers.LastEditDate: 2023-04-20T10:00:31.840Z
Answers.UserDisplayName: Баяр Гончикжапов
Body: <p>I tried to run the following code, but it didn't work.</p>
  <pre><code>ffmpeg -i input.mp4 -filter_complex [0:v]drawbox=x=100:y=100:w=100:h=100:color='r=66-ceil(48*Y/H):g=74-ceil(59*Y/H):b=199-ceil(72*Y/H)':t=fill -c:a copy output.mp4
  </code></pre>
  <p>Please teach me how to overlay a rectangular shape with a vertical gradient onto a video, with a constant duration.<br />
  I mean that I want to place an image similar to the one shown below over a video.<br />
  <a href="https://i.sstatic.net/xY1xT.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/xY1xT.png" alt="enter image description here" /></a></p>
  
Tags: <ffmpeg>
Title: How to dynamically set the color of a box using rgba in 'drawbox' in ffmpeg?
UserDisplayName: Keisuke Toyoda
ThreadText: # How to dynamically set the color of a box using rgba in 'drawbox' in ffmpeg?
  
  (Asked by: username_0 on 2023-04-15)
  
  I tried to run the following code, but it didn't work.
  
  ```
  ffmpeg -i input.mp4 -filter_complex [0:v]drawbox=x=100:y=100:w=100:h=100:color='r=66-ceil(48*Y/H):g=74-ceil(59*Y/H):b=199-ceil(72*Y/H)':t=fill -c:a copy output.mp4
  
  ```
  
  Please teach me how to overlay a rectangular shape with a vertical gradient onto a video, with a constant duration.  
  I mean that I want to place an image similar to the one shown below over a video.  
  [![enter image description here](https://i.sstatic.net/xY1xT.png)](https://i.sstatic.net/xY1xT.png)
  
  **Tags:** ffmpeg
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2023-04-16. Score: 1 | Accepted answer
  
  geq, overlay
  
  ```
  ffmpeg -i input.mp4 -lavfi "
  color=black:size=100x100,geq=r=0:g=0:b='lerp(255,127,Y/H)'[o];
  [0:v][o]overlay=100:100:shortest=1
  " -y out.mp4
  
  ```
  
  drawtext, geq, overlay
  
  ```
  ffmpeg -i "in 1.mp4" -lavfi "
  color=black@0:size=1280x720,
  drawtext=text='Some text'
  :box=1
  :boxborderw=30
  :boxcolor=blue
  :borderw=5
  :bordercolor=red
  :fontsize=h/4
  :fontcolor=white
  :x=(w-text_w)/2
  :y=(h-text_h)/2,
  format=rgba,geq=
  r='if(eq(r(X,Y),0)*eq(g(X,Y),0)*eq(b(X,Y),255),0,r(X,Y))'
  :g='if(eq(r(X,Y),0)*eq(g(X,Y),0)*eq(b(X,Y),255),0,g(X,Y))'
  :b='if(eq(r(X,Y),0)*eq(g(X,Y),0)*eq(b(X,Y),255),lerp(63,255,Y/H),b(X,Y))'
  :a='if(eq(r(X,Y),0)*eq(g(X,Y),0)*eq(b(X,Y),0),0,255)'[t];
  [0][t]overlay=(W-w)/2:(H-h)/2
  " -c:a copy out.mp4 -y
  
  ```
  
  > **Comments:**
  > **username_0**: Thank you! It works!  
  > **username_0**: Actually, I want to use the box above as a background for the text. Is it possible to resize the box to fit the width of the text?  
  > **username_1**: added drawtext. not tested as well  
  > **username_0**: Thank you very much! You have just made it possible for me to achieve exactly what I wanted to do.  
  
  ---
  
  