Overlay a DC (device context) on top of a video?

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Overlay a DC (device context) on top of a video?

Tim Kuo

Is it possible to overlay a DC (device context) on top of a video? The DC could have (for example) text or a graphic, and would be (mostly) transparent. Use cases: subtitling, elapsed time display, codec of video, etc.


From the wxPython demos, it looked straightforward to overlay something on a static image. But I couldn’t get a DC to overlay successfully on a video. TIA for any examples or tutorials.

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Overlay a DC (device context) on top of a video?

Tim Roberts
Tim Kuo wrote:

Is it possible to overlay a DC (device context) on top of a video? The DC could have (for example) text or a graphic, and would be (mostly) transparent. Use cases: subtitling, elapsed time display, codec of video, etc.

From the wxPython demos, it looked straightforward to overlay something on a static image. But I couldn’t get a DC to overlay successfully on a video. TIA for any examples or tutorials.


"Video" meaning what?  Exactly how are you playing and rendering the video?

To do what you've asked, you have to use a chromakey, like the weather guys do on TV.  You paint your window with some unusual color that you won't use in your graphic.  You set up the video renderer to use chromakey, and tell it your unusual color.  Then, the graphics card will only display the video where the window contains your chromakey color.  If you draw other graphics, the graphics card will display those instead of the video pixels.

But doing that means you have to have fairly direct control over the video process.
-- 
Tim Roberts, [hidden email]
Providenza & Boekelheide, Inc.

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

smime.p7s (5K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Overlay a DC (device context) on top of a video?

Matt Newville
In reply to this post by Tim Kuo
Tim,



On Wed, Aug 22, 2018 at 2:16 PM Tim Kuo <[hidden email]> wrote:

Is it possible to overlay a DC (device context) on top of a video? The DC could have (for example) text or a graphic, and would be (mostly) transparent. Use cases: subtitling, elapsed time display, codec of video, etc.


From the wxPython demos, it looked straightforward to overlay something on a static image. But I couldn’t get a DC to overlay successfully on a video. TIA for any examples or tutorials.


If this is a follow-up to your recent question about center an image on resize events, and if your 'video' is a stream of images, then yes you can draw overlay objects on each image as it comes in.  Following up on my answer to your earlier question, I do such drawing of graphic elements but left it out of the earlier answer out of simplicitly and because you did not ask.  There I had an onPaint() method that responded to EVT_PAINT events and did


       
dc = wx.AutoBufferedPaintDC(self)
        
dc.Clear()
       
dc.DrawBitmap(bitmap, pad_w, pad_h, useMask=True)

but while you're there with a live DC object, you might as well as a scalebar or crosshair or something.   Perhaps

        dc.SetPen(wx.Pen(wx.Color(250, 250, 100), 4, wx.SOLID)) 
        dc.DrawLine(400, 750,  600, 750)
        dc.DrawLine(400, 740,  400, 760)
        dc.DrawLine(
6
00, 7
4
0, 
6
00, 7
6
0)

If you are really asking about showing data from a video file, I have no idea ;).

--Matt

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Overlay a DC (device context) on top of a video?

Tim Kuo
In reply to this post by Tim Roberts
I'm not thinking of anything as sophisticated as chromakey. I'm just playing back an mp4 video using wx.media.MediaCtrl, and -- since it initially presents as a still frame (video stopped) -- it would be
nice to overlay an arrow icon or something as a visual hint that this is a video that can be played
if you double-click it.

On Wednesday, August 22, 2018 at 7:38:40 PM UTC-4, Tim Roberts wrote:
Tim Kuo wrote:

Is it possible to overlay a DC (device context) on top of a video? The DC could have (for example) text or a graphic, and would be (mostly) transparent. Use cases: subtitling, elapsed time display, codec of video, etc.

From the wxPython demos, it looked straightforward to overlay something on a static image. But I couldn’t get a DC to overlay successfully on a video. TIA for any examples or tutorials.


"Video" meaning what?  Exactly how are you playing and rendering the video?

To do what you've asked, you have to use a chromakey, like the weather guys do on TV.  You paint your window with some unusual color that you won't use in your graphic.  You set up the video renderer to use chromakey, and tell it your unusual color.  Then, the graphics card will only display the video where the window contains your chromakey color.  If you draw other graphics, the graphics card will display those instead of the video pixels.

But doing that means you have to have fairly direct control over the video process.
-- 
Tim Roberts, <a href="javascript:" target="_blank" gdf-obfuscated-mailto="HjYMUaJmDAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">ti...@...
Providenza & Boekelheide, Inc.

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Overlay a DC (device context) on top of a video?

Tim Kuo
In reply to this post by Matt Newville
Matt -- Thanks for the info. I'm playing back an mp4 using wx.media.MediaCtrl, and would like to overlay a simple static bitmap on top of the mp4. Is that possible?  -- Tim

p.s. I haven't had the time to try out your EVT_PAINT recommendation, but some reading/browsing 
says that you've pointed me in the right direction in that regard. Thanks!

On Wednesday, August 22, 2018 at 11:00:26 PM UTC-4, Matt Newville wrote:
Tim,



On Wed, Aug 22, 2018 at 2:16 PM Tim Kuo <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="0I7W4qRxDAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">sin...@...> wrote:

Is it possible to overlay a DC (device context) on top of a video? The DC could have (for example) text or a graphic, and would be (mostly) transparent. Use cases: subtitling, elapsed time display, codec of video, etc.


From the wxPython demos, it looked straightforward to overlay something on a static image. But I couldn’t get a DC to overlay successfully on a video. TIA for any examples or tutorials.


If this is a follow-up to your recent question about center an image on resize events, and if your 'video' is a stream of images, then yes you can draw overlay objects on each image as it comes in.  Following up on my answer to your earlier question, I do such drawing of graphic elements but left it out of the earlier answer out of simplicitly and because you did not ask.  There I had an onPaint() method that responded to EVT_PAINT events and did


       
dc = wx.AutoBufferedPaintDC(self)
        
dc.Clear()
       
dc.DrawBitmap(bitmap, pad_w, pad_h, useMask=True)

but while you're there with a live DC object, you might as well as a scalebar or crosshair or something.   Perhaps

        dc.SetPen(wx.Pen(wx.Color(250, 250, 100), 4, wx.SOLID)) 
        dc.DrawLine(400, 750,  600, 750)
        dc.DrawLine(400, 740,  400, 760)
        dc.DrawLine(
6
00, 7
4
0, 
6
00, 7
6
0)

If you are really asking about showing data from a video file, I have no idea ;).

--Matt

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Overlay a DC (device context) on top of a video?

Tim Kuo
In reply to this post by Tim Kuo

For example, here's screen shot of Chrome displaying a JPG image and an mp4 video (Google Chrome 68.0.3440.106, MacOS 10.13.5). Even without the video running, it's pretty clear that clicking on the arrow will cause a video to be played. Is that visual hinting something that we can replicate using wxPython ?

<a imageanchor="1" href="about:invalid#zClosurez" style="margin-left: 1em; margin-right: 1em;">Screen Shot 2018-08-22 at 11.22.53 PM.png



On Wednesday, August 22, 2018 at 3:16:44 PM UTC-4, Tim Kuo wrote:

Is it possible to overlay a DC (device context) on top of a video? The DC could have (for example) text or a graphic, and would be (mostly) transparent. Use cases: subtitling, elapsed time display, codec of video, etc.


From the wxPython demos, it looked straightforward to overlay something on a static image. But I couldn’t get a DC to overlay successfully on a video. TIA for any examples or tutorials.

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Overlay a DC (device context) on top of a video?

