2009-05-22 8 views
1

AMcapは、ビデオをキャプチャしたり、ウェブカメラからプレビューするためのアプリです。そのソースコードにはサンプルとしてMicrosoft Windows SDKが付属しています。amcapのデフォルトの色空間をYUY2に設定する方法は?

私がしたい(AMCAPコードにおけるユーザインタラクションのバイパス以下のプロセスまたはしたいと言う)は、デフォルトとして設定:

Ampcapメニュー

Options 

    Video Capture Pin ... 

     Color Space/Compression: YUY2 

     Output size: 1600x1200 

私は互換性のあるウェブカメラを持っていると、上の正常に動作しますAMCapアプリでYUY2と1600x1200に手動で変更する。デフォルトでは

それは次のとおりです。

Color Space/Compression: MJPG 

    Output size: 160x120 

私はプロジェクト全体で「YUY2」の文字列を見つけることを試みたが、私はそれをハードコーディングすることができるように、私は、それを見つけることができませんでした。動的に作成されて操作されたようです。参照:ファイルamcap.cppの近くの行番号3395.

答えて

1

ねえ@Daniファンデミーア:ポインタのおかげで...私はでそれを行っている:後関数BOOLのInitCapFilters()

if(hr != NOERROR) 
{ 

    hr = gcap.pBuilder->FindInterface(&PIN_CATEGORY_CAPTURE, 
             &MEDIATYPE_Video, gcap.pVCap, 
             IID_IAMStreamConfig, (void **)&gcap.pVSC); 

    if(hr != NOERROR) 
    { 
     // this means we can't set frame rate (non-DV only) 
     ErrMsg(TEXT("Error %x: Cannot find VCapture:IAMStreamConfig"), hr); 
    } 
} 

gcap.fCapAudioIsRelevant = TRUE; 

ペースト:

CMediaType *pmt; 
// default capture format 
if(gcap.pVSC && gcap.pVSC->GetFormat((AM_MEDIA_TYPE**)&pmt) == S_OK) 
{ 
    // DV capture does not use a VIDEOINFOHEADER 
    if(pmt->formattype == FORMAT_VideoInfo) 
    { 
    pmt->SetType(&MEDIATYPE_Video); 
    pmt->SetFormatType(&FORMAT_VideoInfo); 
    pmt->SetSubtype(&MEDIASUBTYPE_YUY2); 
    pmt->SetTemporalCompression(FALSE); 

    VIDEOINFOHEADER* lpvihin = (VIDEOINFOHEADER*) pmt->pbFormat; 

     { 

      //DWORD fccYUY2 = 'YUY2' ; 
      //lpvihin->bmiHeader.biCompression =fccYUY2; 
      //'YUY2';// MAKEFOURCC('Y','U','Y','2'); 
      //lpvihin->bmiHeader.biBitCount = 16; 
      lpvihin->bmiHeader.biWidth = 1600;// 960; //1600; 
      lpvihin->bmiHeader.biHeight = 1200;// 720; //1200; 
      lpvihin->bmiHeader.biSizeImage = 1600*1200*3; 

      hr = gcap.pVSC->SetFormat(pmt); 

      ResizeWindow(HEADER(pmt->pbFormat)->biWidth, 
        ABS(HEADER(pmt->pbFormat)->biHeight)); 
     } 
    } 
    if(pmt->majortype != MEDIATYPE_Video) 
    { 
     // This capture filter captures something other that pure video. 
     // Maybe it's DV or something? Anyway, chances are we shouldn't 
     // allow capturing audio separately, since our video capture 
     // filter may have audio combined in it already! 
     gcap.fCapAudioIsRelevant = FALSE; 
     gcap.fCapAudio = FALSE; 
    } 
    DeleteMediaType(pmt); 
} 

ありがとうございました

+0

OK。これが動作することを知っておいてよかった。 DirectShow APIは文書化されていません。いくつかの試行錯誤が必要です。 –

+0

はい、それは本当です。 – Rick2047

1

IID_IAMStreamConfigインターフェイスを使用してカメラのイメージサイズを設定するコードがあります。私はイメージフォーマットを設定するためにそれを使用しませんでしたが、私は仕事をすると思うコードを追加しました。しかし、それはテストされていません。これは未テストコードで、再び

if(hr != NOERROR) 
     hr = gcap.pBuilder->FindInterface(&PIN_CATEGORY_CAPTURE, 
      &MEDIATYPE_Video, gcap.pVCap, 
      IID_IAMStreamConfig, (void **)&pSC); 

を、あなたはそれを試すことができますし、私はそれが役に立てば幸い:

  // get the number of formats and make sure the strutucre size matches 
      int count; 
      int size; 
      VIDEO_STREAM_CONFIG_CAPS caps; 
      pSC->GetNumberOfCapabilities(&count, &size); 
      if(sizeof(caps) != size) 
      { 
       // Error 
      } 

      AM_MEDIA_TYPE* mt_p = NULL; 
      hr = pSC->GetStreamCaps(0, &mt_p, (BYTE*)&caps); 
      if (hr != S_OK) 
      { 
       // Error 
      } 

      if ((mt_p->majortype != MEDIATYPE_Video) || (mt_p->formattype != FORMAT_VideoInfo)) 
      { 
       // Error 
      } 

      VIDEOINFOHEADER* video_info_header_p = (VIDEOINFOHEADER *)mt_p->pbFormat; 
      video_info_header_p->bmiHeader.biWidth = 1600; 
      video_info_header_p->bmiHeader.biHeight = 1200; 
      // Code to change video format 
      // I think 16 is the right value for biBitCount, but I am not sure!!!! 
      video_info_header_p->bmiHeader.biCompression = MAKEFOURCC('Y','U','Y','2'); 
      video_info_header_p->bmiHeader.biBitCount = 16; 

      hr = pSC->SetFormat(mt_p); 
      if (hr != S_OK) 
      { 
       // Error 
      } 

      if (mt_p->cbFormat != 0) 
      { 
       CoTaskMemFree((PVOID)mt_p->pbFormat); 
       mt_p->cbFormat = 0; 
       mt_p->pbFormat = NULL; 
      } 
      if (mt_p->pUnk != NULL) 
      { 
       // Unecessary because pUnk should not be used, but safest. 
       mt_p->pUnk->Release(); 
       mt_p->pUnk = NULL; 
      } 

あなたはAMCAPで、次のブロックの後のコードを配置する必要があります。

+0

ありがとうございました 次は正しい答えです。 – Rick2047

関連する問題