I've been trying to get around this for a while now. If I use 
AV_PIX_FMT_RGBA then the file gets decoded incorrectly. It seems to me that 
the alpha is getting processed, but it's being ignored. This might be due 
to the decoder not supporting alpha, but if I can force libvpx (which sure 
does have alpha), then it can be done. But I would first need to verify if 
this is in fact what is happening.

(many hours of debugging later...)

After doing a little hack like this:

if codec_context.contents.codec_id == 140: # AV_CODEC_ID_VP8
    codec = avcodec.avcodec_find_decoder_by_name(asbytes('libvpx'))

..now the codec has a clue of the ideal pixel format: 35, which is 
AV_PIX_FMT_YUVA420P. This same trick can be found here 
<http://www.panda3d.org/reference/devel/cxx/ffmpegVideoCursor.cxx_source> 
(line 529) and here 
<https://github.com/bakape/thumbnailer/blob/ab02a222c318f3a9588732a1bb87af03c3137944/ffmpeg.c#L65>.
 
So I'm onto something. Now, the next step is to take the yuva420p and 
convert it to the RGBA that ImageData expects... so I do this starting from 
line 863 or so:

        avcodec.avpicture_fill(byref(picture_rgb), data_out, stream.
codec_context.contents.pix_fmt,
            width, height)

        self.img_convert_ctx = swscale.sws_getCachedContext(
            self.img_convert_ctx,
            width, height, stream.codec_context.contents.pix_fmt,
            width, height, AV_PIX_FMT_RGBA,
            SWS_FAST_BILINEAR, None, None, None)

...and nothing interesting happens. It just displays whatever it wants to 
display - in this case, a mostly transparent image with a tiny strip with 
some of the colors that were in my original animation.

My constants (I used the following code in IDLE to help figure out the 
numbers, instead of having to count through the enum:

for i in range(40):
    print(i, list(struct.unpack('cccc', avcodec.avcodec_pix_fmt_to_codec_tag
(i).to_bytes(4, byteorder='little'))))

and then look up the FourCC codes in this list 
<https://ffmpeg.org/pipermail/ffmpeg-devel/2012-May/125112.html>):

        AV_PIX_FMT_ARGB = 27
        AV_PIX_FMT_RGBA = 28
        AV_PIX_FMT_ABGR = 29
        AV_PIX_FMT_BGRA = 30
        AV_PIX_FMT_YUVA420P = 35

And then somewhere around line 820:

image_data = image.ImageData(width, height, 'RGBA', buffer, pitch)

RGB gets changed to RGBA. What is peculiar is that if I change this to ARGB 
and then change the sws_getCachedContext call to use AV_PIX_FMT_ARGB, the 
image data becomes corrupted, and the whole runtime crashes and burns. 
Clearly, I am doing something very, very wrong.

So, I'm not sure what is going on, but I'm just going to use placeholders 
for my images until someone who knows more about this can help me figure 
out what is going on.

-- 
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.

Reply via email to