Karsten Hilbert
In reply to this post by Tim Kuo
On Wed, Aug 22, 2018 at 08:17:08PM -0700, Tim Kuo wrote:

> I'm not thinking of anything as sophisticated as chromakey. I'm just
> playing back an mp4 video using wx.media.MediaCtrl, and -- since it
> initially presents as a still frame (video stopped) -- it would be
> nice to overlay an arrow icon or something as a visual hint that this is a
> video that can be played
> if you double-click it.

Extract the first frame, modify and display that as a still
image, load and play the video when the user clicked the
still image.

Karsten
--
GPG  40BE 5B0E C98E 1713 AFA6  5BC0 3BEA AC80 7D4F C89B

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Overlay a DC (device context) on top of a video?

Tim Kuo
@ Karsten: Clever! I wonder if that's what the browser is doing, under the hood?

So, back to the original question: Is there a way to overlay (say) the "file name" or "video codec used" or "file date" for several seconds? Without having to extract/modify each individual frame of the video?


On Thursday, August 23, 2018 at 5:19:04 AM UTC-4, Karsten Hilbert wrote:
On Wed, Aug 22, 2018 at 08:17:08PM -0700, Tim Kuo wrote:

> I'm not thinking of anything as sophisticated as chromakey. I'm just
> playing back an mp4 video using wx.media.MediaCtrl, and -- since it
> initially presents as a still frame (video stopped) -- it would be
> nice to overlay an arrow icon or something as a visual hint that this is a
> video that can be played
> if you double-click it.

Extract the first frame, modify and display that as a still
image, load and play the video when the user clicked the
still image.

Karsten
--
GPG  40BE 5B0E C98E 1713 AFA6  5BC0 3BEA AC80 7D4F C89B

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Overlay a DC (device context) on top of a video?

rolfofsaxony
In reply to this post by Tim Kuo

To some extent you have already answered your own question.

Insomuch as you mentioned subtitles in one of your original posts.

A sneaky way to provide what you are asking for, is to extract the information that you require from the video and then write a subtitle file (filename.srt), containing the information that you wish to have displayed. The video playing tool behind your code should pick up on that and display it for you.

There are 2 subtitle formats (that I know of):

SubRip Subtitles
The SubRip time stamp is hh:mm:ss,mmm (Note the comma between ss and mmm) (I think it is French, thus the comma)
The SubRip file format is as follows:
1. A numeric counter identifying each sequential subtitle
2. The time that the subtitle should appear on the screen, followed by --> and the time it should disappear
3. subtitle text itself on one or more lines
4. blank line containing no text, indicating the end of this subtitle

i.e.
01
00:00:01,000 --> 00:09:55,320
Format: Mp4  Duration: 00:10:23

02
00:00:10,000 --> 00:00:15,000
Brought to you by Kuo productions

WebVTT Subtitles
The WebVTT time stamp is hh:mm:ss.mmm (Note the full-stop between ss and mmm)
The WebVTT file format is as follows:
1. Optional numeric counter identifying each sequential subtitle
2. The time that the subtitle should appear on the screen, followed by --> and the time it should disappear
3. subtitle text itself on one or more lines
4. blank line containing no text, indicating the end of this subtitle
i.e.
00:00:01.000 --> 00:09:55.320
Format: Mp4  Duration: 00:10:23

00:00:10.000 --> 00:00:15.000
Brought to you by Kuo productions

It isn't what you want but to a degree, it serves the same purpose, is simple and almost free.
Regards
Rolf

On Wednesday, August 22, 2018 at 9:16:44 PM UTC+2, Tim Kuo wrote:

Is it possible to overlay a DC (device context) on top of a video? The DC could have (for example) text or a graphic, and would be (mostly) transparent. Use cases: subtitling, elapsed time display, codec of video, etc.


From the wxPython demos, it looked straightforward to overlay something on a static image. But I couldn’t get a DC to overlay successfully on a video. TIA for any examples or tutorials.

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