Note that there are some explanatory texts on larger screens.

plurals
  1. POc++ builder: convert video to png-snapshots with directshow
    primarykey
    data
    text
    <p>Thanks to your help I was able to search for the right words to use directshow a bit better. I found a tutorial how to use the SampleGrabber-object here: <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/dd407288%28v=vs.85%29.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/windows/desktop/dd407288%28v=vs.85%29.aspx</a></p> <p>I could implement it and modified it a bit so it isn't just saving the first frame, but every Frame to a PNG. For that I use corona. However, I just guessed something around and don't quite know which buffers are containing my data and in which form.</p> <p>So, I have basically 3 questions:<br> Am I using SavePNG right? the resulting Images are upside-down!<br> Can I replace the BaseFilter for the video with one that is connected to a camera?<br> Contains pBuffer my Imagedata so I can get rgb-byte-informations by simply type pBuffer[123]?</p> <p>I'm using embarcadero's C++-Builder (XE2 16).</p> <p>Here is the code I found at the website, a bit modified (error-handling removed for better view. after each hr=... there is a Failed-check):</p> <pre><code>void __fastcall TForm1::btn_kameraClick(TObject *Sender) { HRESULT hr = S_OK; IGraphBuilder *pGraph = NULL; IMediaControl *pControl = NULL; IMediaEventEx *pEvent = NULL; IBaseFilter *pGrabberF = NULL; ISampleGrabber *pGrabber = NULL; IBaseFilter *pSourceF = NULL; IEnumPins *pEnum = NULL; IPin *pPin = NULL; IBaseFilter *pNullF = NULL; BYTE *pBuffer = NULL; hr = CoCreateInstance(CLSID_FilterGraph, NULL,CLSCTX_INPROC_SERVER,IID_PPV_ARGS(&amp;pGraph)); hr = pGraph-&gt;QueryInterface(IID_PPV_ARGS(&amp;pControl)); hr = pGraph-&gt;QueryInterface(IID_PPV_ARGS(&amp;pEvent)); hr = CoCreateInstance(CLSID_SampleGrabber, NULL, CLSCTX_INPROC_SERVER,IID_PPV_ARGS(&amp;pGrabberF)); hr = pGraph-&gt;AddFilter(pGrabberF, L"Sample Grabber"); hr = pGrabberF-&gt;QueryInterface(IID_PPV_ARGS(&amp;pGrabber)); AM_MEDIA_TYPE mt; ZeroMemory(&amp;mt, sizeof(mt)); mt.majortype = MEDIATYPE_Video; mt.subtype = MEDIASUBTYPE_RGB24; hr = pGrabber-&gt;SetMediaType(&amp;mt); hr = pGraph-&gt;AddSourceFilter(L"C:/Users/Julian/Desktop/homogenität/1,1x_2,7y.mpg", L"Source", &amp;pSourceF); hr = pSourceF-&gt;EnumPins(&amp;pEnum); while (S_OK == pEnum-&gt;Next(1, &amp;pPin, NULL)) { hr = ConnectFilters(pGraph, pPin, pGrabberF); SafeRelease(&amp;pPin); if (SUCCEEDED(hr))break; } hr = CoCreateInstance(CLSID_NullRenderer, NULL, CLSCTX_INPROC_SERVER,IID_PPV_ARGS(&amp;pNullF)); hr = pGraph-&gt;AddFilter(pNullF, L"Null Filter"); hr = ConnectFilters(pGraph, pGrabberF, pNullF); hr = pGrabber-&gt;SetOneShot(TRUE); hr = pGrabber-&gt;SetBufferSamples(TRUE); long evCode=0; long cbBuffer=0; hr = pControl-&gt;Run(); hr = pEvent-&gt;WaitForCompletion(INFINITE, &amp;evCode); hr = pGrabber-&gt;GetCurrentBuffer(&amp;cbBuffer, NULL); pBuffer = (BYTE*)CoTaskMemAlloc(cbBuffer); hr = pGrabber-&gt;GetConnectedMediaType(&amp;mt); CComQIPtr&lt; IMediaSeeking, &amp;IID_IMediaSeeking &gt; pSeeking( pGraph ); // for(int i=0;i&lt;10;i++){ bool hui=true;int i=0; while(hui){ REFERENCE_TIME Start = i * UNITS; hr = pSeeking-&gt;SetPositions( &amp;Start, AM_SEEKING_AbsolutePositioning,NULL, AM_SEEKING_NoPositioning ); // Sleep(10); hr = pEvent-&gt;WaitForCompletion(INFINITE,&amp;evCode); if(hr!=0)hui=false; hr = pGrabber-&gt;GetCurrentBuffer(&amp;cbBuffer, (long*)pBuffer); if ((mt.formattype == FORMAT_VideoInfo) &amp;&amp;(mt.cbFormat &gt;= sizeof(VIDEOINFOHEADER)) &amp;&amp;(mt.pbFormat != NULL)) { VIDEOINFOHEADER *pVih = (VIDEOINFOHEADER*)mt.pbFormat; // hr = WriteBitmap(("hui"+(String)i+".bmp").c_str(), &amp;pVih-&gt;bmiHeader, mt.cbFormat - SIZE_PREHEADER, pBuffer, cbBuffer); hr = SavePNG(i,pBuffer, pVih-&gt;bmiHeader.biWidth, pVih-&gt;bmiHeader.biHeight); } else hr = VFW_E_INVALIDMEDIATYPE; i++; } FreeMediaType(mt); done: CoTaskMemFree(pBuffer); SafeRelease(&amp;pPin); SafeRelease(&amp;pEnum); SafeRelease(&amp;pNullF); SafeRelease(&amp;pSourceF); SafeRelease(&amp;pGrabber); SafeRelease(&amp;pGrabberF); SafeRelease(&amp;pControl); SafeRelease(&amp;pEvent); SafeRelease(&amp;pGraph); } bool SavePNG(int i, Byte* m_pImageData,long m_Width,long m_Height) { // Make sure there is image data if (!m_pImageData) return false; stringstream FilePath; FilePath &lt;&lt; "hui"&lt;&lt; i&lt;&lt;".png"; // Create a corona image corona::Image* pImage = corona::CreateImage(m_Width, m_Height, corona::PF_R8G8B8, m_pImageData); // Make sure the image was created if (!pImage) return false; // Save the image to a PNG file corona::SaveImage(FilePath.str().c_str(), corona::FF_PNG, pImage); // Delete the corona image delete pImage; // Nothing went wrong return true; } </code></pre> <p>I hope I have done nothing horribly wrong... I really tried to research everything^^ Does somebody knows about my 3 questions above? I you found something really wrong here, I would also appreciate for you to tell me, so I can fix and improve.</p> <p>Regards, Julian</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload