Connecting Tech Pros Worldwide Help | Site Map

video edit in c++

Newbie
 
Join Date: Sep 2009
Posts: 2
#1: Sep 25 '09
Hello,

I'd appreciate your suggestions about this drafted application for video editing. It is just the first idea, it is (barely) working but can be improved a lot! Find the code attached below. The main goal is to play an avi, averlap an annotation/image and save the new avi.

Thank you very much for your help and comments :-)

Expand|Select|Wrap|Line Numbers
  1. // Avi PostEdit - Annotation Re-capture
  2. // Initial drafted code developed by giulio8  - 22/6/2009
  3.  
  4. // Play an AVI using the MSvfw32.lib 
  5. // in the case of Dev-C++ link with libmsvfw32.a via
  6. // Project>>Project Options>>Parameters>>Add Lib>>libmsvfw32.a
  7.  
  8.  
  9.  
  10. #include <cstdio>
  11. #include <fstream>
  12. using namespace std;
  13.  
  14. #include <windows.h>
  15.  
  16.  
  17. #include <vfw.h>
  18.  
  19.  
  20.  
  21. #include "avi_utils.h"
  22.  
  23.  
  24. #include <shlwapi.h>
  25. //Nota: perché questo codice funzioni va linkato anche con shlwapi.lib; in VC++ si può ottenere tale effetto anche con un #pragma non standard
  26. #ifdef _MSC_VER
  27. #pragma comment(lib,"shlwapi.lib")
  28. #endif
  29. //...
  30.  
  31.  
  32. #define ID_MCIFrame 0
  33. #define ID_MENU1 9001
  34. #define ID_MENU2 9002
  35. #define ID_MENU3 9003
  36. #define ID_MENU4 9004
  37. #define ID_MENU5 9005
  38. #define ID_MENU6 9006
  39. #define ID_MENU7 9007
  40.  
  41. static HINSTANCE BCX_hInstance;
  42. static int     BCX_ScaleX;
  43. static int     BCX_ScaleY;
  44. static char    BCX_ClassName[2048];
  45. static HANDLE  ghInst;
  46. static HWND    Form1;
  47. static HWND    MCIFrame;
  48. static HMENU   MainMenu;
  49. static HMENU   FileMenu;
  50. static OPENFILENAME OpenFileName;
  51. static char    szFile[2048];
  52. static char    szFileTitle[2048];
  53. static char    szFileBmp[2048];
  54. static char    szFileTitleBmp[2048];
  55. static char    szFileBmpC[2048];
  56. static char    szFileTitleBmpC[2048];
  57.  
  58. #define Show(Window)  RedrawWindow(Window,0,0,0);ShowWindow(Window,SW_SHOW);
  59.  
  60. HWND    BCX_Form(char*,int=0,int=0,int=250,int=150,int=0,int=0);
  61. void    BCX_Set_Form_Color (HWND,COLORREF);
  62. void    Center (HWND,HWND=0,HWND=0);
  63. char*   BCX_TmpStr(size_t);
  64. char*   str (double);
  65. char*   curdir (void);
  66.  
  67. void    FormLoad (void);
  68. LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
  69. int     InitOpenFileName (void);
  70. int     PopFileOpenDlg (HWND, char *, char *);
  71. BOOL    AddMenu (HWND);
  72.  
  73. LONG lFrame_start;
  74. LONG lFrame_end;
  75.  
  76. // standard Windows Graphical User Interface main
  77. int WINAPI WinMain(HINSTANCE hInst,HINSTANCE hPrev,LPSTR CmdLine,int CmdShow)
  78. {
  79.  WNDCLASS Wc;
  80.  MSG      Msg;
  81.  // *****************************
  82.  strcpy(BCX_ClassName,"ApiEdit");
  83.  // ************************************
  84.  // Scale Dialog Units To Screen Units
  85.  // ************************************
  86.  RECT rc          =  {0,0,4,8};
  87.  MapDialogRect       (NULL,&rc);
  88.  BCX_ScaleX       =  rc.right/2;
  89.  BCX_ScaleY       =  rc.bottom/4;
  90.  BCX_hInstance    =  hInst;
  91.  // ******************************************************
  92.  Wc.style         =  CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
  93.  Wc.lpfnWndProc   =  WndProc;
  94.  Wc.cbClsExtra    =  0;
  95.  Wc.cbWndExtra    =  0;
  96.  Wc.hInstance     =  hInst;
  97.  Wc.hIcon         =  LoadIcon(NULL,IDI_WINLOGO);
  98.  Wc.hCursor       =  LoadCursor(NULL,IDC_ARROW);
  99.  Wc.hbrBackground =  (HBRUSH)(COLOR_BTNFACE+1);
  100.  Wc.lpszMenuName  =  NULL;
  101.  Wc.lpszClassName =  BCX_ClassName;
  102.  RegisterClass(&Wc);
  103.  
  104.  FormLoad();
  105.  // event message loop 
  106.  while(GetMessage(&Msg,NULL,0,0))
  107.  {
  108.     HWND hActiveWindow = GetActiveWindow();
  109.     if (!IsWindow(hActiveWindow) || !IsDialogMessage(hActiveWindow,&Msg))
  110.       {
  111.         TranslateMessage(&Msg);
  112.         DispatchMessage(&Msg);
  113.       }
  114.  }
  115.  return Msg.wParam;
  116. }
  117.  
  118.  
  119. // circular storage, hold the memory leaks to a minimum
  120. char *BCX_TmpStr (size_t Bites)
  121. {
  122.   static int   StrCnt;
  123.   static char *StrFunc[2048];
  124.   StrCnt=(StrCnt + 1) & 2047;
  125.   if(StrFunc[StrCnt]) free (StrFunc[StrCnt]);
  126.   return StrFunc[StrCnt]=(char*)calloc(Bites+128,sizeof(char));
  127. }
  128.  
  129.  
  130. char *str (double d)
  131. {
  132.   register char *strtmp = BCX_TmpStr(16);
  133.   sprintf(strtmp,"% .15G",d);
  134.   return strtmp;
  135. }
  136.  
  137.  
  138. char *curdir (void)
  139. {
  140.   register char *strtmp = BCX_TmpStr(2048);
  141.   GetCurrentDirectory (1024,strtmp);
  142.   return strtmp;
  143. }
  144.  
  145.  
  146. // center the window form on the screen, optional, for looks
  147. void Center (HWND hwnd, HWND Xhwnd, HWND Yhwnd)
  148. {
  149.   RECT rect, rectP;
  150.   int  x, y, width, height;
  151.   int  screenwidth, screenheight;
  152.   if(Xhwnd==0)
  153.     {
  154.       RECT  DesktopArea;
  155.       RECT  rc;
  156.       SystemParametersInfo(SPI_GETWORKAREA,0,&DesktopArea,0);
  157.       GetWindowRect(hwnd,&rc);
  158.       SetWindowPos(hwnd,HWND_TOP,
  159.         ((DesktopArea.right-DesktopArea.left)-(rc.right-rc.left))/2+
  160.           DesktopArea.left,((DesktopArea.bottom-DesktopArea.top)-
  161.          (rc.bottom-rc.top))/2 + DesktopArea.top,0,0,SWP_NOSIZE);
  162.       return;
  163.     }
  164.   GetWindowRect (hwnd,&rect);
  165.   GetWindowRect (Xhwnd,&rectP);
  166.   width = rect.right-rect.left;
  167.   x = ((rectP.right-rectP.left)-width)/2 + rectP.left;
  168.   if (Yhwnd==NULL)
  169.   {
  170.       height = rect.bottom-rect.top;
  171.       y = ((rectP.bottom-rectP.top)-height)/2 + rectP.top;
  172.   }
  173.   else
  174.   {
  175.       GetWindowRect(Yhwnd,&rectP);
  176.       height = rect.bottom-rect.top;
  177.       y = ((rectP.bottom-rectP.top)-height)/2+rectP.top;
  178.   }
  179.   screenwidth = GetSystemMetrics(SM_CXSCREEN);
  180.   screenheight = GetSystemMetrics(SM_CYSCREEN);
  181.   if ((x<0)) 
  182.     x=0;
  183.   if ((y<0)) 
  184.     y=0;
  185.   if ((x+width>screenwidth))   
  186.     x = screenwidth-width;
  187.   if ((y+height>screenheight)) 
  188.     y = screenheight-height;
  189.   MoveWindow (hwnd, x, y, width, height, FALSE);
  190. }
  191.  
  192.  
  193. // create the windows form
  194. HWND BCX_Form(char *Caption, int X, int Y, int W, int H, int Style, int Exstyle)
  195. {
  196.    HWND  A;
  197.    // assigne default style if none given
  198.    if (!Style)
  199.    {
  200.         Style= WS_MINIMIZEBOX  |
  201.         WS_SIZEBOX      |
  202.         WS_CAPTION      |
  203.         WS_MAXIMIZEBOX  |
  204.         WS_POPUP        |
  205.         WS_SYSMENU;
  206.    }
  207.    A = CreateWindowEx(Exstyle,BCX_ClassName,Caption,
  208.    Style,
  209.    X*BCX_ScaleX,
  210.    Y*BCX_ScaleY,
  211.    (4+W)*BCX_ScaleX,
  212.    (12+H)*BCX_ScaleY,
  213.    NULL,(HMENU)NULL,BCX_hInstance,NULL);
  214.    SendMessage(A,(UINT)WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),
  215.      (LPARAM)MAKELPARAM(FALSE,0));
  216.    return A;
  217. }
  218.  
  219.  
  220. // color, why not
  221. void BCX_Set_Form_Color (HWND hWnd, COLORREF Kolor)
  222. {
  223.   HBRUSH hbr=CreateSolidBrush(Kolor);
  224.   DeleteObject((HBRUSH)SetClassLong(hWnd,GCL_HBRBACKGROUND,(DWORD)hbr));
  225.   InvalidateRect (hWnd,NULL,TRUE);
  226. }
  227.  
  228.  
  229. // the details - corner coordinates,width,height,title
  230. void FormLoad (void)
  231. {
  232.     Form1=BCX_Form("PostEdit Capture",0,0,197,170);
  233.     SetClassLong(Form1,GCL_STYLE,GetClassLong(Form1,GCL_STYLE)|CS_DBLCLKS);
  234.     BCX_Set_Form_Color(Form1,RGB(0,0,0));
  235.     //  Now create the MCIWnd 
  236.     MCIFrame=MCIWndCreate(Form1,(HINSTANCE)ghInst,WS_CHILD|WS_VISIBLE|MCIWNDF_NOPLAYBAR|MCIWNDF_NOTIFYALL,"");
  237.     AddMenu(Form1);
  238.     Center(Form1);
  239.     Show(Form1);
  240.  
  241. }
  242.  
  243. int InitSaveFileName (void)
  244. {
  245.   *szFile=0;
  246.   *szFileTitle=0;
  247.   OpenFileName.lStructSize=sizeof(OPENFILENAME);
  248.   OpenFileName.hwndOwner=MCIFrame;
  249.   OpenFileName.hInstance=(HINSTANCE)ghInst;
  250.   OpenFileName.lpstrFilter =
  251.     "Bmp Files (*.BMP)\0*.bmp\0All Files(*.*)\0*.*\0\0";
  252.   OpenFileName.lpstrCustomFilter=NULL;
  253.   OpenFileName.nMaxCustFilter=0;
  254.   OpenFileName.nFilterIndex=0;
  255.   OpenFileName.lpstrFile=szFile;
  256.   OpenFileName.nMaxFile=MAX_PATH;
  257.   OpenFileName.lpstrFileTitle=szFileTitle;
  258.   OpenFileName.nMaxFileTitle=MAX_PATH;
  259.   OpenFileName.lpstrInitialDir=curdir();
  260.   OpenFileName.lpstrTitle=NULL;
  261.   OpenFileName.nFileOffset=0;
  262.   OpenFileName.nFileExtension=0;
  263.   OpenFileName.lpstrDefExt="*.bmp";
  264.   OpenFileName.lCustData=0L;
  265.   OpenFileName.Flags=OFN_SHOWHELP|OFN_PATHMUSTEXIST|OFN_HIDEREADONLY;
  266.   OpenFileName.lpfnHook=NULL;
  267.   OpenFileName.lpTemplateName=NULL;
  268.   return 0;
  269. }
  270.  
  271. int PopFileSaveDlg (HWND Form1, char *szFileBmp, char *szFileTitleBmp)
  272. {
  273.   OpenFileName.lpstrTitle="Save bitmap";
  274.   OpenFileName.hwndOwner=MCIFrame;
  275.   OpenFileName.lpstrFile=szFileBmp;
  276.   OpenFileName.lpstrFileTitle=szFileTitleBmp;
  277.   OpenFileName.Flags=OFN_EXPLORER|OFN_CREATEPROMPT;
  278.   return GetOpenFileNamePreview(&OpenFileName);
  279. }
  280.  
  281.  
  282.  
  283. /* 
  284. Funzione per scrivere l'handle di una bitmap su file 
  285. Thanks to http://www.geocities.com/krishnapg/bitmap.html#SaveBitmap 
  286. */ 
  287. void SaveBitmap(char *szFilename,HBITMAP hBitmap){ 
  288.       HDC        hdc=NULL; 
  289.       FILE*      fp=NULL; 
  290.       LPVOID     pBuf=NULL; 
  291.       BITMAPINFO bmpInfo; 
  292.       BITMAPFILEHEADER  bmpFileHeader; 
  293.       do{ 
  294.             hdc=GetDC(NULL); 
  295.             ZeroMemory(&bmpInfo,sizeof(BITMAPINFO)); 
  296.             bmpInfo.bmiHeader.biSize=sizeof(BITMAPINFOHEADER); 
  297.             GetDIBits(hdc,hBitmap,0,0,NULL,&bmpInfo,DIB_RGB_COLORS); 
  298.             if(bmpInfo.bmiHeader.biSizeImage<=0) 
  299.             bmpInfo.bmiHeader.biSizeImage=bmpInfo.bmiHeader.biWidth*abs(bmpInfo.bmiHeader.biHeight)*(bmpInfo.bmiHeader.biBitCount+7)/8; 
  300.             if((pBuf = malloc(bmpInfo.bmiHeader.biSizeImage))==NULL) 
  301.             { 
  302.                   //MessageBox( NULL, "Unable to Allocate Bitmap Memory", "Error", MB_OK|MB_ICONERROR); 
  303.                   break; 
  304.             }           
  305.             bmpInfo.bmiHeader.biCompression=BI_RGB; 
  306.             GetDIBits(hdc,hBitmap,0,bmpInfo.bmiHeader.biHeight,pBuf, &bmpInfo, DIB_RGB_COLORS);       
  307.             if((fp = fopen(szFilename,"wb"))==NULL) 
  308.             { 
  309.                   //MessageBox( NULL, "Unable to Create Bitmap File", "Error", MB_OK|MB_ICONERROR); 
  310.                   break; 
  311.             } 
  312.             bmpFileHeader.bfReserved1=0; 
  313.             bmpFileHeader.bfReserved2=0; 
  314.             bmpFileHeader.bfSize=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+bmpInfo.bmiHeader.biSizeImage; 
  315.             bmpFileHeader.bfType='MB'; 
  316.             bmpFileHeader.bfOffBits=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER); 
  317.             fwrite(&bmpFileHeader,sizeof(BITMAPFILEHEADER),1,fp); 
  318.             fwrite(&bmpInfo.bmiHeader,sizeof(BITMAPINFOHEADER),1,fp); 
  319.             fwrite(pBuf,bmpInfo.bmiHeader.biSizeImage,1,fp); 
  320.       }while(false); 
  321.             if(hdc)     ReleaseDC(NULL,hdc); 
  322.             if(pBuf)    free(pBuf); 
  323.             if(fp)      fclose(fp); 
  324.  
  325.  
  326. // event message handler
  327. LRESULT CALLBACK WndProc (HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
  328. {
  329.   static char s[2048];
  330.   memset(&s,0,sizeof(s));
  331.   static char mstr[2048];
  332.   memset(&mstr,0,sizeof(mstr));
  333.   static char mstr1[2048];
  334.   memset(&mstr1,0,sizeof(mstr1));
  335.   while(1)
  336.   {
  337.     if (Msg==WM_CREATE)
  338.     {
  339.       return 0;
  340.       break;
  341.     }
  342.     if (Msg==WM_COMMAND)
  343.     {
  344.       if (LOWORD(wParam)==ID_MENU2)
  345.       {
  346.           MCIWndClose(MCIFrame);
  347.           InitOpenFileName();
  348.          PopFileOpenDlg(Form1,szFile,szFileTitle);
  349. //           strcpy(szFile,"d:\\dati\\amss\\cam_guida2.avi");
  350.           if(strlen(szFile)>0)
  351.           {
  352.               MCIWndOpen(MCIFrame,szFile,0);
  353.   AppendMenu(FileMenu,MF_STRING,ID_MENU6,"&Start frame");
  354.  
  355.  
  356.           }
  357.           return 0;
  358.       }
  359.       if(LOWORD(wParam)==ID_MENU3)
  360.       {
  361.           MCIWndClose(MCIFrame);
  362.           ExitProcess(0);
  363.       }
  364.       //break;
  365.       // if(LOWORD(wParam)==ID_MENU4)
  366.       //{
  367.  
  368.       //}
  369.  
  370.  
  371.        if(LOWORD(wParam)==ID_MENU5)
  372.       {
  373. HDC hDc = CreateCompatibleDC(GetDC(MCIFrame));
  374. RECT rcWind;
  375. GetClientRect(MCIFrame, &rcWind);
  376. int width = rcWind.right - rcWind.left;
  377. int height = rcWind.bottom - rcWind.top;
  378.  
  379. static char    szFileAvi[2048];
  380. static char    szFileTitleAvi[2048];
  381.           InitOpenFileName();
  382.          PopFileOpenDlg(Form1,szFileAvi,szFileTitleAvi);
  383. HAVI avi = CreateAvi(szFileAvi,5,NULL);
  384.  
  385. static  char  bmptemp[2048];
  386.     BROWSEINFO bi = { 0 };
  387.     TCHAR path[MAX_PATH];
  388.     bi.lpszTitle = "Pick a Temp Directory";
  389.     bi.pszDisplayName = path;
  390.     LPITEMIDLIST pidl = SHBrowseForFolder ( &bi );
  391.     if ( pidl != 0 )
  392.     {
  393.         // get the name of the folder
  394.  
  395.  
  396.         sprintf(bmptemp, "%s", path);
  397.         // free memory used
  398.         IMalloc * imalloc = 0;
  399.         if ( SUCCEEDED( SHGetMalloc ( &imalloc )) )
  400.         {
  401.             imalloc->Free ( pidl );
  402.             imalloc->Release ( );
  403.         }
  404.     }
  405.  
  406.  
  407.  
  408. char buffer[100]; 
  409. LONG lFrame;
  410. lFrame = MCIWndGetPosition(MCIFrame); 
  411.  
  412. for (LONG i=lFrame_start; i<=lFrame_end; i++)
  413.     MCIWndSeek(MCIFrame,i);
  414.   HBITMAP hBmp = CreateCompatibleBitmap(GetDC(MCIFrame), width, height);   
  415.  
  416.    // join em up
  417.    SelectObject(hDc, hBmp);   
  418.  
  419.    // copy from the screen to my bitmap
  420.    BitBlt(hDc, 0, 0, width, height, GetDC(MCIFrame), 0, 0, SRCCOPY);  
  421.  
  422.       // avifile.appendNewFrame(hBitmap);
  423.  
  424.  
  425.  
  426.   //sprintf(buffer, "%s%i.bmp", bmptemp, i); // image a rajouter
  427.   sprintf(buffer, "%s.bmp", bmptemp);
  428.   SaveBitmap(buffer,hBmp);
  429.  
  430.   HBITMAP hBmpDIB =(HBITMAP)LoadImage(NULL,buffer,IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION);
  431.  
  432. if (i==lFrame_start) // Set up compression just before the first frame
  433.   {  AVICOMPRESSOPTIONS opts; 
  434.     ZeroMemory(&opts,sizeof(opts));
  435.     opts.fccHandler=mmioFOURCC('D','I','V','X');
  436.     SetAviVideoCompression(avi,hBmpDIB,&opts,true,Form1);
  437. }
  438.     AddAviFrame(avi,hBmpDIB);
  439.   DeleteObject(hBmp); 
  440.     DeleteObject(hBmpDIB); 
  441. }
  442. CloseAvi(avi);
  443. MessageBox(NULL,"Avi saved.","COMPLETED",MB_OK | MB_ICONINFORMATION);
  444.  
  445.  
  446.       }
  447.  
  448.  
  449.        if(LOWORD(wParam)==ID_MENU6)
  450.       {
  451.  
  452. lFrame_start = MCIWndGetPosition(MCIFrame);                                   
  453.   AppendMenu(FileMenu,MF_STRING,ID_MENU7,"&End Frame");
  454.             }
  455.        if(LOWORD(wParam)==ID_MENU7)
  456.       {
  457. lFrame_end = MCIWndGetPosition(MCIFrame);                                   
  458.             // AppendMenu(FileMenu,MF_STRING,ID_MENU4,"&Save bmp");
  459.   AppendMenu(FileMenu,MF_STRING,ID_MENU5,"&Save capture");
  460.             }
  461. break;
  462.     }
  463.  
  464.     if (Msg==MCIWNDM_NOTIFYMODE)
  465.     {
  466.       while(1)
  467.       {
  468.         if ((long)lParam==MCI_MODE_NOT_READY)
  469.         {
  470.           SetWindowText(Form1,"Not Ready");
  471.           break;
  472.         }
  473.         if ((long)lParam==MCI_MODE_PAUSE)
  474.         {
  475.           SetWindowText(Form1,"Paused");
  476.           break;
  477.         }
  478.         if ((long)lParam==MCI_MODE_PLAY)
  479.         {
  480.           SetWindowText(Form1,"Playing");
  481.           break;
  482.         }
  483.         if ((long)lParam==MCI_MODE_STOP)
  484.         {
  485.           SetWindowText(Form1,"Stopped");
  486.           break;
  487.         }
  488.         if ((long)lParam==MCI_MODE_OPEN)
  489.         {
  490.           SetWindowText(Form1,"Opening");
  491.           break;
  492.         }
  493.         if ((long)lParam==MCI_MODE_RECORD)
  494.         {
  495.           SetWindowText(Form1,"Recording");
  496.           break;
  497.         }
  498.         if ((long)lParam==MCI_MODE_SEEK)
  499.         {
  500.           SetWindowText(Form1,"Seeking");
  501.         }
  502.         break;
  503.       }
  504.       break;
  505.     }
  506.     if (Msg==MCIWNDM_NOTIFYMEDIA)
  507.     {
  508.       SetWindowText(Form1,(LPSTR)lParam);
  509.       break;
  510.     }
  511.     if (Msg==MCIWNDM_NOTIFYPOS)
  512.     {
  513.       SetWindowText(Form1,str(MCIWndGetPosition(MCIFrame)));
  514.       break;
  515.     }
  516.     if (Msg==MCIWNDM_NOTIFYERROR)
  517.     {
  518.       SetWindowText(Form1,"MCI ERROR");
  519.       break;
  520.     }
  521.     if (Msg==WM_PAINT)
  522.     {
  523.       //  The VideoWindow is restricted to a ratio of 4:3 here 
  524.       break;
  525.     }
  526.     if (Msg==WM_SIZE)
  527.     {
  528.       static  WORD  Basedsp;
  529.       memset(&Basedsp,0,sizeof(Basedsp));
  530.       static  WORD  Cntr;
  531.       memset(&Cntr,0,sizeof(Cntr));
  532.       Basedsp=(HIWORD(lParam)-20)/3;
  533.       Cntr=(LOWORD(lParam)-(Basedsp*4))/2;
  534.       // MoveWindow(MCIFrame,Cntr,0,(Basedsp*4),HIWORD(lParam),TRUE);
  535.       //  Don't forget to close opened Files 
  536.       break;
  537.     }
  538.     if (Msg==WM_CLOSE)
  539.     {
  540.       MCIWndClose(MCIFrame);
  541.       DestroyWindow(Form1);
  542.       return 0;
  543.       break;
  544.     }
  545.     if (Msg==WM_DESTROY)
  546.     {
  547.       MCIWndClose(MCIFrame);
  548.       PostQuitMessage(0);
  549.       return 0;
  550.     }
  551.     break;
  552.   }
  553.   // tidy up and exit program
  554.   if (Msg==WM_DESTROY)
  555.   {
  556.        UnregisterClass(BCX_ClassName,BCX_hInstance);
  557.        PostQuitMessage(0);
  558.   }
  559.   return DefWindowProc(hWnd,Msg,wParam,lParam);
  560. }
  561.  
  562.  
  563. // tons of options for the neat file dialog box
  564. int InitOpenFileName (void)
  565. {
  566.   *szFile=0;
  567.   *szFileTitle=0;
  568.   OpenFileName.lStructSize=sizeof(OPENFILENAME);
  569.   OpenFileName.hwndOwner=MCIFrame;
  570.   OpenFileName.hInstance=(HINSTANCE)ghInst;
  571.   OpenFileName.lpstrFilter =
  572.     "Avi Files (*.AVI)\0*.avi\0All Files(*.*)\0*.*\0\0";
  573.   OpenFileName.lpstrCustomFilter=NULL;
  574.   OpenFileName.nMaxCustFilter=0;
  575.   OpenFileName.nFilterIndex=0;
  576.   OpenFileName.lpstrFile=szFile;
  577.   OpenFileName.nMaxFile=MAX_PATH;
  578.   OpenFileName.lpstrFileTitle=szFileTitle;
  579.   OpenFileName.nMaxFileTitle=MAX_PATH;
  580.   OpenFileName.lpstrInitialDir=curdir();
  581.   OpenFileName.lpstrTitle=NULL;
  582.   OpenFileName.nFileOffset=0;
  583.   OpenFileName.nFileExtension=0;
  584.   OpenFileName.lpstrDefExt="*.avi";
  585.   OpenFileName.lCustData=0L;
  586.   OpenFileName.Flags=OFN_SHOWHELP|OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST|OFN_HIDEREADONLY;
  587.   OpenFileName.lpfnHook=NULL;
  588.   OpenFileName.lpTemplateName=NULL;
  589.   return 0;
  590. }
  591.  
  592. int PopFileOpenDlg (HWND Form1, char *szFile, char *szFileTitle)
  593. {
  594.   OpenFileName.lpstrTitle="Open File";
  595.   OpenFileName.hwndOwner=MCIFrame;
  596.   OpenFileName.lpstrFile=szFile;
  597.   OpenFileName.lpstrFileTitle=szFileTitle;
  598.   OpenFileName.Flags=OFN_EXPLORER|OFN_CREATEPROMPT;
  599.   return GetOpenFileNamePreview(&OpenFileName);
  600. }
  601.  
  602.  
  603. BOOL AddMenu (HWND hwndOwner)
  604. {
  605.   MainMenu=CreateMenu();
  606.   FileMenu=CreateMenu();
  607.   InsertMenu(MainMenu,0,MF_POPUP,(UINT)FileMenu,"&File");
  608.   AppendMenu(FileMenu,MF_STRING,ID_MENU2,"&Open");
  609.   AppendMenu(FileMenu,MF_STRING,ID_MENU3,"&Exit");
  610. //  AppendMenu(FileMenu,MF_STRING,ID_MENU4,"&Save bmp");
  611. //  AppendMenu(FileMenu,MF_STRING,ID_MENU5,"&Save capture");
  612.   // activate the menu 
  613.   if (!SetMenu(hwndOwner,MainMenu))
  614.   {
  615.       return FALSE;
  616.   }
  617.   return TRUE;
  618. }
  619.  
