Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LWLibavSource: unable to return alpha frame of ARGB png image if alpha frame is requested after the main content #8

Closed
AkarinVS opened this issue Sep 8, 2021 · 0 comments
Assignees

Comments

@AkarinVS
Copy link
Owner

AkarinVS commented Sep 8, 2021

Using VS R54.

Given a png file (logo11.png) with transparency, this code fails with "lsmas: failed to output a video frame." for the alpha clip:

import vapoursynth as vs
core = vs.core
c = core.lsmas.LWLibavSource('logo11.png')

if True:
  f = c[0].get_frame(0)
  a = f.get_read_array(0)
  print(a[0,1])

f = c[1].get_frame(0) # fails here
a = f.get_read_array(0)
print(a[0,1])

However, if we flip the condition of the if statement, it works.

Also, a test sample movie with alpha (RLE RGBA)
https://user-images.githubusercontent.com/79720032/132518447-659caa63-ce2d-4120-9f76-5700cfc7fcb6.mov

@AkarinVS AkarinVS self-assigned this Sep 8, 2021
@AkarinVS AkarinVS changed the title unable to return alpha frame in certain situations LWLibavSource: unable to return alpha frame in certain situations Sep 8, 2021
@AkarinVS AkarinVS changed the title LWLibavSource: unable to return alpha frame in certain situations LWLibavSource: unable to return alpha frame of ARGB png image if alpha frame is requested after the main content Sep 8, 2021
Asd-g pushed a commit to HomeOfAviSynthPlusEvolution/L-SMASH-Works that referenced this issue Apr 6, 2022
lsmas used to relying on new_output_video_frame to call determine_colorspace_conversion
to set vs_vohp->make_frame[output_index] for output_index 1 at get_frame time.

However, the guard to determine_colorspace_conversion in new_output_video_frame is
input argument input_pix_fmt_change, which does not take output_index into account.

The end result is that, if the alpha frame is requested before the main clip frames,
then new_output_video_frame notices that input_pix_fmt_change is true, and calls
appropriate functions to set the make_frame function for the output_index 1.

However, if the main clip frame is retrieved first, then new_output_video_frame will
cal determine_colorspace_conversion for output_index 0, which sets results in the flag
vshp->frame_prop_change_flags being cleared (as update_scaler_configuration_if_needed
determined that vshp already matches av_frame's properties.

You might wonder why does the code work if the request order is reversed (alpha first
and then main)? Good question: it is because during vs_setup_video_rendering,
determine_colorspace_conversion is already called for the main clip.

To fix this convoluted mess, we make vs_setup_video_rendering also call
determine_colorspace_conversion for output_index 1 (the alpha clip) as well.

Fixes AkarinVS/L-SMASH-Works#8.

Signed-off-by: akarin <[email protected]>
(cherry picked from commit AkarinVS/L-SMASH-Works@95138e2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant