|
Hi,
The follow are some my codes. I finished to write a Avis and wav(write by other thread) then continue to add the wav to Avis file existing.
Please help me for some suggestions and code example.
With the follow code it can write but I can't play final avi file with Window Media, Real Player, it seem to wrong codecs or format
I have used the compression codecs option as MSVC(Mircorsoft Video Codecs 1)
Please help me again.
//Add Frame code
bool CAVIUtil::AppendFrameUsual(HBITMAP hBitmap)
{
BITMAPINFO bmpInfo;
bmpInfo.bmiHeader.biBitCount = 0;
bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
GetDIBits(m_hAviDC, hBitmap, 0, 0, NULL, &bmpInfo, DIB_RGB_COLORS);
bmpInfo.bmiHeader.biCompression = BI_RGB;
GetDIBits(m_hAviDC, hBitmap, 0, bmpInfo.bmiHeader.biHeight, m_lpBits, &bmpInfo, DIB_RGB_COLORS);
if (FAILED(AVIStreamWrite(m_pAviCompressedStream, m_lSample++, 1, m_lpBits, bmpInfo.bmiHeader.biSizeImage, 0, NULL, NULL)))
{
strcpy(m_szErrorMessage, "AppendFrameUsual(): AVIStreamWrite failed");
return (false);
}
return (true);
}
//Add wav to avi
HRESULT CAVIUtil::AddAviWav(const char *src)
{
char *buf=0; WavChunk *wav = (WavChunk*)src;
HANDLE hf=CreateFile(src,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,0,NULL);
if (hf==INVALID_HANDLE_VALUE) {
MessageBox(NULL,"AVIERR_FILEOPEN","ERROR",MB_OK);
return AVIERR_FILEOPEN;
}
DWORD size = GetFileSize(hf,NULL);
buf = new char[size];
DWORD red; ReadFile(hf,buf,size,&red,NULL);
CloseHandle(hf);
wav = (WavChunk*)buf;
// check that format doesn't clash
bool badformat=false;
if (m_wfx.nChannels==0)
{ m_wfx.wFormatTag=wav->fmt.wFormatTag;
m_wfx.cbSize=0;
m_wfx.nAvgBytesPerSec=wav->fmt.dwAvgBytesPerSec;
m_wfx.nBlockAlign=wav->fmt.wBlockAlign;
m_wfx.nChannels=wav->fmt.wChannels;
m_wfx.nSamplesPerSec=wav->fmt.dwSamplesPerSec;
m_wfx.wBitsPerSample=wav->fmt.wBitsPerSample;
}
else
{
if (m_wfx.wFormatTag!=wav->fmt.wFormatTag) badformat=true;
if (m_wfx.nAvgBytesPerSec!=wav->fmt.dwAvgBytesPerSec) badformat=true;
if (m_wfx.nBlockAlign!=wav->fmt.wBlockAlign) badformat=true;
if (m_wfx.nChannels!=wav->fmt.wChannels) badformat=true;
if (m_wfx.nSamplesPerSec!=wav->fmt.dwSamplesPerSec) badformat=true;
if (m_wfx.wBitsPerSample!=wav->fmt.wBitsPerSample) badformat=true;
}
if (badformat) {if (buf!=0) delete[] buf;
MessageBox(NULL,"AVIERR_BADFORMAT","ERROR",MB_OK);
return AVIERR_BADFORMAT;
}
//
// create the stream if necessary
if(m_pAudioStream==0){
AVISTREAMINFO ahdr; ZeroMemory(&ahdr,sizeof(ahdr));
ahdr.fccType=streamtypeAUDIO;
ahdr.dwScale=m_wfx.nBlockAlign;
ahdr.dwRate=m_wfx.nSamplesPerSec*m_wfx.nBlockAlign;
ahdr.dwSampleSize=m_wfx.nBlockAlign;
ahdr.dwQuality=(DWORD)-1;
HRESULT hr = AVIFileCreateStream(m_pAviFile,&m_pAudioStream, &ahdr);
if (hr!=AVIERR_OK) {if (buf!=0) delete[] buf; return hr;}
hr = AVIStreamSetFormat(m_pAudioStream,0,&m_wfx,sizeof(WAVEFORMATEX));
if (hr!=AVIERR_OK) {if (buf!=0) delete[] buf;return hr;}
}
// now we can write the data
unsigned long numbytes = wav->dat.size;
unsigned long numsamps = numbytes*8 / m_wfx.wBitsPerSample;
HRESULT hr = AVIStreamWrite(m_pAudioStream,m_lAudioSample,numsamps,wav->dat.data,numbytes,0,NULL,NULL);
if (buf!=0) delete[] buf;
if (hr!=AVIERR_OK) {
MessageBox(NULL,"AVIERR_OK","ERROR",MB_OK);
return hr;
}
m_lAudioSample+=numsamps;
MessageBox(NULL,"AVIS_OK","S_OK",MB_OK);
return S_OK;
}
|
|
|
|
|
I need to write the sepatared file in some case and need to merge these to a avi file if needed.
So, Please help me with this route.
Thank again
Tri
|
|
|
|
|
Please modify your post - I can't read the code easily. Select the code and click on the Formatting: pre label below the text entry box - this tells CodeProject to keep formatting as you had it in the code.
It is always useful to do Preview before you Post message.
I will find my code and try to make a short extract, then post that. The details look similar so it may be useful.
|
|
|
|
|
Yah,
Sorry for make difficulty to read,
Please help me with some your code
Thanks!
|
|
|
|
|
I have not checked in detail, but I noticed a difference in dwRate setting - I use the samplesPerSecond value, while you use samplesPerSecond * sampleSize. This will be a problem if you are not using 8-bit samples.
Error checking (using uiResult) removed to save space
Lots of other details removed as well
void SaveAVIFileWithAudio(void)
{
PAVIFILE pAVIFile = NULL;
AVISTREAMINFO VideoStreamInfo;
AVISTREAMINFO AudioStreamInfo;
PAVISTREAM pAVIVideoStream = NULL;
PAVISTREAM pCompressedVideoStream = NULL;
PAVISTREAM pAVIAudioStream = NULL;
AVICOMPRESSOPTIONS CompressionOptions;
AVIFileInit();
GetSaveFileName(&AVIFileNameEtc);
uiResult = AVIFileOpen(&pAVIFile,
AVIFileNameEtc.lpstrFile,
OF_WRITE | OF_CREATE,
NULL);
memset(&VideoStreamInfo, 0, sizeof(VideoStreamInfo));
memset(&AudioStreamInfo, 0, sizeof(AudioStreamInfo));
VideoStreamInfo.fccType = streamtypeVIDEO;
VideoStreamInfo.fccHandler = mmioFOURCC('m','p','4','2');
uiResult = AVIFileCreateStream(pAVIFile,
&pAVIVideoStream,
&VideoStreamInfo);
memset(&CompressionOptions, 0, sizeof(CompressionOptions));
CompressionOptions.fccType = streamtypeVIDEO;
CompressionOptions.fccHandler = VideoStreamInfo.fccHandler;
uiResult = AVIMakeCompressedStream(&pCompressedVideoStream,
pAVIVideoStream, &CompressionOptions, NULL);
uiResult = AVIStreamSetFormat(pCompressedVideoStream, 0,
&bitmapForAVIHeader,
bitmapForAVIHeader.biSize);
AudioStreamInfo.fccType = streamtypeAUDIO;
AudioStreamInfo.dwScale = 1;
AudioStreamInfo.dwQuality = -1;
AudioStreamInfo.dwRate = 11025;
AudioStreamInfo.dwStart = 0;
AudioStreamInfo.dwLength = uiLocalNumFramesUsed *
uiAudioBufferActualSize;
AudioStreamInfo.dwSuggestedBufferSize = uiAudioBufferActualSize;
AudioStreamInfo.dwSampleSize = 2;
uiResult = AVIFileCreateStream(pAVIFile,
&pAVIAudioStream,
&AudioStreamInfo);
uiResult = AVIStreamSetFormat(pAVIAudioStream, 0,
&AudioFormat,
sizeof(AudioFormat));
for (uiCounter = 0; uiCounter < uiLocalNumFramesUsed; uiCounter++)
{
uiResult = AVIStreamWrite(pCompressedVideoStream,
uiCounter,
1,
gpAVIBufBits,
bitmapForAVIHeader.biSizeImage,
0, NULL, NULL);
uiResult = AVIStreamWrite(pAVIAudioStream,
uiCounter,
1,
pAudioDataBlock[uiLocalIndex],
uiAudioBufferActualSize,
0, NULL, NULL);
}
AVIStreamRelease(pCompressedVideoStream);
AVIStreamRelease(pAVIVideoStream);
AVIStreamRelease(pAVIAudioStream);
AVIFileRelease(pAVIFile);
AVIFileExit();
};
|
|
|
|
|
Many thank to normanS,
But I need merge the wav and avis together, because I have recorded as two separate file by two record threading, so with your code I can not add to my code for merge now.
Do you have any suggetsion or help again?
Tx,
Tri
|
|
|
|
|
Where exactly is the problem?
As far as I could tell, the code I posted was similar to what you used (same APIs, etc), so it should be possible for you to use my code (parameters used in the audio header, sequence of calling AVI functions etc) to give ideas of what to try in your code. The source of the data (you are reading from AVI and WAV files, I am getting it from audio and video buffers in memory) should not make a difference.
One thought I had - are you creating the AVI with video only, and the WAV with audio only, then trying to add the audio to the end of the video-only AVI? If so, this is not recommended - it may work (maybe only in some AVI players?), but performance could be really bad, since AVIs are designed to alternate between chunks of audio and chunks of video.
A better approach if you have video.avi and audio.wav would be to read a frame of video from video.avi, a block of audio the same length as the video frame (33.333 or 40 milliseconds) from audio.wav, then write this information to a new mixedAudioVideo.avi. Repeat until finished.
What error message are you getting when you try to play the AVI you create? Maybe that can give a tip of what is going wrong.
|
|
|
|
|
Hi All,
Could any one please provide me with the sample or example code for updating the data of XML files to MS Access database tables.?, Actually i need to make a vc++ dll which can read all xml files in a particular directory and update the data to coresponding table in MS Access database..Thanks in Advance.!
Regards,
princenrj23
____________
|
|
|
|
|
Use MSXML to read or parse data from the XML file .
CDatabase etc can be used to read and modify the Access files
So after reading data from the XML write it to Access Files
Or you can also use
IXMLDocument otherwise.
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
dude even am aware that i have to use XMLParser to read the XML file and then have to map the tags to the table of MS Access database using ADO, but as i am newbee to vc++ and xml so i was looking for an example code or a tutorial which could help me getting started??? Thanks anyway for the help!
|
|
|
|
|
Dude what i am confused with is, how to open all xml files one by one from a single directory, parse the file and how do i know which element is to be updated to which column of which table(MS-Access Database)??, i am newbee to xml and vc++???, what is surprising to me is that there is no single tutorial or example code for this on internet?? dude if you have done such a programming in past plz post something useful?. It will be a great help...Thanks in Advance!!
|
|
|
|
|
May be this code can help you. You can get all the filenames that reside in a single directory. Now once you have the file names you can read the file parse it and use the data
WIN32_FIND_DATA FindFileData; <br />
HANDLE hHandle; <br />
<br />
int complt=1; <br />
char FileName[100]; <br />
strcpy(FileName,""); <br />
char rpath[]="abc"; <br />
char Path[]="abc"; <br />
SetCurrentDirectory(Path); <br />
hHandle=FindFirstFile("*.*",&FindFileData); <br />
<br />
if(hHandle == INVALID_HANDLE_VALUE) <br />
MessageBox("The Path Could Not Be Found."); <br />
else <br />
{ <br />
while(complt) <br />
{ <br />
strcpy(FileName,Path); <br />
strcat(FileName,FindFileData.cFileName); <br />
CString s=FindFileData .cFileName;<br />
if(s.Find ("txt"))<br />
{<br />
}<br />
complt=FindNextFile(hHandle,&FindFileData); <br />
} <br />
} <br />
FindClose(hHandle); <br />
as far as your specific requirement is concerned it would be hard to tell what you actually want to do and the logic behind that.
To update the table accordingly you will have to search for the CDatabase class and use its functions. This class will be derived from CRecordSet. Check out MSDN for details.
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
Thanks Anshuman for the speedy response dude, my major concern is how to use MSXML parser and when & where to use ADO??.... do i need to have xml schema or a database schema?? to do the mapping of xml tags to MS Access table columns, or by simply opening each file traversing through it's nodes and looking for corresponding table in the database and updating it will do the job??
|
|
|
|
|
if you have small amount of data you can go for the second option.
Read articles on MSXML for this.
For large and huge data you would need a different approach. Can't help you on this man.
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
is there anyone who could help me with this?
|
|
|
|
|
I want to create a transparent RichEdit control, and find many example use follow code in parent dialog class:
HBRUSH CParentDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if((nCtlColor == CTLCOLOR_EDIT) && (pWnd->GetDlgCtrlID()==IDC_MYRICHEDIT))
{
pDC->SetBkMode(TRANSPARENT);
pDC->SetTextColor(RGB(255,0,0));
return HBRUSH(GetStockObject(HOLLOW_BRUSH));
}
}
It does not work in my application. I think maybe because which I create is CRichEditCtrl while those example create CEdit, or maybe because my parent window is CWnd class while those example use CDialog class.
Anyone can tell me what the problem is, and how to fix it? help me create a transparent RichEdit control successfully, thanks a lot.
|
|
|
|
|
Hi,
Have u called AfxInitRichEdit in InitInstance of your application ??
Appu..
"If you judge people, you have no time to love them."
|
|
|
|
|
Yes, I called the function in InitInstance().
|
|
|
|
|
Hi everyone,
Can anyone tell me how to create a window that sits behind the icons on a desktop, and replaces the current background.
Examples of this feature already being implemented are:
- Nvidia - video on desktop
- My Movie Desktop
What I'd like is that:
(1) My window should sit behind all other windows; and
(2) If possible, sit behind the icons on the desktop, replacing or sitting on top of the current windows background.
A snipet of c++/c# code would be great
Regards,
Glenn
|
|
|
|
|
I have an existing Dialog-based application which currently calls ::WinHelp(...); for all help. I would like to upgrade this app so that it uses HTML Help instead. I read that I have to set the help mode to HTML (call EnableHtmlHelp() in the app's constructor. Unfortunately, I cant seem to get this to work. When I try to compile, I get an error indicating that the function EnableHtmlHelp() is undefined. I cant find any info as to what, if any, headers are missing or library references. Any help would be appreciated.
Thanks.
LA
|
|
|
|
|
|
Here is some help from _Russel_.
Add the macros
ON_COMMAND(ID_HELP_FINDER, CMDIFrameWnd::OnHelpFinder)<br />
ON_COMMAND(ID_DEFAULT_HELP, CMDIFrameWnd::OnHelpFinder)<br />
ON_COMMAND(ID_HELP, CMDIFrameWnd::OnHelp)<br />
ON_COMMAND(ID_CONTEXT_HELP, CMDIFrameWnd::OnContextHelp) to the Mainframe map
And add to the constructor of the application
EnableHtmlHelp();
Then put the help file in the exe folder.
Appu..
"If you judge people, you have no time to love them."
|
|
|
|
|
hi all!
i have create a CTreeCtrl and set an images -brought from CImageList- to it's itemes (each item has it's different icon). but i can't set an image to the sub itemes (all sub itemes have the same image that index 0 in the ImageList, and i can't specify an icon to sub item.
Who may tell me please how to set an image to the tree sub item?
That's that.
|
|
|
|
|
Hi,
The follow link maybe have some help for you.
http://www.codeproject.com/treectrl/DeviceTree.asp
|
|
|
|
|
|