Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How do I make a video animation with transparent background?

1,027 views
Skip to first unread message

Martin Schöön

unread,
Aug 9, 2016, 8:44:30 AM8/9/16
to
Here is what I want to do: I want to create an animated graph and
store it as a video file, mp4 say. This file will then be used as
an overlay on another video.

Using this example:
http://matplotlib.org/examples/animation/moviewriter.html
and this tutorial:
https://www.youtube.com/watch?v=h0F5X4b7jug
I have covered a lot of ground.

What I have failed to achieve is a graph with a transparent
background. None of the leads I have found searching the Internet
have helped me. (I may have found the needed information without
realising it...)

Any help is appreciated.

Another thing I would like to do is to present numerical data
in the video or as a separate video -- think LCD display reading
out numbers up-dated every second. Once again preferably on a
transparent background. Here I have covered no ground :-(

TIA,

/Martin

Lawrence D’Oliveiro

unread,
Aug 9, 2016, 9:50:54 PM8/9/16
to
On Wednesday, August 10, 2016 at 12:44:30 AM UTC+12, Martin Schöön wrote:

> What I have failed to achieve is a graph with a transparent
> background.

While it is possible to render image frames with alpha transparency channels, as far as I know none of the motion-video image formats supports transparency. They all assume that the image fills the entire frame and completely covers anything behind.

You could invent your own player which draws the frames one after another itself. Note that the JPEG image format doesn’t support transparency; you would have to use a bulkier format like PNG.

Another option would be to have an additional video track where the image is interpreted purely as transparency masking information for the “proper” video track. You would still need to write your own player to handle this.

Chris Angelico

unread,
Aug 9, 2016, 10:04:39 PM8/9/16
to
On Wed, Aug 10, 2016 at 11:50 AM, Lawrence D’Oliveiro
<lawren...@gmail.com> wrote:
> On Wednesday, August 10, 2016 at 12:44:30 AM UTC+12, Martin Schöön wrote:
>
>> What I have failed to achieve is a graph with a transparent
>> background.
>
> While it is possible to render image frames with alpha transparency channels, as far as I know none of the motion-video image formats supports transparency. They all assume that the image fills the entire frame and completely covers anything behind.
>

Animated GIFs support transparency. Are you happy with the framerates
you can get in a simple GIF?

But this isn't really a Python question.

ChrisA

Lawrence D’Oliveiro

unread,
Aug 9, 2016, 10:49:22 PM8/9/16
to
On Wednesday, August 10, 2016 at 2:04:39 PM UTC+12, Chris Angelico wrote:

> Animated GIFs support transparency.

But they don’t do full colour.

Steven D'Aprano

unread,
Aug 10, 2016, 12:58:05 AM8/10/16
to
Define "full colour".

GIFs don't directly support 16-bit or 32-bit colours in a single frame,
but they can support more than 256 colours:

http://webmasters.stackexchange.com/questions/304/can-i-have-an-animated-gif-with-more-than-256-colours-per-frame


including what looks to the naked eye (or at least *my* naked eye)
effectively like 32-bit colour.



--
Steve

Dale Marvin

unread,
Aug 10, 2016, 1:48:39 AM8/10/16
to
Another option in the Python world is Vapoursynth:
<https://github.com/vapoursynth/vapoursynth>
<http://www.vapoursynth.com/doc/index.html>

I runs with Cython and generally pipes to something like ffmpeg which
creates the final video file so it may be a more complex than you want
but it is capable of the processing you are asking for and in a Python
language syntax.

Dale

Christian Gollwitzer

unread,
Aug 10, 2016, 3:05:28 AM8/10/16
to
Am 09.08.16 um 14:44 schrieb Martin Schöön:
> Using this example:
> http://matplotlib.org/examples/animation/moviewriter.html
> and this tutorial:
> https://www.youtube.com/watch?v=h0F5X4b7jug
> I have covered a lot of ground.
>
> What I have failed to achieve is a graph with a transparent
> background. None of the leads I have found searching the Internet
> have helped me. (I may have found the needed information without
> realising it...)
>
> Any help is appreciated.


Here is a simple idea: Draw the background with a colour, that is not
used in the graphs, like bright blue or green. Any decent video editing
software should support colour keying, i.e. masking the green parts out,
becuase this is used in film production (green screening)

Christian

Martin Schöön

unread,
Aug 10, 2016, 5:34:33 PM8/10/16
to
Thanks for all the input so far and not only Christian but all of you.

Yes, after posting I did some more research and started to realise
that I may have barked up the wrong tree when assuming my use of
Matplotlib needed to be improved to get the intended result.

Next on my TODO list is to look into the color composition idea. I
have already looked this tutorial:
https://youtu.be/sZzmksnzrX0

What I would like to end up with is something like this:
https://youtu.be/aHEyRoDmDWk
(graph in lower right corner and 'speedometer' in lower left corner)

/Martin

Lawrence D’Oliveiro

unread,
Aug 10, 2016, 6:33:12 PM8/10/16
to
On Thursday, August 11, 2016 at 9:34:33 AM UTC+12, Martin Schöön wrote:
> Next on my TODO list is to look into the color composition idea. I
> have already looked this tutorial:
> https://youtu.be/sZzmksnzrX0

If the images you generate have an alpha channel, Blender can composite them directly, without needing colour-keying.

Martin Schöön

unread,
Aug 14, 2016, 7:12:47 AM8/14/16
to
Colour-keying works in Blender -- I only need to tweak all those parameters
a bit more to get a satisfying end result.

Case closed and it was not a Python/Matplotlib issue.

I still need the animated numerical thing but drop it here. I will be
back with a separate thread/subject for that.

Again, thanks for the input.

/Martin
0 new messages