Skip to content

How do I encode a GIF? (Changing pixel format appears to not work + error when encoding GIF) #1147

@joeyballentine

Description

@joeyballentine

Overview

Encoding to GIF does not work, as I get an error about yuv420p not being supported for that format. However, PyAV seems to ignore any attempt I make to overwrite the pixel format of the stream.

Expected behavior

I should be able to save a GIF

Actual behavior

I get an error

Traceback:

[0]     for packet in writer.out_stream.encode(out_frame):
[0]   File "av\stream.pyx", line 153, in av.stream.Stream.encode
[0]   File "av\codec\context.pyx", line 482, in av.codec.context.CodecContext.encode
[0]   File "av\codec\context.pyx", line 291, in av.codec.context.CodecContext.open
[0]   File "av\error.pyx", line 336, in av.error.err_check
[0] av.error.ValueError: [Errno 22] Invalid argument; last error log: [gif] Specified pixel format yuv420p is invalid or not supported

Investigation

I tried several different ways I hoped would be able to override the pixel format, mainly setting stream.pix_fmt = "gif", assuming that would work based on the numpy example. I also tried setting the attribute elsewhere and in the stream options, to no avail.

Research

I have done the following:

Additional context

Apologies if I've gotten something wrong here. It just seems like the output format does not get overwritten by anything I enter there.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions