# My deinterlace filter for OBS studio



## sam686 (Nov 1, 2015)

I made my own deinterlace filter that can work with interlace video capture, and output at the optional double frame rate. It uses an existing filter system. I may have a problem with double frame rate part. I don't see an easy way to check if there is a new frame. I have to include obs-internal.h and use that struct, just to check if a previous frame have changed, which will probably break or crash on different version binaries having different variables/offsets in the same struct.

https://github.com/sam8641/filters-for-OBS-Studio

Later on, I might add more deinterlace methods.


----------



## Jim (Nov 1, 2015)

Hey there.  Unfortunately there are fundamental problems with writing deinterlacing as an effect filter.  Someone else had already originally written a deinterlacing effect filter similarly, but ran in to problems that made it unacceptable for merge that you're probably beginning to see.

First problem: async frames are not guaranteed to be consecutively sent to an effect filter.  This means that if for whatever reason a frame was not played (if OBS' framerate is lower than the source's) or the last frame repeated (if OBS' framerate is higher than the source's).  In the former case, there's no way to get the "last" frame in texture form.  In the latter case, you could write ways to detect it (like you did), but it's still not ideal.  The last frame must be stored in texture form and be accessible to the deinterlacer at all times, whether or not that last frame was actually able to be played on time or not.

Second problem:  being an effect filter means that it can be ordered in the list of effect filters in a way that could break deinterlacing.  For example, a user could unintentionally apply a crop before applying the deinterlacing and it could subsequently mess up the output.  Deinterlacing needs to occur before effect filters are applied.

Both of those things mean that deinterlacing unfortunately really needs to be something handled by libobs itself to get the a result guaranteed to have proper playback.  Proper deinterlacing is not trivial, hence why it's been delayed quite a bit.

I do plan on personally handling this very soon just to simply get it out of the way, but I wanted to get API and plugin issues out of the way first before doing so.  Having to wait on it sucks, but I'd rather it have it done right rather than be done on a specific schedule.

And yea, it'd be better to write API functions exposing what you want to do rather than include obs-internal.h directly.

Anyway, just wanted to explain why it's taken so long to add it.


----------



## sam686 (Nov 1, 2015)

One feature request i have is to have "isThisNewFrame", or to skip filter rendering if the previous filter or source didn't render a new frame.

I also want an ability to specify how many previous frames needed for current filter, with obs-studio filling in both previous frames from source/previous filter, even if there are frame skips.

With both the above, then how about adding a deinterlace plugin system that is nearly the same as the existing filter system, perhaps the same with only a "Deinterlace_Flag" option. OBS-Studio can then handle it as listing, and applying these deinterlace plugin as a first and only one deinterlace plugin per source.

I have an idea of also making a de-noise or similar filters that may also depend on previous frames and/or checking if it is a new frame.

There is an additional problem on how to deinterlace YV12/NV12/half vertical color resolution in which i think original OBS didn't deinterlace these colors correctly, the plugin system might need a way to input raw frames.


----------



## sam686 (Nov 2, 2015)

I made some changes to my plugin to avoid obs-internal.h, and to avoid having me to handle the first, frame rate problems as you said.

The second problem is a need to flag as a deinterlace plugin instead of a regular filter plugin.

This will require correctly adding in some missing API functions. Right now, my newest changes will need the following.
struct obs_source_info:   int number_of_video_frames_needed;

// for double frame rate, which field to render
EXPORT bool obs_source_get_source_interlace_fields(obs_source_t *source);

// This function is to allow getting multiple previous frames
EXPORT gs_texture_t *obs_source_get_texture(obs_source_t *source, unsigned int i);


----------



## Jim (Nov 2, 2015)

https://github.com/jp9000/obs-studio/tree/deinterlace - here's the last instance of our deinterlace plugin.  Has those functions you were referring to.

I may not end up making it part of the back-end and just keep it as a plugin.  I'm not entirely sure yet.  Honestly the only thing it needs is a reliable way to get the "last" frame.


----------



## Jim (Nov 2, 2015)

Also feel free to come by our chat, #obs-dev on quakenet.  At some point I'll add something to get the last frame that should make life a lot easier.


----------



## Anonanon (Nov 4, 2015)

I've waited through many versions and months for deinterlacing, but I didn't want to nag the devs any more.

Are you willing to compile and release some sort of test beta for those who wish to use it now?


----------

