Quantcast

"Extracting" Alpha Channel

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

"Extracting" Alpha Channel

Dan Flett
In television graphics or vision mixing, it's often necessary to "extract"
the alpha channel from a graphics file and turn it into a separate "Key" or
"Matte" clip.

The Key video is a grayscale representation of the alpha channel - black is
fully transparent and white is fully opaque.

It is possible to do this the using "lut" filter (I use lutrgb):

-vf "[in] format=rgba, split [T1], fifo, lutrgb=r=minval:g=minval:b=minval,
[T2] overlay [out]; [T1] fifo, lutrgb=r=maxval:g=maxval:b=maxval [T2]"

This filter first converts the input video to the rgba colorspace.

It then splits the input video into 2 streams (as per the turorial in the
libavilfter docs).  The "background" stream is set to a fully black frame by
setting the r,g,b values to "minval".  The foreground stream is set to a
fully white frame by setting the r,g,b values to "maxval".  In both streams
the alpha channel is untouched.

At the end of the first stream, the "overlay" filter overlays the white
stream over the black one, using the untouched alpha channel as the mask.
The result is a grayscale representation of the alpha channel - the actual
rgb video content is thrown away.

Dan

_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: "Extracting" Alpha Channel

Stefano Sabatini
On date Thursday 2011-07-28 12:00:36 +1000, Dan Flett encoded:

> In television graphics or vision mixing, it's often necessary to "extract"
> the alpha channel from a graphics file and turn it into a separate "Key" or
> "Matte" clip.
>
> The Key video is a grayscale representation of the alpha channel - black is
> fully transparent and white is fully opaque.
>
> It is possible to do this the using "lut" filter (I use lutrgb):
>
> -vf "[in] format=rgba, split [T1], fifo, lutrgb=r=minval:g=minval:b=minval,
> [T2] overlay [out]; [T1] fifo, lutrgb=r=maxval:g=maxval:b=maxval [T2]"
>
> This filter first converts the input video to the rgba colorspace.
>
> It then splits the input video into 2 streams (as per the turorial in the
> libavilfter docs).  The "background" stream is set to a fully black frame by
> setting the r,g,b values to "minval".  The foreground stream is set to a
> fully white frame by setting the r,g,b values to "maxval".  In both streams
> the alpha channel is untouched.
>
> At the end of the first stream, the "overlay" filter overlays the white
> stream over the black one, using the untouched alpha channel as the mask.
> The result is a grayscale representation of the alpha channel - the actual
> rgb video content is thrown away.

Another interesting possibility (simpler, faster) would be to
implement a decomposer and a composer filter, for splitting RGBA
channels into separate gray video streams and re-composing them.
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: "Extracting" Alpha Channel

Phil Rhodes

> Another interesting possibility (simpler, faster) would be to
> implement a decomposer and a composer filter

Hang on. You're saying that implementing a video filter in low level code  
is simpler and faster than using an existing commandline tool?!

P
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: "Extracting" Alpha Channel

Dan Flett
In reply to this post by Stefano Sabatini
 

-----Original Message-----
From: [hidden email] [mailto:[hidden email]]
On Behalf Of Stefano Sabatini
Sent: Thursday, 28 July 2011 19:13
To: FFmpeg user questions and RTFMs
Subject: Re: [FFmpeg-user] "Extracting" Alpha Channel

On date Thursday 2011-07-28 12:00:36 +1000, Dan Flett encoded:

