AviSynth / AviSynthPlus

AviSynth with improvements
http://avs-plus.net
971 stars 75 forks source link

`VideoFrame` should provide its color format #317

Closed Enyium closed 1 year ago

Enyium commented 1 year ago

A VideoFrame should bring with it the necessary data to handle it. You can already query its width (advancement- and validity-wise) as well as height. You should also be able to query the information what exactly the bytes describe, i.e., the color format.

Often, you also have access to the IClip to get the color format from. But when retrieving a VideoFrame with env->propGetFrame(), there is no defined relationship to an IClip.

Not being able to get the associated color format when getting a frame out of a frame prop is a problem for my Rust crate.

pinterf commented 1 year ago

True. Actual format is a higher level information, VideoFrame is not capable to store that info. I'm not seeing a compatible way to do that while still keeping VideoInfo pixel_type in a parallel way. You must probably stuff the format info into a frame property as well.

Enyium commented 1 year ago

Why would VideoFrame not be capable to store that info? Just add another private field and a public getter.

I'm not seeing a compatible way to do that while still keeping VideoInfo pixel_type in a parallel way.

What do you mean by compatible and parallel? Where would be the problem if VideoFrame received a copy of the associated IClip's VideoInfo's pixel_type? Could the VideoFrame's color format ever change, once instantiated? (We're not talking about VideoFrameBuffer, which is recycled.)

pinterf commented 1 year ago

Unfornately there are cases where the same VideoFrame is changing its pixel_type format. Personally, I consider this habit as an abuse, though technically possible. Within a complex filter chain replacing these with a proper frame copy is possibly not slowing down the process.

Cases which I remember of:

The other cases:

Other notices:

With these remarks, it probably will break nothing and can be kept pixel_type of VideoInfo consistent with of VideoFrame. I still have to go through a lot of plugin sources, whether they are affected or not.

Enyium commented 1 year ago

(This discussion should've been in the PR.)

I complied with every point.

CombinePlanes... there is already a MakeProperyWritable which makes a necessary copy as a side effect

CombinePlanes hat a change to be made, but I didn't find a MakeProperyWritable() call there.

env->SubFramePlanar... env->SubFrame

These functions themselves weren't the best places to change this behavior. I did it in the VideoFrame::Subframe() overloads.

I still have to go through a lot of plugin sources, whether they are affected or not.

Only for those not in the codebase, if my approach to change plugins was sufficient:

pinterf commented 1 year ago

My bad. Error in commit 1b70e45d36dbd963299834a154f8b901ad1a4e79 text. Not #317 but #337.