Deinterlacing proposal

Mikhail Ramendik <[email protected]> Thu, 29 Sep 2005 06:07:50 +0400
Newsgroups gmane.comp.video.ogle.devel
Message-ID <[email protected]>
> Yes, ugly deinterlacing, Xv-dependent and dependent on the gfxcard
> being able to handle xvimages with a width up to 1440 :)
> But it's better than nothing.

It's not only better than nothing. It's probably the fastest mode possible, as 
there is no extra load on the CPU for deinterlacing. So I think this should 
be kept as "Fast deinterlacing".

Now, I have spent some time thinking, and I have an idea for a really strong 
deinterlacer. It will use code from several Transcode plugins, and will 
hopefully produce the best quality possible for all sorts of incoming 
material (interlaced, telecined, non-interlaced). "Best for all cases", the 
user does not have to set up a plugin chain differently for different kinds 
of films (as in, for example, mplayer - if you want to get real good 
quality).

The downsides:

- It will introduce a fixed lag of, probably, 3 to 7 frames (exact number to 
be determined). It's desirable to delay the sound accordingly; this should be 
simple as the lag is really fixed.

- It will be really CPU-intensive. Bigtime. Perhaps it can be optimized by 
using MMX and SSE/SSE2, but I don't think I know how to optimize such code 
now.The reason: it will heavily rely on motion/interlace detection, sometimes 
done more than once per frame.

It will take some time in development, but a simple prototype can be developed 
quickly in order to debug the API (it will provide trivial deinterlacing 
too).

To get this done, I will need a "hook". Here's the entire API as planned now:

DEINTERLACE_LAG will be a hardcoded #define-d value showing the lag (in 
frames).

int deinterlace_init (int x, int y, int d_mode);    this will be the init 
procedure; x and y show the image size; d_mode is the "deinterlace mode" 
which the user will be able to define in the config fle, but in early 
versions just hardcode this to 0. Returns 0 if initialization has failed, 1 
on success.

int deinterlace_frame (yuv_image_t *frame, double framerate);   this will be 
the main routine. Call this before displaying every frame. Returns 0 if the 
frame should be dropped, 1 if it should be displayed. (Note: this can result 
in a varying frame rate, but it's OK for playback.But if the sound sync is 
too complicated for this case, then let the frame always be displayed). The 
framerate parameter is indeed needed, and should contain the current 
framerate. (Will be used to determine if the system should attempt inverse 
telecine).

int deinterlace_frame_frombuf(yuv_image_t *frame);  this takes an empty buffer 
and fills it with the next "lagging" frame, if that is available. Returns 1 
if a frame was available, 0 if none was available. This should be used to 
"clear out" the buffers when the playback comes to a stop. 

Can you implement these calls? 

If so, I can send you stub deinterlace.h and deinterlace.c files . 
Unfortunately I don't understand autotools, so I'll have to ask you to 
include them in the build process. (This can be a one-time custom version if 
you don't want the unfinished stuff in CVS; I just need to be able to compile 
it all). After that I'll be able to work on the deinterlace code.

-- 
Yours, Mikhail Ramendik