Click here to Skip to main content
15,867,568 members
Articles / Desktop Programming / MFC

Ticker ( Showing or Scrolling Text Over Running Video )

Rate me:
Please Sign up or sign in to vote.
3.33/5 (8 votes)
26 Sep 20061 min read 107.7K   1.8K   52   23
This article tells how you can show your text over video, change text, text color, text background color and its transparency.
Sample Image - Ticker.jpg

Introduction

Showing something over running video? You can see my previous article to show an image over video. But this time, I am going to do some more artwork or text work over running video.

Ticker

Displaying text over video? This project has some similarities with my previous project, but it is not much similar. Here the text also scrolls over video.

Prerequisite

It is a prerequisite to read my article which displays image over video. This is because in that article, I have explained everything which is required to display an image over video, and displaying the text is not much different. So here in this article, I will just stick to the working code which is needed to display text over video.

Prepare the Ground with IVMRMixerControl9

First of all we need to set some preferences for mixing. Because the default mixing preferences are not good for blending the text over video, in the code below I am doing the same:

C++
// Request point filtering (instead of bilinear filtering)
// to improve the text quality. In general, if you are
// not scaling the app Image, you should use point filtering.
// This is very important if you are doing source color keying.
pVmr->QueryInterface(IID_IVMRMixerControl9, (void**)&pMix);
DWORD dwPrefs=0;
pMix->GetMixingPrefs(&dwPrefs);
dwPrefs |= MixerPref_PointFiltering;
dwPrefs &= ~(MixerPref_BiLinearFiltering);
pMix->SetMixingPrefs(dwPrefs);

Preparing the Image From Text

Now we need to make the image having the text we want to show over video.

C++
CDC * pdc = GetDC(); 
CDC mCompatibleDC;
mCompatibleDC.CreateCompatibleDC(pdc);
mCompatibleDC.SelectObject(mFont);
CSize strSize = mCompatibleDC.GetTextExtent(strFinish);
CBitmap bm;
bm.CreateCompatibleBitmap(pdc,strSize.cx,strSize.cy);
mCompatibleDC.SelectObject(&bm);
mCompatibleDC.SetBkColor(mBK_Color);
mCompatibleDC.SetTextColor(mTXT_Color);
mCompatibleDC.TextOut(0,0,strFinish);

Showing the Text Over Video

Now we will prepare for showing the image with text over video.

C++
VMR9AlphaBitmap bmpInfo;
ZeroMemory(&bmpInfo, sizeof(bmpInfo) );
bmpInfo.dwFlags |= VMRBITMAP_HDC;
bmpInfo.hdc = pDC->m_hDC;
LONG cx, cy;
pWC->GetNativeVideoSize(&cx, &cy, NULL, NULL);
bmpInfo.rSrc = Rect;
// rDest specifies the destination rectangle in composition space (0.0f to 1.0f)
bmpInfo.rDest.right = 1.0f;
bmpInfo.rDest.left = 0.0f;
bmpInfo.rDest.top = (float)(cy - Rect.Height()) / (float)cy - EDGE_BUFFER;
bmpInfo.rDest.bottom = 1.0f - EDGE_BUFFER;
// Set the transparency value (1.0 is opaque, 0.0 is transparent).
bmpInfo.fAlpha = 1.0;
pBmp->SetAlphaBitmap(&bmpInfo);

All is done. Now you can blend any text over video.

More Info

If you are interested in more information, see my blog.

History

  • 26 Sep 2006 First version

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Pakistan Pakistan
tanvon malik ( real name Tanveer Ahmad )I am a CNC Programmer, cnc setter, cnc operator. want to know about me visit my websites.
CNC Programming
CNC Manuals
DXF & GCode Files with Online Viewers
Komment.me

I been in Switzerland MAG former +FMS+ for CNC training.


Most interesting technologies I like COM MFC DirectShow such as filter development. I am from Pakistan.
Have worked on projects mostly related video capturing, video data processing and real time object tracking on videos. For these I have worked on projects which use "Open CV Library". Which is mostly used for capturing data and its processing.

Comments and Discussions

 
QuestionMy voite is 1 Pin
Greg_moon28-Jul-12 22:15
Greg_moon28-Jul-12 22:15 
My voite is 1
QuestionCan i get same project in C# [modified] Pin
Azhar Saiyed23-Sep-10 2:43
Azhar Saiyed23-Sep-10 2:43 
GeneralDownload problem Pin
Member 461091624-Feb-10 21:16
Member 461091624-Feb-10 21:16 
QuestionOverlay text in External Video Renders Pin
kannan1237-Mar-09 6:27
kannan1237-Mar-09 6:27 
Generalfixed size text display on video Pin
yorawat12-Jan-09 22:15
yorawat12-Jan-09 22:15 
QuestionWhat if the source is not a video file. Pin
Taran930-Sep-08 21:32
Taran930-Sep-08 21:32 
Questionhow to overlay multiple text on video Pin
mythili29-May-08 2:00
mythili29-May-08 2:00 
AnswerRe: how to overlay multiple text on video Pin
Danoo4-Jun-08 0:45
Danoo4-Jun-08 0:45 
GeneralRe: how to overlay multiple text on video Pin
mythili9-Jun-08 18:34
mythili9-Jun-08 18:34 
GeneralRe: how to overlay multiple text on video Pin
mythili11-Jun-08 3:45
mythili11-Jun-08 3:45 
Generalerror in creating vmr filter Pin
san07618-Mar-08 19:09
san07618-Mar-08 19:09 
Questionhow can I use "CLSID_VideoMixingRenderer9" in smart device project. Pin
Suman Kumar Sikdar9-Apr-07 19:33
Suman Kumar Sikdar9-Apr-07 19:33 
QuestionC# Pin
Mario_F13-Dec-06 12:43
Mario_F13-Dec-06 12:43 
AnswerRe: C# Pin
ieremix9-Jan-07 10:03
ieremix9-Jan-07 10:03 
GeneralDoesn't Compile in Visual C++ Express 2005 Pin
reginaldStjohn13-Dec-06 6:28
reginaldStjohn13-Dec-06 6:28 
GeneralRe: Doesn't Compile in Visual C++ Express 2005 Pin
tanvon malik6-Sep-08 22:14
tanvon malik6-Sep-08 22:14 
Generalthanks Pin
shital_harode@rediffmail.com31-Oct-06 22:15
shital_harode@rediffmail.com31-Oct-06 22:15 
GeneralRe: thanks Pin
tanvon malik6-Sep-08 21:53
tanvon malik6-Sep-08 21:53 
Generaltext over video Pin
shital_harode@rediffmail.com30-Oct-06 22:44
shital_harode@rediffmail.com30-Oct-06 22:44 
GeneralRe: text over video Pin
tanvon malik31-Oct-06 2:17
tanvon malik31-Oct-06 2:17 
GeneralRe: text over video Pin
JaneYan6-Feb-07 15:22
JaneYan6-Feb-07 15:22 
GeneralRe: text over video Pin
tanvon malik6-Sep-08 22:13
tanvon malik6-Sep-08 22:13 
GeneralYou might want to reload your demo project Pin
fwsouthern27-Sep-06 9:39
fwsouthern27-Sep-06 9:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.