Introduction
Modifying AVI files can always be done using popular media programs available online, but these programs work without allowing you to add your own magic.
In this article, we’ll build our own AVI editing application and explore some fun techniques using simple code additions.
Background
This project is destined for the intermediate level MFC developers. The MSVS-2015 pro installed is
a prerequisite to proper text comprehension.
Demo Explanations
As a sample, the long-suffering well-known “Beatles” gif selected: only the lazy would not try to “improve” this video. Start MyAviShop.exe in the MyAviShopDemo
directory enclosed. Just follow step by step the instructions below and after completion, you’ll have a comprehensive idea of the features of the program.
1.1 AVI Open and Controls
Select the DemoSample/Beatles_01.avi file with the menu command File->Open Avi. The use of some controls demonstrated in the sample below:
1.2 Mask of the Object Detected Handling
Select menu Polygon->New Polygon and number of points expected in your new mask polygon. Move and resize all the polygon of the object detected using the standard Rechittest
procedures (just pay attention to the Keep Ratio checkbox condition):
In the sample provided, this job already has been done; therefore select menu Polygon->Delete All Polygons, select menu Polygon->Open Polygonset and select Beatles_a.pl2 file; Next, use menu Polygon->Mask PolygonSet to create the list of the masked images of the object detected with the one-tone color background which may be superposed above any AVI video:
In the sample provided, this job already has been done for every person and fixed in the files as Beatles_01_of_Beatles_a.mpl for a, b, c, d
masks.
Now we shall arrange the copy of people moving in the one-tone color background:
- Open Blank.avi as a target with the menu File Avi->Open Avi command;
- Capture masks for Blank.avi of Beatles_a.avi, Beatles_b.avi, Beatles_c.avi, Beatles_d.avi. with the menu Mask Edit->MaskCapture and open *.mpl file corresponding.
- Save current AVI with
File Avi->Save as Avi:
The results you may see in Beatles_Blank.avi:
Now we shall arrange the mask of people moving in the changed order and save current AVI with File Avi->Save as Avi (results you may see in Beatles_Blank_r.avi):
Next, apply this mask to the empty street (the results you may see in Beatles_r.avi):
In this article title AVI, people seemed like a walking roundabout. And this is the smallest trick possible to arrange:
1.3 Screen Capture
Call menu File Images->Screen Capture to pick up images from the screen; (Result in the ScreenCap February 02_2019_15_56.avi file):
2. Project Source Storage and Building Notes
The source files of the project are located in two directories:
MyAviShop
– created with the standard MFC AppWizard:
- MyAviShop.cpp, MyAviShopDoc.cpp, MyAviShopView.cpp, MainFrm.cpp, MyAviShop.rc, resource.h - created with the standard MFC AppWizard and all the messages handling procedures have been arranged also with MFC standards;
- Splitter.cpp have been inserted instead of the originally MFC created ChildFrm.cpp;
- All the dialogs’ concerned classes created with the standard MFC AppWizard;
- MaskHandle.cpp and MaskUnit.cpp – created by the author for the mask images handling;
GlobUse
– the program set of the procedures which are independent of the Main Project and may be included in any MFC project as required:
- EasyAVI.cpp - borrowed from the article "Easy AVI" by Andy Bantly;
- MyRectTrack.cpp - has been created by the author for the project provided in order to perform flexible operations with the
Mask Recttrack
; - Another code has been earlier created by the author and has been already used with other projects as well as CodeProject including.
Even if you are first time working with MSVS, just select menu Debug->Start without debugging and the project MyAviShop
should start building and working.
3. Codes Explanations
All the Menu and Controls handling Commands have been done with standard MFC AppWizard technologies. Therefore, I feel nothing to explain better than in the standard tutorials. Just some points that I’ve developed myself.
3.1 Mask Visualization
The mask enclosed in some polygon area may be shredded out using two graphical contests (black-white and some buffer):
if (m_pCurPolygon->m_PointList.GetCount() > 2) {
double scale = m_pDoc->m_Scale;
m_bwDC.BitBlt(tRect.left, tRect.top, tRect.Width(),
tRect.Height(), NULL, 0, 0, WHITENESS);
m_pCurPolygon->DrawBlackStroke(&m_bwDC, Vector_2D(1), 0,
m_pCurPolygon->turnPoint*scale, 0, scale, scale, FALSE, TRUE);
m_bwDC.BitBlt(tRect.left, tRect.top, tRect.Width(),
tRect.Height(), NULL, 0, 0, DSTINVERT);
pImg->StretchBlt(m_bufDC.m_hDC, m_pixOffSet.x, m_pixOffSet.y,
int(scale * pImg->GetWidth()), int(scale * pImg->GetHeight()));
m_bufDC.BitBlt(tRect.left, tRect.top, tRect.Width(),
tRect.Height(), &m_bwDC, 0, 0, SRCAND);
m_memDC.FillRect(tRect, &CBrush(RGB(127, 127, 127)));
pImg->StretchBlt(m_memDC.m_hDC, m_pixOffSet.x, m_pixOffSet.y,
int(scale * pImg->GetWidth()), int(scale * pImg->GetHeight()), SRCAND);
m_memDC.TransparentBlt(tRect.left, tRect.top, tRect.Width(),
tRect.Height(), &m_bufDC, tRect.left, tRect.top, tRect.Width(),
tRect.Height(), RGB(255, 255, 255));
m_pCurPolygon->DrawSolidStroke(&m_memDC, Vector_2D(1), 0,
m_pCurPolygon->turnPoint*scale, 0, scale, scale, FALSE, TRUE);
}
- The black-white contest to fill with the white color;
- Draw black area enclosed with the polygon;
- Revert colors: a white polygon with the black background;
- Put the original image into buffer contest;
- Put BW mask from a black-white contest on to buffer contents using
SRCAND
: on the buffer contest, we have the mask of the image enclosed with the polygon on the black background.
3.2 Mask Recttrack
For the mask handling, some special classes have been inserted:
CMyRectTrack
– derived from the Polygon_2D
class; used for the moving, resizing and rotating of the mask; CMaskUnit
- derived from the CObject
class; used to store the information of the mask: position, size, an angle of turn, the number in the list of mask images; CMaskHandle
- derived from the CObject
class; used to manage the list of the CMaskUnit Objects
and has the references both to the target list of images and to the mask list of images.
Set of masks drawing procedure as follows:
for (POSITION pos = m_maskWindowList.GetHeadPosition(); pos != NULL;)
{
CMyAviShopDoc * pDoc = (CMyAviShopDoc *)m_maskWindowList.GetNext(pos);
for (POSITION psn = pDoc->m_maskHandleList.GetHeadPosition(); psn != NULL;)
{
CMaskHandle * ptr = (CMaskHandle *)pDoc->m_maskHandleList.GetNext(psn);
if (ptr->m_pAviHost == m_pDoc)
{
POSITION psa = ptr->m_maskUnitList.FindIndex(nn);
if (psa != NULL)
{
CMaskUnit * pMsk = (CMaskUnit *)ptr->m_maskUnitList.GetAt(psa);
m_pDoc->m_pCurMaskUnit = pMsk;
m_pMyRectTrack->m_angle = pMsk->m_angle;
m_pMyRectTrack->SetRect(pMsk->m_tgtRect);
if (m_pDoc->m_bDrawMaskRect && pMsk->m_number >= 0)
m_pMyRectTrack->DrawRectTrack(&m_memDC, m_pDoc->m_Scale);
else
m_pMyRectTrack->DrawRectTrack(&m_bwDC, m_pDoc->m_Scale);
pMsk->SetMask(&m_memDC, &m_bufDC, &m_bwDC, m_pMyRectTrack, m_pDoc->m_Scale);
}
break;
} }
}
4. Your Own Applications Development Using this Project
You may pick up all this project, rename it with the project of my former CodeProject article "MFC Project from Existing Code in One Click" and combine and improve the code as you like.
Or you may pick up any of GlobUse directory files from this project and include it in any MFC project with menu Project->Existing Item.
Or you may simply use the MyAviShop.exe from the demo provided to “improve” any AVI and/or NetWork scene captured.
Your references to my code should be highly appreciated if any.
Discussion
The idea of this article is that the project provided with you may arrange good support to the usual AVI editor programs or even to develop your own AVI Shop program.
And this is the illustration of the CodeProject performance capabilities to help the developers in any solution.
Conclusion, Points of Interest, and Acknowledgements
The gif illustrations have been created with the help of the MyAviShop
itself: one session performed the actions while another one "spied" the performance.
This project is the instrument to arrange some tricks and effects as you like having in mind that the codes are open.
Some samples of my earlier versions of this job are available on YouTube/vl2525.
Many thanks to Andy Bantly and Darryl Bryk for their fine job.
History
- 2nd April, 2019: Initial version