Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Usage

Reply
 
Thread Tools Search this Thread Display Modes
Old 16th December 2012, 12:57   #1  |  Link
vcmohan
Registered User
 
Join Date: Jul 2003
Location: India
Posts: 890
Reformer Plugin

Reformer plugin is for conversion between rectangle and quadrilateral image areas. This is similar to my Reform plugin but uses matrix algebra and renders better even if the angle of rotation/displacement of coordinates are 90 degrees or more.
Reformer is probably is very much like David Horman's plugin quad. However Reformer works for YUY2 and YV12 formats in addition to RGB formats. Coordinates of both rectangle and quadrilateral can be specified.
__________________
mohan
my plugins are now hosted here
vcmohan is offline   Reply With Quote
Old 16th December 2012, 16:11   #2  |  Link
martin53
Registered User
 
Join Date: Mar 2007
Posts: 407
Mohan,

quad is currently used in the FSubstitute script.
The option to use YV12 is intriguing.
But FSubstitute needs at least these two properties of the transformation filter:
  1. Background
  2. Target coordinates in- or outside frame borders
Background is currently done with a mask transformation of quad which is a little smaller than the real transformed frame. The frame is then overlaid over the background with this mask.

Target coordinates in- or outside the frame borders are important because most of the time, when the content pans over the frame, the panned content must be partly overlaid inside the frame, partly outside.

(Background info: FSubstitute uses another frame to enhance the current frame. Since the other frame usually is panned/zoomed/rotated against the current one, it must be overlaid with a transformation, in order to preserve the positions of the objects in the current frame. The parts of the current frame that the other frame does not cover remain untouched. The transition between them should be smoothened)

Code:
crgb = c.ConvertToRGB32()
cmsk = BlankClip(crgb, color=$ffffff).cTransformClip(sMD, zoom, rot, quad, 2.5).Blur(1.58)
#c stays background of cO
cO = c.Freezeframe(currentframe+iDelta, currentframe+iDelta, currentframe)
	\.Overlay(crgb.cTransformClip(sMD, zoom, rot, quad, 0), mask=cmsk, opacity=1.0).ConvertToYV12()
the user function cTransformClip() is basically the quad plugin with motion information provided in the sMD string, and the mask is 2.5 pixels smaller and blurred at each side.

Do you think reformer could be used to avoid rgb conversion here?
martin53 is offline   Reply With Quote
Old 17th December 2012, 10:26   #3  |  Link
vcmohan
Registered User
 
Join Date: Jul 2003
Location: India
Posts: 890
Martin53
I have absolutely no clue as to what you are doing and how. It is way above my understanding and therefore I cannot answer yes or no. I suggest if you have time, you may kindly try with reformer and inform me of any short comings of the plugin. One parameter I can add is Q for Quality factor in range 3 to 10 to control interpolation accuracy (at the cost of additional memory requirement only). I feel may not be needed as right now it has reasonable accuracy.
__________________
mohan
my plugins are now hosted here
vcmohan is offline   Reply With Quote
Old 18th December 2012, 04:25   #4  |  Link
vcmohan
Registered User
 
Join Date: Jul 2003
Location: India
Posts: 890
Last night I further thought about your comments. Probably you were concerned about the accuracy of each pixel in case of YV12. If the original image was in YV12 or YUY2 formats already some compromise was done. Converting to RGB32 and finally back to original format will not actually improve accuracy.
I could not understand how you could arrive at 2.5 pixels on each side. How can one show in image a half pixel? .

Reformer in case lanczos interpolation was opted does a 36pt Lanczos as long as 6x6 pts are available. If not it does a bicubic as long as 4x4 pts are available. If not it does a near point or bilinear interpolation.

I do not see why a problem should be felt near frame borders.

May be my understanding is completely flawed. Will be grateful for any enlightenment.
__________________
mohan
my plugins are now hosted here
vcmohan is offline   Reply With Quote
Old 18th December 2012, 11:15   #5  |  Link
martin53
Registered User
 
Join Date: Mar 2007
Posts: 407
Mohan,
I really failed to explain adequately what I'm doing. I'll give it another try

I stitch e.g. the previous or the next frame to the current frame so they fit together as good as possible.

First, I run a motion estimation for the neighbour frame.
Then I need quad() - or reformer() - to move the neighbour frame to its location.

Now comes step three, what I was talking about:

Of course, the transformed neighbour frame now has an uncovered region within the frame borders, because it was transformed, e.g. panned to the left or right. Let's assume the region is black.
The 'stitching' should overlay the neighbour frame over the current frame, but leave the current frame visible at the 'black region'.
Also, if the stitch is a bit blurred, it is less visible.
Currently, I do it this way:
- First, I give a pure white frame to quad() with almost the real transformation coordinates. But every corner coordinate of the rectangle is shifted 2.5 pixels towards the center. Quad() allows floating point coordinates.
Quad returns a black/white rectangle, the black region now being a bit larger. I blur this a bit and this becomes the mask for the final step.
The neighbour frame is quad() transformed normally.
In the final step, i overlay the transformed neighbour frame over the current frame with Overlay(), and use the prepared mask.

Since I am not using the alpha layer of any rgb32 frame, I think all that should also work directly in YV12 - Overlay() must deal with it, or I can check it MaskTools v2 offer an alternative filter.

