[Cin] Patch against interpolation bug in cinelerra/affine.C, interp.h

Georgy Salnikov sge at nmr.nioch.nsc.ru
Mon Jul 20 17:59:09 CEST 2020


Recently I accidentally found the following bug in Cinelerra-GG and created
a patch to correct it.

When trying to stabilize video with the 'Motion' plugin I got repeatedly a
constantly accumulated clockwise rotation of the video frames (when tracking
'Previous frame same block') or twitching video (when 'Tracking single frame').

After some debugging and dumping temporary frames in PPM format I found
that, for example, rotation of a frame to the angle of 0.000000 degrees
actually results in its translation one pixel to the right and one pixel
down. This was the reason for the Motion plugin to try constantly to rotate
video about 0.25 degrees each frame.

The actual location of this problem was in the Affine engine, namely in the
used interpolation macros. The wrong expressions for displacements of the
interpolated pixels lead to that, for example, that when the input and
output points should coinside (which is the case for the 0 degree rotation),
the X and Y of the pixel which are to be taken with the coefficient 1.0
become (tx-1,ty-1) instead of (tx,ty).

Perhaps the bug in Affine could influence also other features in Cinelerra,
but to observe such a subtle displacements in most of video editing
scenarios looks not so easy. On the contrary, the accumulated rotation while
motion stabilization makes it evident.

In cinelerra/interp.h I corrected only the expressions for the integer
coords and float displacements for the interpolated pixels.

The main correction in cinelerra/affine.C (look in the patch attached) is at
the lines 245-246: the processed frame block size was one pixel less both in
horizontal and vertical directions. I have found only one other similar
place in the code, namely in the 'Lens' plugin, and there the calculation of
max x and y was correct.

Additionally I'd propose to correct affine.C at the lines:
188 (perhaps an unportable method to compare a float variable with 0.0)
693 (looks like a definitely incorrect calculation of y1 for the package #0)

The rest, commented out, are for debugging output only.

This patch is against cin_5.1.20200430-src.tgz, I posted it to bugtracker as
issue 479.

Thanks for the attention
Georgy
_______________________________________________________________________________

Georgy Salnikov
NMR Group
Novosibirsk Institute of Organic Chemistry
Lavrentjeva, 9, 630090 Novosibirsk, Russia
Phone   +7-383-3307864
Email   sge at nmr.nioch.nsc.ru
_______________________________________________________________________________
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cinelerra-5.1-affineinterp.diff.gz
Type: application/octet-stream
Size: 1178 bytes
Desc: 
URL: <https://lists.cinelerra-gg.org/pipermail/cin/attachments/20200720/82c4969e/attachment.obj>


More information about the Cin mailing list