Just some clarification...

The first issue I noticed is related to the size of the new edited avi saved, that is too big as compared to the original one. I assume that is due to some wrong settings in my code. But also anything else about performance and quality is welcome! :-)

A second question I would ask is about overlapping an image on the bitmaps of the api. In my code the avi is played and recaptured one bitmap at a time. I wonder whether you could directly overlap an image on the bitmaps without playing/recapturing.

Eventually a third point could be the use of better library than shlwapi.lib or different avi_utils...
Newbie
 
Join Date: Sep 2009
Posts: 2
#2: Sep 28 '09

re: video edit in c++


Quote:

Originally Posted by giulio8 View Post

Hello,

Just some clarification...

The first issue I noticed is related to the size of the new edited avi saved, that is too big as compared to the original one. I assume that is due to some wrong settings in my code. But also anything else about performance and quality is welcome! :-)

A second question I would ask is about overlapping an image on the bitmaps. In my code the avi is played and recaptured one bitmap at a time. I wonder whether you could directly overlap an image on the bitmaps without playing/recapturing.

Eventually a third point could be the use of better library than shlwapi.lib or different avi_utils...

Ok, I think I have to use:

Expand|Select|Wrap|Line Numbers
  1. graphic = Graphics.FromImage(bitmap);
  2. ...
  3. graphic.DrawLine... etc. 
Reply

Tags
avi bitmap c++ video edit