About DirectX Video Capture
-
:(( Hey, I am having trouble capturing video from my pc cammera. The directx SDK directshow sample "Play Cap" have developed my previewing skills. But capturing is not going so well. In the DX9 Book it is said that just by making some minor changes in the ICaptureBuilderGraph2::RenderStream() we developers be able to capture live video. But thats not happening. In the "Play Cap" sample code when i do this minor changes as told it raises an error.
//After g_pCapture->AddFilter(pSrcFilter); IBaseFilter *pMux; hr = g_Capture->SetOutPutFileName(&MEDIASUBTYPE_Avi, L"C:\\Test.avi", &pMux, NULL); hr = g_Capture->RenderStream(&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Avi, pSrcFilter, NULL, pMux /*NULL*/); pMux->Release(); pSrcFilter->Release(); hr = setupVideoWindow(); // Raises an error at the first line // if i leave the renderstream last variable NULL then the program runs // succesfully. But capturing doesn't takes place.
-
:(( Hey, I am having trouble capturing video from my pc cammera. The directx SDK directshow sample "Play Cap" have developed my previewing skills. But capturing is not going so well. In the DX9 Book it is said that just by making some minor changes in the ICaptureBuilderGraph2::RenderStream() we developers be able to capture live video. But thats not happening. In the "Play Cap" sample code when i do this minor changes as told it raises an error.
//After g_pCapture->AddFilter(pSrcFilter); IBaseFilter *pMux; hr = g_Capture->SetOutPutFileName(&MEDIASUBTYPE_Avi, L"C:\\Test.avi", &pMux, NULL); hr = g_Capture->RenderStream(&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Avi, pSrcFilter, NULL, pMux /*NULL*/); pMux->Release(); pSrcFilter->Release(); hr = setupVideoWindow(); // Raises an error at the first line // if i leave the renderstream last variable NULL then the program runs // succesfully. But capturing doesn't takes place.
I don't see a video renderer filter, so how can you setup the video window? You seem to have only created a graph for capturing video to disk.
-
:(( Hey, I am having trouble capturing video from my pc cammera. The directx SDK directshow sample "Play Cap" have developed my previewing skills. But capturing is not going so well. In the DX9 Book it is said that just by making some minor changes in the ICaptureBuilderGraph2::RenderStream() we developers be able to capture live video. But thats not happening. In the "Play Cap" sample code when i do this minor changes as told it raises an error.
//After g_pCapture->AddFilter(pSrcFilter); IBaseFilter *pMux; hr = g_Capture->SetOutPutFileName(&MEDIASUBTYPE_Avi, L"C:\\Test.avi", &pMux, NULL); hr = g_Capture->RenderStream(&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Avi, pSrcFilter, NULL, pMux /*NULL*/); pMux->Release(); pSrcFilter->Release(); hr = setupVideoWindow(); // Raises an error at the first line // if i leave the renderstream last variable NULL then the program runs // succesfully. But capturing doesn't takes place.
:sigh: dear hfry, I didn't gave the whole code. In the paragraph it is mentioned that the "Play Cap" sample code which comes with dx9 SDK helped me develop some understanding of video capture. Now if you have seen the Source Code of "Play Cap" you will understand where in between that code i have inserted these lines. I have mention that after the line "g_pCapture->AddFilter()". Which you will find in the Funtion VideoCapture() "(Play Cap)" Source code. If even then you need the code then i will write the code for you. Thanks for the reply.
-
:sigh: dear hfry, I didn't gave the whole code. In the paragraph it is mentioned that the "Play Cap" sample code which comes with dx9 SDK helped me develop some understanding of video capture. Now if you have seen the Source Code of "Play Cap" you will understand where in between that code i have inserted these lines. I have mention that after the line "g_pCapture->AddFilter()". Which you will find in the Funtion VideoCapture() "(Play Cap)" Source code. If even then you need the code then i will write the code for you. Thanks for the reply.
I have taken the trouble to look at the sample. Did you add your capture code after
hr = g_pCapture->RenderStream (&PIN_CATEGORY_PREVIEW, &MEDIATYPE_Video, pSrcFilter, NULL, NULL)
? Or did you modify it into your capture code? If you render a video stream with the destination as NULL, it will render it to the default video renderer (The old video renderer usually, and VMR7 in non-mixing mode on Windows XP). edit: That said, if you want to do both capturing to disk and previewing to the screen, always render the preview pin first. That way in the event that there isn't a real preview pin, a smart-T filter will be inserted so you can do the capture. From memory AFAIK, I don't think the smart-T gets inserted if you render the capture pin first and there isn't a preview pin. -- modified at 9:09 Monday 27th March, 2006 -
I have taken the trouble to look at the sample. Did you add your capture code after
hr = g_pCapture->RenderStream (&PIN_CATEGORY_PREVIEW, &MEDIATYPE_Video, pSrcFilter, NULL, NULL)
? Or did you modify it into your capture code? If you render a video stream with the destination as NULL, it will render it to the default video renderer (The old video renderer usually, and VMR7 in non-mixing mode on Windows XP). edit: That said, if you want to do both capturing to disk and previewing to the screen, always render the preview pin first. That way in the event that there isn't a real preview pin, a smart-T filter will be inserted so you can do the capture. From memory AFAIK, I don't think the smart-T gets inserted if you render the capture pin first and there isn't a preview pin. -- modified at 9:09 Monday 27th March, 2006Million thanks, Now it seems you have almost understood my problem. I have added the code below before the line you have mentioned and ommited it. The code below gives error when i give "renderstream" pMux Pointer. If i leave it null the code runs but video doesn't gets saved. This code is supposed to capture the live video.
IBaseFilter *pMux; hr = g_pCapture->SetOutputFileName( &MEDIASUBTYPE_Avi, // Specifies AVI for the target file. L"C:\\Example.avi", // File name. &pMux, // Receives a pointer to the mux. NULL); // (Optional) Receives a pointer to the file sink. if(FAILED(hr)) { Msg(TEXT("Couldn't create save file...")); } hr = g_pCapture->RenderStream( &PIN_CATEGORY_CAPTURE, // Pin category. &MEDIATYPE_Video, // Media type. pSrcFilter, // Capture filter. NULL, // Intermediate filter (optional). pMux /*NULL*/); // Mux or file sink filter. // Release the mux filter. pMux->Release(); the code below remains as it is. // hr = g_pCapture->RenderStream( // &PIN_CATEGORY_PREVIEW, // Pin category. // &MEDIATYPE_Video, // Media type. // pSrcFilter, // Capture filter. // NULL, // Intermediate filter (optional). // NULL);
-
Million thanks, Now it seems you have almost understood my problem. I have added the code below before the line you have mentioned and ommited it. The code below gives error when i give "renderstream" pMux Pointer. If i leave it null the code runs but video doesn't gets saved. This code is supposed to capture the live video.
IBaseFilter *pMux; hr = g_pCapture->SetOutputFileName( &MEDIASUBTYPE_Avi, // Specifies AVI for the target file. L"C:\\Example.avi", // File name. &pMux, // Receives a pointer to the mux. NULL); // (Optional) Receives a pointer to the file sink. if(FAILED(hr)) { Msg(TEXT("Couldn't create save file...")); } hr = g_pCapture->RenderStream( &PIN_CATEGORY_CAPTURE, // Pin category. &MEDIATYPE_Video, // Media type. pSrcFilter, // Capture filter. NULL, // Intermediate filter (optional). pMux /*NULL*/); // Mux or file sink filter. // Release the mux filter. pMux->Release(); the code below remains as it is. // hr = g_pCapture->RenderStream( // &PIN_CATEGORY_PREVIEW, // Pin category. // &MEDIATYPE_Video, // Media type. // pSrcFilter, // Capture filter. // NULL, // Intermediate filter (optional). // NULL);
And what is the hr error code from g_pCapture->RenderStream()? Before starting all this did you use GraphEdit to check what kind of graph you should be building?
-
And what is the hr error code from g_pCapture->RenderStream()? Before starting all this did you use GraphEdit to check what kind of graph you should be building?
Dear hfry, Sorry for the delayed answer. I am posting this message to inform you that my boss has shifted me directx to C#. Now I am doing work on some other project. The answer to your question is i didn't used graphEdit to check what kind of graph i should use. Now my final question is after using graphEdit in my application will i be able to generate a captured file successfully. Because with your help i am now able to just create blank file with nothing on it. Which gives an error that ClassFactory couldn't generate xxx. I will do as you have told me and give it a last try. By the way thanks for all ur time an patience. Forever gratefull. Mubashir
-
:(( Hey, I am having trouble capturing video from my pc cammera. The directx SDK directshow sample "Play Cap" have developed my previewing skills. But capturing is not going so well. In the DX9 Book it is said that just by making some minor changes in the ICaptureBuilderGraph2::RenderStream() we developers be able to capture live video. But thats not happening. In the "Play Cap" sample code when i do this minor changes as told it raises an error.
//After g_pCapture->AddFilter(pSrcFilter); IBaseFilter *pMux; hr = g_Capture->SetOutPutFileName(&MEDIASUBTYPE_Avi, L"C:\\Test.avi", &pMux, NULL); hr = g_Capture->RenderStream(&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Avi, pSrcFilter, NULL, pMux /*NULL*/); pMux->Release(); pSrcFilter->Release(); hr = setupVideoWindow(); // Raises an error at the first line // if i leave the renderstream last variable NULL then the program runs // succesfully. But capturing doesn't takes place.