I want to draw diagonal lines on the video using ffmpeg.

Asked 2 years ago, Updated 2 years ago, 444 views

I would like to draw diagonal lines in the video.
Vertical and horizontal lines

-i input-vf drawerbox=10:10:1:200:color='#ff0000':8:enable='between(t,3,5)output

I was able to draw with drawbox as shown in , but I don't know how to use diagonal lines.
How can I draw a diagonal line?

Thank you for your cooperation.

ffmpeg

2022-09-30 22:00

2 Answers

According to ffmpeg draw a line from point, the if statement can be used in the geq filter to repeat the "draw a point at coordinates where X and Y coordinates match" process as quoted below.

ffmpeg-in.mp4-filter_complex 
      US>" color=red:s=490x490, geq=lum='p(X,Y))':a='if(eq(X,Y),255,0)'[c];
       [0][c] overlay=10:10:shortest=1" 
out.mp4

However, as stated in the comment in the answer above, this process is expensive because it scans the entire screen with a geq filter and draws dots.
GEAQ's "How to lighten the load" advice (quoted below) that allows you to draw lines, circles, and patterns in mathematical formulas may also be helpful.

The geq filter is heavy, so if there is no change in the image, it is better to take out only one frame with a trim filter and repeat it with a loop filter.

ffplay-flavfi-i color, geq='st(0, between(X,W/3,2*W/3)* between(Y,H/3,2*H/3));ld(0)*255:128', trim=end_frame=1, loop=-1:1:0, setspts=N/FRAME_RATE/TB


2022-09-30 22:00

An alternative is to prepare a diagonal image and synthesize it into a video.

Note:
Mix and synthesize videos and images with FFmpeg


2022-09-30 22:00

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.