> In television graphics or vision mixing, it's often necessary to "extract"
> the alpha channel from a graphics file and turn it into a separate
> "Key" or "Matte" clip.
>
> The Key video is a grayscale representation of the alpha channel -
> black is fully transparent and white is fully opaque.
>
> It is possible to do this the using "lut" filter (I use lutrgb):
>
> -vf "[in] format=rgba, split [T1], fifo,
> lutrgb=r=minval:g=minval:b=minval,
> [T2] overlay [out]; [T1] fifo, lutrgb=r=maxval:g=maxval:b=maxval [T2]"
>
> This filter first converts the input video to the rgba colorspace.
>
> It then splits the input video into 2 streams (as per the turorial in
> the libavilfter docs).  The "background" stream is set to a fully
> black frame by setting the r,g,b values to "minval".  The foreground
> stream is set to a fully white frame by setting the r,g,b values to
> "maxval".  In both streams the alpha channel is untouched.
>
> At the end of the first stream, the "overlay" filter overlays the
> white stream over the black one, using the untouched alpha channel as the
mask.
> The result is a grayscale representation of the alpha channel - the
> actual rgb video content is thrown away.

Another interesting possibility (simpler, faster) would be to implement a
decomposer and a composer filter, for splitting RGBA channels into separate
gray video streams and re-composing them.

------------------------

How about being able to do something like this?

format=yuva, lutyuv=y=a:u=minval:v=minval

Basically, being able to specify that the y (luma) channel output is equal
to the a (alpha) channel of the input?

Being able to swap color channels around would be good:

format=rgb, lutrgb=r=b:g=r:b=g


_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: "Extracting" Alpha Channel

Dan Flett
In reply to this post by Phil Rhodes
 

-----Original Message-----
From: [hidden email] [mailto:[hidden email]]
On Behalf Of Phil Rhodes
Sent: Thursday, 28 July 2011 21:31
To: FFmpeg user questions and RTFMs
Subject: Re: [FFmpeg-user] "Extracting" Alpha Channel


> Another interesting possibility (simpler, faster) would be to
> implement a decomposer and a composer filter

Hang on. You're saying that implementing a video filter in low level code is
simpler and faster than using an existing commandline tool?!

P
_______________________________________________

Hehe, yeah.  I'm more of a user than a coder. :)  I like to tell people
what's possible with ffmpeg as it is.  If a coder sees an easier way, then
great!

_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Different timestamp on RTP

Wernam Wer

Hi all,
I'm using FFMPEG to enconding and send via RTP a livestream video, I use the last version of FFMPEG with this command:./ffmpeg -vcodec copy -i pipe -an -f rtp rtp://224.52.52.22:7004 -sameq -v 0 < /dev/null &But I'm having problem into the client to reproduce it, FFMPEG work fine, but when I scan the packets with Wireshark I see a big difference between the timestamp of the RTCP packets and RTP packets, the RTP packets have a bad timestamp, because if I calculate the time between two packets and then how should increase the timestamp it never give a good value (RTCP have a correct value).
I'm using ffmpeg into an ARM with Linux 2.4
To solve it I have change a this line into the code:libavformat/rtpenc.c393s->cur_timestamp = av_rescale_q(ff_ntp_time() - s->first_rtcp_ntp_time, (AVRational){1, 1000000},s1->streams[0]->time_base) + s->base_timestamp;
But I'm not sure why it's happening , any idea?
Thanks for the helpWernam

     
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: "Extracting" Alpha Channel

Phil Rhodes
In reply to this post by Dan Flett
> If a coder sees an easier way, then great!

Well, yes. Easier if you are already an experienced software engineer with  
an advanced knowledge of the internals of ffmpeg. Yes. Then. :)

Still, you can always look at - er - FFDN, the ffmpeg developer's network,  
an MSDN-style compendium of all you need to know to write new code for  
ffmpeg!

Oh no, wait...

P
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: "Extracting" Alpha Channel

Stefano Sabatini
In reply to this post by Phil Rhodes
On date Thursday 2011-07-28 12:31:16 +0100, Phil Rhodes encoded:
>
> >Another interesting possibility (simpler, faster) would be to
> >implement a decomposer and a composer filter
>
> Hang on. You're saying that implementing a video filter in low level
> code is simpler and faster than using an existing commandline tool?!

Correction: simpler and faster - once the filter is implemented, just
casting some random ideas in the case someone != me wants to try it
(which is unlikely - I have to admit).
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: "Extracting" Alpha Channel

