41 |
|
|
42 |
#define APP_NAME TEXT("Xvid MiniConvert") |
#define APP_NAME TEXT("Xvid MiniConvert") |
43 |
|
|
44 |
#define Pass_FILE "xvid_2pass.stats" |
#define Pass_FILE_A "xvid_2pass.stats" |
45 |
#define Pass_FILE_W L"xvid_2pass.stats" |
#define Pass_FILE TEXT("xvid_2pass.stats") |
46 |
|
|
47 |
// Todo: Avoid global vars... |
// Todo: Avoid global vars... |
48 |
OPENFILENAME sOfn, sSfn; |
OPENFILENAME sOfn, sSfn; |
121 |
|
|
122 |
const size_t STRING_LENGTH = 256; |
const size_t STRING_LENGTH = 256; |
123 |
WCHAR wsz[STRING_LENGTH]; |
WCHAR wsz[STRING_LENGTH]; |
124 |
swprintf(wsz, STRING_LENGTH, TEXT("FilterGraph %08x pid %08x"), |
swprintf(wsz, STRING_LENGTH, L"FilterGraph %08x pid %08x", |
125 |
(DWORD_PTR)pUnkGraph, GetCurrentProcessId()); |
(DWORD_PTR)pUnkGraph, GetCurrentProcessId()); |
126 |
|
|
127 |
HRESULT hr = CreateItemMoniker(TEXT("!"), wsz, &pMoniker); |
HRESULT hr = CreateItemMoniker(L"!", wsz, &pMoniker); |
128 |
if (SUCCEEDED(hr)) { |
if (SUCCEEDED(hr)) { |
129 |
hr = pROT->Register(ROTFLAGS_REGISTRATIONKEEPSALIVE, pUnkGraph, |
hr = pROT->Register(ROTFLAGS_REGISTRATIONKEEPSALIVE, pUnkGraph, |
130 |
pMoniker, pdwRegister); |
pMoniker, pdwRegister); |
357 |
if (hr == S_OK) pVidMeter = CProgressNotifyFilter::CreateInstance(0, &hr, 0); |
if (hr == S_OK) pVidMeter = CProgressNotifyFilter::CreateInstance(0, &hr, 0); |
358 |
if (hr == S_OK) hr = pVidMeter->NonDelegatingQueryInterface(IID_IBaseFilter, (void **)&m_pVideoMeter); |
if (hr == S_OK) hr = pVidMeter->NonDelegatingQueryInterface(IID_IBaseFilter, (void **)&m_pVideoMeter); |
359 |
//hr = CoCreateInstance(CLSID_ProgressNotifyFilter, 0, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void **)&m_pVideoMeter); |
//hr = CoCreateInstance(CLSID_ProgressNotifyFilter, 0, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void **)&m_pVideoMeter); |
360 |
if (hr == S_OK) hr = m_pGraph->AddFilter(m_pVideoMeter, TEXT("Video meter")); |
if (hr == S_OK) hr = m_pGraph->AddFilter(m_pVideoMeter, L"Video meter"); |
361 |
if (hr == S_OK) hr = GetFilterPin(m_pVideoMeter, PINDIR_INPUT, 0, &pVMeterInVideoPin, GUID_NULL, GUID_NULL); |
if (hr == S_OK) hr = GetFilterPin(m_pVideoMeter, PINDIR_INPUT, 0, &pVMeterInVideoPin, GUID_NULL, GUID_NULL); |
362 |
|
|
363 |
if (pOutVideoPin) { |
if (pOutVideoPin) { |
427 |
m_bFileCopy = 0; |
m_bFileCopy = 0; |
428 |
|
|
429 |
if (hr == S_OK) hr = AddDirectXFilterByMoniker(CLSID_VideoCompressorCategory, "xvid", &m_pXvidEncoder, 1); |
if (hr == S_OK) hr = AddDirectXFilterByMoniker(CLSID_VideoCompressorCategory, "xvid", &m_pXvidEncoder, 1); |
430 |
if (hr == S_OK) hr = m_pGraph->AddFilter(m_pXvidEncoder, TEXT("Encoder")); |
if (hr == S_OK) hr = m_pGraph->AddFilter(m_pXvidEncoder, L"Encoder"); |
431 |
|
|
432 |
if (hr == S_OK) hr = ConnectFilters(m_pGraph, pOutVideoPin, m_pXvidEncoder, GUID_NULL, GUID_NULL, 0); |
if (hr == S_OK) hr = ConnectFilters(m_pGraph, pOutVideoPin, m_pXvidEncoder, GUID_NULL, GUID_NULL, 0); |
433 |
if (hr == S_OK) pCompressedVideoFilter = m_pXvidEncoder; |
if (hr == S_OK) pCompressedVideoFilter = m_pXvidEncoder; |
512 |
#endif |
#endif |
513 |
} |
} |
514 |
|
|
515 |
strcpy(m_pXvidCfgRec->stats, Pass_FILE); |
strcpy(m_pXvidCfgRec->stats, Pass_FILE_A); |
516 |
|
|
517 |
m_pXvidCfgRec->display_status = 0; |
m_pXvidCfgRec->display_status = 0; |
518 |
|
|
524 |
|
|
525 |
CUnknown *pChgUnk = ChangeSubtypeT::CreateInstance(0, &hr); |
CUnknown *pChgUnk = ChangeSubtypeT::CreateInstance(0, &hr); |
526 |
if (hr == S_OK) hr = pChgUnk->NonDelegatingQueryInterface(IID_IBaseFilter, (void **)&m_pChgType); |
if (hr == S_OK) hr = pChgUnk->NonDelegatingQueryInterface(IID_IBaseFilter, (void **)&m_pChgType); |
527 |
if (hr == S_OK) hr = m_pGraph->AddFilter(m_pChgType, TEXT("ChgToxvid")); |
if (hr == S_OK) hr = m_pGraph->AddFilter(m_pChgType, L"ChgToxvid"); |
528 |
if (hr == S_OK) hr = ConnectFilters(m_pGraph, pCompressedVideoFilter, m_pChgType, GUID_NULL, GUID_NULL, 1); |
if (hr == S_OK) hr = ConnectFilters(m_pGraph, pCompressedVideoFilter, m_pChgType, GUID_NULL, GUID_NULL, 1); |
529 |
|
|
530 |
if (hr == S_OK) hr = AddFilterByCLSID((GUID *)&CLSID_AviDest, &m_pMuxer); |
if (hr == S_OK) hr = AddFilterByCLSID((GUID *)&CLSID_AviDest, &m_pMuxer); |
565 |
|
|
566 |
if (hr == S_OK && in_Pass != 2) { // Make progress bar visible |
if (hr == S_OK && in_Pass != 2) { // Make progress bar visible |
567 |
TCHAR buf[MAX_PATH+50], buf2[MAX_PATH]; |
TCHAR buf[MAX_PATH+50], buf2[MAX_PATH]; |
568 |
if (wcslen(m_szSourceFilePath) > 60) { |
if (_tcslen(m_szSourceFilePath) > 60) { |
569 |
PathCompactPathEx(buf2, m_szSourceFilePath, 60, 0); |
PathCompactPathEx(buf2, m_szSourceFilePath, 60, 0); |
570 |
swprintf(buf, MAX_PATH+50, TEXT("Converting %s"), buf2); |
_stprintf(buf, TEXT("Converting %s"), buf2); |
571 |
} |
} |
572 |
else |
else |
573 |
swprintf(buf, MAX_PATH+50, TEXT("Converting %s..."), m_szSourceFilePath); |
_stprintf(buf, TEXT("Converting %s..."), m_szSourceFilePath); |
574 |
|
|
575 |
ShowWindow(GetDlgItem(ghDlg, IDC_EDIT_SRC), SW_HIDE); |
ShowWindow(GetDlgItem(ghDlg, IDC_EDIT_SRC), SW_HIDE); |
576 |
ShowWindow(GetDlgItem(ghDlg, IDC_BUTTON_SRC), SW_HIDE); |
ShowWindow(GetDlgItem(ghDlg, IDC_BUTTON_SRC), SW_HIDE); |
600 |
bFraunhoferPro = 0; |
bFraunhoferPro = 0; |
601 |
else { |
else { |
602 |
// C:\WINDOWS\System32\l3codecp.acm was not recognized |
// C:\WINDOWS\System32\l3codecp.acm was not recognized |
603 |
int sLen = wcslen(kvalue); |
int sLen = _tcslen(kvalue); |
604 |
if ((sLen >= 12) && (wcscmp(&(kvalue[sLen - 12]), TEXT("l3codecp.acm")) == 0)) |
if ((sLen >= 12) && (_tcscmp(&(kvalue[sLen - 12]), TEXT("l3codecp.acm")) == 0)) |
605 |
bFraunhoferPro = 1; |
bFraunhoferPro = 1; |
606 |
} |
} |
607 |
|
|
762 |
if (m_szDstFilePath) |
if (m_szDstFilePath) |
763 |
free (m_szDstFilePath); |
free (m_szDstFilePath); |
764 |
|
|
765 |
m_szDstFilePath = _wcsdup(in_szFilePath); |
m_szDstFilePath = _tcsdup(in_szFilePath); |
766 |
|
|
767 |
return S_OK; |
return S_OK; |
768 |
} |
} |
773 |
if (!m_pGraph || m_pFileWriter) |
if (!m_pGraph || m_pFileWriter) |
774 |
return E_UNEXPECTED; |
return E_UNEXPECTED; |
775 |
|
|
776 |
|
int sLen = _tcslen(in_szFilePath); |
777 |
|
OLECHAR *pwName = new OLECHAR [sLen+1]; |
778 |
|
#ifndef UNICODE |
779 |
|
mbstowcs(pwName, in_szFilePath, sLen+1); |
780 |
|
#else |
781 |
|
wcsncpy(pwName, in_szFilePath, sLen+1); |
782 |
|
#endif |
783 |
|
|
784 |
HRESULT hr = AddFilterByCLSID((GUID *)&CLSID_FileWriter, &m_pFileWriter); |
HRESULT hr = AddFilterByCLSID((GUID *)&CLSID_FileWriter, &m_pFileWriter); |
785 |
IFileSinkFilter* pDst=0; |
IFileSinkFilter* pDst=0; |
786 |
if (hr == S_OK) hr = m_pFileWriter->QueryInterface(IID_IFileSinkFilter, (void **)(&pDst)); |
if (hr == S_OK) hr = m_pFileWriter->QueryInterface(IID_IFileSinkFilter, (void **)(&pDst)); |
787 |
if (hr == S_OK) hr = pDst->SetFileName(in_szFilePath, &m_DstFileMediaType); |
if (hr == S_OK) hr = pDst->SetFileName(pwName, &m_DstFileMediaType); |
788 |
|
delete [] pwName; |
789 |
if (pDst) |
if (pDst) |
790 |
pDst->Release(); |
pDst->Release(); |
791 |
|
|
800 |
if (m_szSourceFilePath) |
if (m_szSourceFilePath) |
801 |
free (m_szSourceFilePath); |
free (m_szSourceFilePath); |
802 |
|
|
803 |
m_szSourceFilePath = _wcsdup(in_szFilePath); |
m_szSourceFilePath = _tcsdup(in_szFilePath); |
804 |
|
|
805 |
return S_OK; |
return S_OK; |
806 |
} |
} |
810 |
{ |
{ |
811 |
if (!m_pGraph || m_pSrcFilter) return E_UNEXPECTED; |
if (!m_pGraph || m_pSrcFilter) return E_UNEXPECTED; |
812 |
|
|
813 |
HRESULT hr = m_pGraph->AddSourceFilter(in_szFilePath, TEXT("Source filter"), &m_pSrcFilter); |
int sLen = _tcslen(in_szFilePath); |
814 |
|
OLECHAR *pwName = new OLECHAR [sLen+1]; |
815 |
|
#ifndef UNICODE |
816 |
|
mbstowcs(pwName, in_szFilePath, sLen+1); |
817 |
|
#else |
818 |
|
wcsncpy(pwName, in_szFilePath, sLen+1); |
819 |
|
#endif |
820 |
|
|
821 |
|
HRESULT hr = m_pGraph->AddSourceFilter(pwName, L"Source filter", &m_pSrcFilter); |
822 |
|
|
823 |
#if 0 |
#if 0 |
824 |
HRESULT hr = AddFilterByCLSID((GUID *)&CLSID_AsyncReader, &this->m_pSrcFilter); |
HRESULT hr = AddFilterByCLSID((GUID *)&CLSID_AsyncReader, &this->m_pSrcFilter); |
828 |
if (pSrc) pSrc->Release(); |
if (pSrc) pSrc->Release(); |
829 |
#endif |
#endif |
830 |
|
|
831 |
|
delete [] pwName; |
832 |
|
|
833 |
return hr; |
return hr; |
834 |
} |
} |
835 |
|
|
917 |
pBitrateProgressNotify->GetBitrate(m_CountedFrames, m_TotalFramesSize); |
pBitrateProgressNotify->GetBitrate(m_CountedFrames, m_TotalFramesSize); |
918 |
pBitrateProgressNotify->Release(); |
pBitrateProgressNotify->Release(); |
919 |
pBitrateProgressNotify = 0; |
pBitrateProgressNotify = 0; |
920 |
TCHAR *pSrcStr = _wcsdup(m_szSourceFilePath); |
TCHAR *pSrcStr = _tcsdup(m_szSourceFilePath); |
921 |
TCHAR *pDstStr = _wcsdup(m_szDstFilePath); |
TCHAR *pDstStr = _tcsdup(m_szDstFilePath); |
922 |
|
|
923 |
pControl->Release(); |
pControl->Release(); |
924 |
pEvent->Release(); |
pEvent->Release(); |
932 |
|
|
933 |
if (bBreakRequested || hr != S_OK) { |
if (bBreakRequested || hr != S_OK) { |
934 |
DeleteFile(m_szDstFilePath); |
DeleteFile(m_szDstFilePath); |
935 |
DeleteFile(Pass_FILE_W); |
DeleteFile(Pass_FILE); |
936 |
hr = E_FAIL; |
hr = E_FAIL; |
937 |
goto finish_recompress; |
goto finish_recompress; |
938 |
} |
} |
992 |
if (pEvent) pEvent->Release(); |
if (pEvent) pEvent->Release(); |
993 |
if (pBitrateProgressNotify) pBitrateProgressNotify->Release(); |
if (pBitrateProgressNotify) pBitrateProgressNotify->Release(); |
994 |
|
|
995 |
DeleteFile(Pass_FILE_W); |
DeleteFile(Pass_FILE); |
996 |
|
|
997 |
finish_recompress: |
finish_recompress: |
998 |
|
|
1059 |
TCHAR *NextFileName = SrcFile; |
TCHAR *NextFileName = SrcFile; |
1060 |
TCHAR tempFile[2*MAX_PATH]; |
TCHAR tempFile[2*MAX_PATH]; |
1061 |
|
|
1062 |
if(SrcFile[wcslen(SrcFile) + 1] != TEXT('\0')) // Multiple input files? |
if(SrcFile[_tcslen(SrcFile) + 1] != TEXT('\0')) // Multiple input files? |
1063 |
{ |
{ |
1064 |
nbInputFiles = 0; |
nbInputFiles = 0; |
1065 |
NextFileName = &NextFileName[wcslen(NextFileName) + 1]; |
NextFileName = &NextFileName[_tcslen(NextFileName) + 1]; |
1066 |
|
|
1067 |
while(NextFileName[0] != L'\0') // Count total filesize and number of source files |
while(NextFileName[0] != L'\0') // Count total filesize and number of source files |
1068 |
{ |
{ |
1071 |
DetermineFileSize(tempFile, &filesize); |
DetermineFileSize(tempFile, &filesize); |
1072 |
totalSize += filesize; |
totalSize += filesize; |
1073 |
|
|
1074 |
NextFileName = &NextFileName[wcslen(NextFileName) + 1]; |
NextFileName = &NextFileName[_tcslen(NextFileName) + 1]; |
1075 |
nbInputFiles++; |
nbInputFiles++; |
1076 |
} |
} |
1077 |
} |
} |
1078 |
|
|
1079 |
NextFileName = SrcFile; |
NextFileName = SrcFile; |
1080 |
if (nbInputFiles > 1) { |
if (nbInputFiles > 1) { |
1081 |
NextFileName = &NextFileName[wcslen(NextFileName) + 1]; // Bypass dir and jump to first filename |
NextFileName = &NextFileName[_tcslen(NextFileName) + 1]; // Bypass dir and jump to first filename |
1082 |
} |
} |
1083 |
|
|
1084 |
HRESULT hr = S_OK; |
HRESULT hr = S_OK; |
1090 |
count++; |
count++; |
1091 |
|
|
1092 |
if (nbInputFiles == 1) { |
if (nbInputFiles == 1) { |
1093 |
wcscpy(tempFile, SrcFile); // Src |
_tcscpy(tempFile, SrcFile); // Src |
1094 |
|
|
1095 |
PathStripPath(SrcFile); |
PathStripPath(SrcFile); |
1096 |
|
|
1097 |
LPWSTR ext = PathFindExtension(SrcFile); |
LPTSTR ext = PathFindExtension(SrcFile); |
1098 |
TCHAR sztmpPath[2*MAX_PATH]; |
TCHAR sztmpPath[2*MAX_PATH]; |
1099 |
wcsncpy(sztmpPath, SrcFile, (ext-SrcFile)); |
_tcsncpy(sztmpPath, SrcFile, (ext-SrcFile)); |
1100 |
sztmpPath[ext-SrcFile] = TEXT('\0'); |
sztmpPath[ext-SrcFile] = TEXT('\0'); |
1101 |
swprintf(sztmpPath, 2*MAX_PATH, TEXT("%s_Xvid.avi"), sztmpPath); |
_stprintf(sztmpPath, TEXT("%s_Xvid.avi"), sztmpPath); |
1102 |
|
|
1103 |
PathCombine(szDstPath, DstFile, sztmpPath); // Dst |
PathCombine(szDstPath, DstFile, sztmpPath); // Dst |
1104 |
} |
} |
1105 |
else { |
else { |
1106 |
PathCombine(tempFile, SrcFile, NextFileName); // Src |
PathCombine(tempFile, SrcFile, NextFileName); // Src |
1107 |
|
|
1108 |
LPWSTR ext = PathFindExtension(NextFileName); |
LPTSTR ext = PathFindExtension(NextFileName); |
1109 |
TCHAR sztmpPath[2*MAX_PATH]; |
TCHAR sztmpPath[2*MAX_PATH]; |
1110 |
wcsncpy(sztmpPath, NextFileName, (ext-NextFileName)); |
_tcsncpy(sztmpPath, NextFileName, (ext-NextFileName)); |
1111 |
sztmpPath[ext-NextFileName] = TEXT('\0'); |
sztmpPath[ext-NextFileName] = TEXT('\0'); |
1112 |
swprintf(sztmpPath, 2*MAX_PATH, TEXT("%s_Xvid.avi"), sztmpPath); |
_stprintf(sztmpPath, TEXT("%s_Xvid.avi"), sztmpPath); |
1113 |
|
|
1114 |
PathCombine(szDstPath, DstFile, sztmpPath); // Dst |
PathCombine(szDstPath, DstFile, sztmpPath); // Dst |
1115 |
|
|
1116 |
NextFileName = &NextFileName[wcslen(NextFileName) + 1]; |
NextFileName = &NextFileName[_tcslen(NextFileName) + 1]; |
1117 |
} |
} |
1118 |
|
|
1119 |
pRec->CleanUp(); |
pRec->CleanUp(); |
1293 |
|
|
1294 |
GetDlgItemText(hDlg, IDC_EDIT_SRC, OpenFilePath, sizeof(OpenFilePath)/sizeof(OpenFilePath)); |
GetDlgItemText(hDlg, IDC_EDIT_SRC, OpenFilePath, sizeof(OpenFilePath)/sizeof(OpenFilePath)); |
1295 |
|
|
1296 |
if (wcslen(sOfn.lpstrFile) == 0) { |
if (_tcslen(sOfn.lpstrFile) == 0) { |
1297 |
swprintf(sOfn.lpstrFile, 2*MAX_PATH, TEXT("%s"), OpenFilePath); |
_stprintf(sOfn.lpstrFile, TEXT("%s"), OpenFilePath); |
1298 |
} |
} |
1299 |
|
|
1300 |
if (GetOpenFileName(&sOfn)) { |
if (GetOpenFileName(&sOfn)) { |
1301 |
if(sOfn.lpstrFile[wcslen(sOfn.lpstrFile) + 1] != TEXT('\0')) // Multiple input files? |
if(sOfn.lpstrFile[_tcslen(sOfn.lpstrFile) + 1] != TEXT('\0')) // Multiple input files? |
1302 |
swprintf(OpenFilePath, 2*MAX_PATH, TEXT("%s (multiselect)"), sOfn.lpstrFile); |
_stprintf(OpenFilePath, TEXT("%s (multiselect)"), sOfn.lpstrFile); |
1303 |
else |
else |
1304 |
swprintf(OpenFilePath, 2*MAX_PATH, TEXT("%s"), sOfn.lpstrFile); |
_stprintf(OpenFilePath, TEXT("%s"), sOfn.lpstrFile); |
1305 |
|
|
1306 |
SetDlgItemText(hDlg, IDC_EDIT_SRC, OpenFilePath); |
SetDlgItemText(hDlg, IDC_EDIT_SRC, OpenFilePath); |
1307 |
} |
} |
1317 |
GetDlgItemText(hDlg, IDC_EDIT_DST, SaveFilePath, sizeof(SaveFilePath)/sizeof(SaveFilePath[0])); |
GetDlgItemText(hDlg, IDC_EDIT_DST, SaveFilePath, sizeof(SaveFilePath)/sizeof(SaveFilePath[0])); |
1318 |
GetDlgItemText(hDlg, IDC_EDIT_SRC, OpenFilePath, sizeof(OpenFilePath)/sizeof(OpenFilePath[0])); |
GetDlgItemText(hDlg, IDC_EDIT_SRC, OpenFilePath, sizeof(OpenFilePath)/sizeof(OpenFilePath[0])); |
1319 |
|
|
1320 |
if ((wcslen(OpenFilePath) > 0 || wcslen(sOfn.lpstrFile) > 0) && wcslen(SaveFilePath) > 0) { |
if ((_tcslen(OpenFilePath) > 0 || _tcslen(sOfn.lpstrFile) > 0) && _tcslen(SaveFilePath) > 0) { |
1321 |
EnableWindow(GetDlgItem(hDlg, IDC_BUTTON_START), 0); |
EnableWindow(GetDlgItem(hDlg, IDC_BUTTON_START), 0); |
1322 |
if (wcslen(sOfn.lpstrFile) > 0) |
if (_tcslen(sOfn.lpstrFile) > 0) |
1323 |
SrcFile = sOfn.lpstrFile; |
SrcFile = sOfn.lpstrFile; |
1324 |
else { |
else { |
1325 |
OpenFilePath[wcslen(OpenFilePath)+1] = TEXT('\0'); |
OpenFilePath[_tcslen(OpenFilePath)+1] = TEXT('\0'); |
1326 |
SrcFile = OpenFilePath; |
SrcFile = OpenFilePath; |
1327 |
} |
} |
1328 |
|
|
1329 |
wcscpy(DstFile, SaveFilePath); |
_tcscpy(DstFile, SaveFilePath); |
1330 |
hConvertThread = CreateThread(0, 0, RecompressThreadProc, GetDlgItem(hDlg, IDC_PROGRESSBAR), 0, 0); |
hConvertThread = CreateThread(0, 0, RecompressThreadProc, GetDlgItem(hDlg, IDC_PROGRESSBAR), 0, 0); |
1331 |
} |
} |
1332 |
else |
else |