But it is essential to the transform plugin that it allows floating point coordinates and corners that are in- or outside of the frame borders.

Reformer does, in contrast to quad, already allow a background clip. The only problem I face with this is that I do not want to us the 'hard' edge between the background and the quadrilateral, hence all the effort.


Edit: I made a quick hack to replace the existing filters, and it works fine!
I had to use c.r2q(Blankclip(c, color_yuv=$008080) ...) to avoid an ugly greenish color with the mask.

Now the code looks like
Code:
function cR2Q(clip c, string MDepanString, mask offset) {
	:
	: make numerical corner coordinates from MDepan string and offset here
	:
	return c.r2q(blankclip(c,color_yuv=$008080), coordinates)
}

cmsk = BlankClip(c, pixel_type="YV12",color_yuv=$ff8080).cR2Q(MDepanString, 2.5).Blur(1.58)
c.mt_merge(c.cR2Q(MDepanString, 0), cmsk, luma=true)

Last edited by martin53; 18th December 2012 at 12:05. Reason: tested
martin53 is offline   Reply With Quote
Old 18th December 2012, 12:52   #6  |  Link
vcmohan
Registered User
 
Join Date: Jul 2003
Location: India
Posts: 890
Martin
I now could understand the problem. It appears you have solved it.
It is true that Reformer uses internally integer coordinates as I used parts of my Reform plugin code as starting point. I will see whether I can change it easily to process fully in floating point. But may take some time.
Can you provide me a few frames of your processing result? I am just plain curious about the whole thing you are doing.
__________________
mohan
my plugins are now hosted here
vcmohan is offline   Reply With Quote
Old 18th December 2012, 19:08   #7  |  Link
martin53
Registered User
 
Join Date: Mar 2007
Posts: 407
Mohan
please just look for my thread "bye bye blurred frames".
martin53 is offline   Reply With Quote
Old 20th December 2012, 04:03   #8  |  Link
vcmohan
Registered User
 
Join Date: Jul 2003
Location: India
Posts: 890
Martin
Thanks. I first thought that what you were doing was similar to my Expanse plugin, but now I realize it is not.
__________________
mohan
my plugins are now hosted here
vcmohan is offline   Reply With Quote
Old 21st March 2020, 20:24   #9  |  Link
LigH
German doom9/Gleitz SuMo
 
LigH's Avatar
 
Join Date: Oct 2001
Location: Germany, rural Altmark
Posts: 6,746
I tried to use the "Reformer" plugin to create a kind of "Star Wars scroller" by mapping a sliding window over a lengthy image onto a trapezoid (qr=false).

Unfortunately it seems that it doesn't support RGB32 well. The trapezoid was all opaque.
__________________

New German Gleitz board
MediaFire: x264 | x265 | VPx | AOM | Xvid
LigH is offline   Reply With Quote
Old 21st March 2020, 21:05   #10  |  Link
wonkey_monkey
Formerly davidh*****
 
wonkey_monkey's Avatar
 
Join Date: Jan 2004
Posts: 2,492
Have you tried quad, which is part of warp?
__________________
My AviSynth filters / I'm the Doctor
wonkey_monkey is offline   Reply With Quote
Old 21st March 2020, 21:23   #11  |  Link
Selur
Registered User
 
Selur's Avatar
 
Join Date: Oct 2001
Location: Germany
Posts: 7,255
@LigH: if you find a nice/easy/short solution using Avisynth or Vapoursynth let me know (share a small example script ).

I also would like to do this, last time I needed something like this I use ffmpegs drawtext:
Code:
ffplay.exe -i "f:\TestClips&Co\files\test.avi" -vf "[in]drawtext=fontfile='C\:/Windows/Fonts/arial.ttf':fontsize=40:fontcolor=yellow:x=(w-text_w)/2+20:y=h-40*t:line_spacing=80:textfile='c\:/Users/Selur/Desktop/zahlen.txt':enable='between(t,600,900)'[out]"
the 'zahlen.txt' is a simple text file:
Code:
line 1
line 2
line 3
line 4
line 5
...
drawtext: https://www.ffmpeg.org/ffmpeg-all.html#drawtext-1 <- used to display the lines
enable: https://www.ffmpeg.org/ffmpeg-all.html#Timeline-editing <- used to only use the filter from position 600s to 900s.

Cu Selur

Ps.: I know that lots of NLEs can do this, but I like solutions I can script in a command line.
PPs.: I used ffplay just for testing, same syntax works fine with ffmpeg.
__________________
Hybrid here in the forum, homepage

Last edited by Selur; 21st March 2020 at 21:25.
Selur is offline   Reply With Quote
Old 23rd March 2020, 15:28   #12  |  Link
LigH
German doom9/Gleitz SuMo
 
LigH's Avatar
 
Join Date: Oct 2001
Location: Germany, rural Altmark
Posts: 6,746
I used a workaround to map both the content and its mask on a quad with the same dimensions before using the mapped mask as alpha channel on the mapped content. To share the examples, I'll have to create a new neutral content...
__________________

New German Gleitz board
MediaFire: x264 | x265 | VPx | AOM | Xvid
LigH is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:04.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.