使用DirectShow 將影片內容轉成圖檔 |
尚未結案
|
terence_lee
初階會員 發表:62 回覆:82 積分:28 註冊:2004-07-15 發送簡訊給我 |
|
bearmaster
一般會員 發表:36 回覆:45 積分:16 註冊:2004-05-27 發送簡訊給我 |
若你要開發 DirectShow 想必一定有安裝 DiretX SDK 吧. 可參考 AMCap 的寫法, Source: (SDK root)\Samples\C \DirectShow\Capture\AMCap 或是(從DirectX SDK擷取的資料):
The AVI Mux filter takes the video stream from the capture pin and packages it into an AVI stream. An audio stream could also be connected to the AVI Mux filter, in which case the mux would interleave the two streams. The File Writer filter writes the AVI stream to disk. To build the graph, start by calling the ICaptureGraphBuilder2::SetOutputFileName method, as follows: IBaseFilter *pMux;
hr = pBuild->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. The first parameter specifies the file type — in this case, AVI. The second parameter gives the file name. For AVI, the SetOutputFileName method cocreates the AVI Mux filter and the File Writer filter and adds them to the graph. It also sets the file name on the File Writer filter, by calling the IFileSinkFilter::SetFileName method, and connects the two filters. The method returns a pointer to the AVI Mux in the third parameter. Optionally, it returns a pointer to the IFileSinkFilter interface in the fourth parameter. If you don't need this interface, you can set this parameter to NULL, as shown in the previous example. Next, call the ICaptureGraphBuilder2::RenderStream method to connect the capture filter to the AVI Mux, as follows: hr = pBuild->RenderStream(
&PIN_CATEGORY_CAPTURE, // Pin category.
&MEDIATYPE_Video, // Media type.
pCap, // Capture filter.
NULL, // Intermediate filter (optional).
pMux); // Mux or file sink filter. // Release the mux filter.
pMux->Release(); The first parameter gives the pin category, which is PIN_CATEGORY_CAPTURE for capture. The second parameter gives the media type. The third parameter is a pointer to the capture filter's IBaseFilter interface. The fourth parameter is optional; it lets you route the video stream through an intermediate filter, such as an encoder, before passing it to the mux filter. Otherwise, set this parameter to NULL, as shown in the previous example. The fifth parameter is the pointer to the mux filter. This pointer is obtained by calling the SetOutputFileName method. To capture audio, call RenderStream with the media type MEDIATYPE_Audio. If you are capturing audio and video from two separate devices, it is a good idea to make the audio stream the master stream. This helps to prevent drift between the two streams, because the AVI Mux filter adjust the playback rate on the video stream to match the audio stream. To set the master stream, call the IConfigAviMux::SetMasterStream method on the AVI Mux filter: IConfigAviMux *pConfigMux = NULL;
hr = pMux->QueryInterface(IID_IConfigAviMux, (void**)&pConfigMux);
if (SUCCEEDED(hr))
{
pConfigMux->SetMasterStream(1);
pConfigMux->Release();
} The parameter to SetMasterStream is the stream number, which is determined by the order in which you call RenderStream. For example, if you call RenderStream first for video and then for audio, the video is stream 0 and the audio is stream 1. You may also want to set how the AVI Mux filter interleaves the audio and video streams, by calling the IConfigInterleaving::put_Mode method. IConfigInterleaving *pInterleave = NULL;
hr = pMux->QueryInterface(IID_IConfigInterleaving, (void**)&pInterleave);
if (SUCCEEDED(hr))
{
pInterleave->put_Mode(INTERLEAVE_CAPTURE);
pInterleave->Release();
} With the INTERLEAVE_CAPTURE flag, the AVI Mux performs interleaving at a rate that is suitable for video capture. You can also use INTERLEAVE_NONE, which means no interleaving — the AVI Mux will simply write the data in the order that it arrives. The INTERLEAVE_FULL flag means the AVI Mux performs full interleaving; however, this mode is less suitable for video capture because it requires the most overheard. Encoding the Video Stream You can encode the video stream by inserting an encoder filter between the capture filter and the AVI Mux filter. Use the System Device Enumerator or the Filter Mapper to select an encoder filter. (For more information, see Enumerating Devices and Filters.) Specify the encoder filter as the fourth parameter to RenderStream, shown in bold in the following example: IBaseFilter *pEncoder;
/* Create the encoder filter (not shown). */
// Add it to the filter graph.
pGraph->AddFilter(pEncoder, L"Encoder); /* Call SetOutputFileName as shown previously. */ // Render the stream.
hr = pBuild->RenderStream(&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video,
pCap, pEncoder, pMux);
pEncoder->Release(); The encoder filter might support IAMVideoCompression or other interfaces for setting the encoding parameters. For a list of possible interfaces, see File Encoding and Decoding Interfaces.
|
KENI_LIN
中階會員 發表:86 回覆:267 積分:90 註冊:2004-05-31 發送簡訊給我 |
可以參考以下兩個討論區:
(1)DirectShow原始程式:http://delphi.ktop.com.tw/topic.php?TOPIC_ID=54652
(2)影像程式介紹:http://delphi.ktop.com.tw/topic.php?TOPIC_ID=66402 第(1)項裡面,應該就有你要的capture功能,DXSDK9.0安裝和使用方法可以參考第(2)項討論內容. 寒窗苦讀十年書;只待今朝狀元時!~~
︵ / / ︵
( ∩ ∩ )
○ ︶ ○
Keni Lin
------
Keni Lin |
KENI_LIN
中階會員 發表:86 回覆:267 積分:90 註冊:2004-05-31 發送簡訊給我 |
|
terence_lee
初階會員 發表:62 回覆:82 積分:28 註冊:2004-07-15 發送簡訊給我 |
|
terence_lee
初階會員 發表:62 回覆:82 積分:28 註冊:2004-07-15 發送簡訊給我 |
|
KENI_LIN
中階會員 發表:86 回覆:267 積分:90 註冊:2004-05-31 發送簡訊給我 |
|
terence_lee
初階會員 發表:62 回覆:82 積分:28 註冊:2004-07-15 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |