forked from afrum/my_ffmpeg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
perspective
59 lines (38 loc) · 3.68 KB
/
perspective
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# changing the perspective of a video https://youtu.be/H0-4OK9Oszc
# (Stretching or squashing a video based on a quadrilateral shape you define to give the appearance of perspective)
# if you imagine plotting 4 sets of x,y coordinates on a video and drawing lines from one corner to the other to make a quadrilateral shape
# and then you stretch the area of this quadrilateral shape to fit the shape of the original video that is what this command does.
ffmpeg -i input.MOV -vf "perspective=0:0:W:400:0:H:W:H-400" perspective0.MOV
# this first command selects a quadralateral shape the first 2 coordinates x0 and y0 which is shown as 0:0
# 0 for x0 coordinate means that the upper left corner moves to the right 0 pixels (it doesn't move that point)
# 0 for y0 coordinate means that the upper left corner moves down 0 pixels (it also doesn't move)
# W:400 represents the top righ corner coordinates x1:y1
# W for x1 coordinate means the coordinate for the top right corner is the same number of pixels accross as the width of the video
# 400 for y1 coordinate means the coordinate for the top right corner is moved down 400 pixels
# 0:H are the coordinates for the bottom left corner x2:y2 (H represents height in pixels of the video)
# W:H-400 are the coordinates for the bottom right corner x3:y3
# If you want the original image squashed to fit into the quadrilateral shape then you add the sense=destination option
ffmpeg -i input.MOV -vf "perspective=eval=0:0:W:400:0:H:W:H-400:sense=destination" perspective1.MOV
# if you want a plain surrounding of the new perspective you need to add some type of border to the video
# either by using pad or datagrid or drawbox any other command that works for you
ffmpeg -i input.MOV -vf drawbox,perspective=200:200:W-200:200:0:H:W:H:sense=destination perspective2.MOV
# for drawbox you don't need to figure out the video's dimensions but for pad and datagrid you can use this command
# to get dimensions I found at this link https://stackoverflow.com/questions/7362130/getting-video-dimension-resolution-width-x-height-from-ffmpeg
ffprobe -v error -show_entries stream=width,height -of csv=p=0:s=x input.m4v
# now that we know the dimensions we can do the drawgrid and perspective command together
# my dimensions were 1920x1989, also notice that the thickness of the grid is 1 pixels larger than the area otherwise it doesn't work
ffmpeg -i input.MOV -vf drawgrid=1915:1075:t=6,perspective=200:200:W-200:200:0:H:W:H:sense=destination perspective2.MOV
#-----------------------------------------------------------------------------
# Making a intro similar to Star Wars text
# you can combine the rolling credits https://github.com/afrum/my_ffmpeg/blob/main/Rolling%20credits
# drawbox and perspective options
# I use drawbox twice the first drawbox makes a black background and the second one does a border
# if you take one or both of the drawbox out it will give you different effects
ffmpeg -i input.MOV -vf "drawbox=t=fill,drawtext=textfile=prologue.txt:x=20:y=h-80*t:fontsize=50:fontcolor=yellow,drawbox,perspective=W/4:H/8:W-(W/4):H/8:0:H:W:H:sense=destination" prologue.MOV
#----------------------------------------------------------------------------
# Boomer recording the TV effect
# this is a quick effect of someone recording their TV, you can probably improve on this.
# this combines 4 options drawbox, drawgrid, perspective and boxblur.
# drawbox gives the black backgound, drawgrid puts the lines on the TV, perspective gives impression that the cell phone recorder is not facing straigh on,
# boxblur makes the gridlines less sharp.
ffmpeg -i input.MOV -vf "drawbox=t=20,drawgrid=h=10,perspective=0:0:W-(W/20):H/20:0:H:W-(W/20):H-(H/20):sense=destination,boxblur=3:1" boomertv.MOV