-
Notifications
You must be signed in to change notification settings - Fork 185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improvement to the Perspective filter #1145
Comments
Thanks, agreed that adding av.sense property is useful. With 'sense=destination' it really only works as user would expect with the crop filter added, so I made the previous 'sense=source' default as that looks more 'non-buggy'. The workaround of using crop filter prior to adding is such vital piece of information that I'll add it to docs somehow. I pushed the change in into master. |
You are fast to close :-) so not sure that you will read that. I was thinking that it could be a good idea to create a new filter instead of adding a sense argument. The old filter one with sense=source could be renamed to "Perspective correct" while the new one with sense=destination could be "Perspective Add". Also, there are no practical reasons to limit the point to the screen dimension especially when using sense=destination. I made multiple versions with different input and output ranges. The 5th is the one I like the best. It is relative to the corner so setting all points to (0,0) will reset the transformation.
The values SCREEN33_XMIN ... SCREEN33_XMAX are defined a follow in propertyparse.py
|
Ok, I'll reopen. Maybe do pull request, so I'll get all proposed changes in together. I think I can copy-paste from here, but pull request leaves you as the author in git log, and this helps me remember to give attribution when writing release notes and adding you as contributor.
Ok, I get it. I did a similar trick for cairoaffineblend when I contributed it to frei0r as frei0r requires all params to be in range 0.0-1.0. User being able to place image corners outside of screen area is indeed useful new functionality, so if perspective 5 + propertyparse.py change does that let's put that in. If you prefer I do it, I can do it. |
And of course, there is still the problem of setting a proper default value for the 4 points. If I understand correctly, the issue is mostly because symbols such as |
Ok, I'll wait for more input on setting proper default values for the 4 corner points. |
I could do a pull request but since I have multiple versions with different behaviors I think that this is more about figuring out which one is best. I should probably do a proper fork so that other can try it. |
I was trying to apply a perspective effect to a video clip and I noticed that Perspective filter is currently quite limited.
After reading the MLT and ffmpeg documentations I came up with a few simple changes to make it a lot more useful.
https://www.mltframework.org/plugins/FilterAvfilter-perspective/
https://ffmpeg.org/ffmpeg-filters.html#perspective
The most important is that the 'sense' argument should be added. The default 'sense=source' is suitable to do some perspective corrections but not to apply a new perspective to a clip or image. For that , you need 'sense=destination'.
<property name="av.sense" args="editor=combobox exptype=default cbopts=Source:0,Destination:1 displayname=Sense">1</property>
With 'sense=destination', it becomes possible to move the 4 corners of a clip or image to any position.
However, there are 2 issues when using Perspective with 'sense=destination'
The first issue is that the pixels on the screen border are repeated infinitely in each direction. This is a known issue of ffmpeg perspective https://trac.ffmpeg.org/ticket/8124 but I figured out that it can be solved by applying a crop filter before the perspective filter to remove one pixel pixels on each side.
The second issue is that the 4 points (x0,y0), (x1,y1), (x2,y2), (x3,y3) are controlling the displacement of the 4 corners of the screen which is often different from the 4 corners of the image or clip (when the aspect ratio does not match exactly). The solution is to insert a Position Scale filter before the Crop and the Perspective filters to use the whole screen. This is not strictly needed but that can greatly help if you want to position the 4 points precisely.
Here is a short video showing how to use Perspective with sense=destination
https://www.youtube.com/watch?v=XYsXt3-BJvQ
The text was updated successfully, but these errors were encountered: