Domanda

AMCap è un applicazione per la cattura video o per visualizzare in anteprima da webcam. Il suo codice sorgente fornito con Microsoft Windows SDK come campione.

Voglio (by-pass il seguente processo di interazione con l'utente nel codice AMCAP o dire vuole) impostarlo come predefinito:

Menu Ampcap

  Options

    Video Capture Pin ...

        Color Space/Compression: YUY2

        Output size: 1600x1200

Ho una webcam compatibile e funziona bene a cambiare manualmente per YUY2 e 1600x1200 in AMCAP app.

Per impostazione predefinita è:

    Color Space/Compression: MJPG

    Output size: 160x120

Ho cercato di trovare stringa 'YUY2' in tutto il progetto, ma non riuscivo a trovare, in modo che potessi hardcode esso. Sembra che si crea in modo dinamico e quindi operato; riferimento:. nel file amcap.cpp vicina linea no 3395

È stato utile?

Soluzione 2

Ehi @Dani van der Meer: Grazie per il puntatore ... ho fatto da: Nei InitCapFilters funzione BOOL ()

Dopo

 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;

Incolla:

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);
}

Grazie mille

Altri suggerimenti

Ho qualche codice che utilizza un'interfaccia IID_IAMStreamConfig per impostare la dimensione dell'immagine della telecamera. Non ho usato per impostare il formato di immagine, ma ho aggiunto il codice che penso farà il lavoro. E 'testato comunque.

            // 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;
            }

Si dovrebbe inserire il codice dopo il seguente blocco in AMCAP:

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

Ancora una volta, questo è il codice non testato, ma si può provare e spero che aiuta.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top