Stefano Sabatini
In reply to this post by Dan Flett
On date Thursday 2011-07-28 21:47:59 +1000, Dan Flett encoded:
[...]

> How about being able to do something like this?
>
> format=yuva, lutyuv=y=a:u=minval:v=minval
>
> Basically, being able to specify that the y (luma) channel output is equal
> to the a (alpha) channel of the input?
>
> Being able to swap color channels around would be good:
>
> format=rgb, lutrgb=r=b:g=r:b=g

Basically this won't be anymore a lut filter (for each input value,
lookup a pre-computed value in a table) but an eval filter (for each
input value, evaluate an expression depending on the current video
state).

mp=geq allows to do something similiar, but only works with yuv
formats, and I wrote an eval filter which was never applied, maybe
I'll find the time/inspiration to work on this...
--
ffmpeg-user random tip #5
FFmpeg documentation:
http://www.ffmpeg.org/documentation.html
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: "Extracting" Alpha Channel

Dan Flett
In reply to this post by Phil Rhodes
 

-----Original Message-----
From: [hidden email] [mailto:[hidden email]]
On Behalf Of Phil Rhodes
Sent: Thursday, 28 July 2011 22:55
To: FFmpeg user questions and RTFMs
Subject: Re: [FFmpeg-user] "Extracting" Alpha Channel

> If a coder sees an easier way, then great!

Well, yes. Easier if you are already an experienced software engineer with
an advanced knowledge of the internals of ffmpeg. Yes. Then. :)

Still, you can always look at - er - FFDN, the ffmpeg developer's network,
an MSDN-style compendium of all you need to know to write new code for
ffmpeg!

Oh no, wait...

P
_______________________________________________

Don't get me wrong, I think it's cool that Stefano would see things we write
and suggest improvements to the ffmpeg code.  I would never disparage a keen
ffmpeg developer.  But yes, comparing command-line solutions to ffmpeg code
solutions is the proverbial situation concerning apples and oranges.

I've got plenty of suggested improvements to ffmpeg, as do most people on
this list I'm sure.  Most of us know the FOSS way is to not post our wish
lists and say "do this now"!  But perhaps the roundabout way of doing that
is to post command-line solutions to problems and let developers come up
with simpler, faster modifications to ffmpeg. :)

The ffmpeg docs, especially now with libavfilter, could do with a bit more
of a "cookbook" of command-line solutions - with explanations as to how they
work.  There are some good examples in the libavfilter docs but libavfilter
is still pretty new so I guess it takes time for more sophisticated,
real-world examples to appear.  Something along the lines of a wiki could
help here, allowing the greater user community to contribute.

_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: "Extracting" Alpha Channel

Gavin Kinsey
In reply to this post by Dan Flett
On Thursday 28 July 2011 12:47:59 Dan Flett wrote:

>
> How about being able to do something like this?
>
> format=yuva, lutyuv=y=a:u=minval:v=minval
>
> Basically, being able to specify that the y (luma) channel output is
> equal to the a (alpha) channel of the input?
>
> Being able to swap color channels around would be good:
>
> format=rgb, lutrgb=r=b:g=r:b=g

I've actually written a filter to do this.  I use it to convert a colour
plane into the alpha channel.  The main limitation is it only works for RGB.  
I'm planning on submitting it to the -devel list when I have time.

Though I expect it will take quite a few revisions before it is acceptable,
because I copied and pasted another filter then mauled it until it did what I
needed, so there is a lot of rubbish in it.

--
Gavin Kinsey
AD Holdings Plc


Closed IPTV, the new safe and secure deterministic IP Video solution from Dedicated Micros, is now shipping through selected distributors.
- Come and see this award winning plug and play, IP Video innovation at one of our Roadshows around the UK visit: https://www.dedicatedmicros.com/europe/ClosedIPTVRoadshow2011
- Contact our Customer Services Team for more information regarding how to enter the world of safe and secure hybrid IP and analogue video surveillance systems.
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user
Loading...