怎么使用dx的des实切文件的切割,切割后的片段文件的编码方式,帧速率等与原文件相同(也就是不解码的情况下切割)  搜索了原来的贴子好像有位仁兄遇到同样的问题,后面解决了,但没说具体怎么解决的,希望大家能帮忙解决.
    原贴:http://topic.csdn.net/t/20040628/12/3127830.html
  内容剪集:
       如何对视频文件进行切割?楼主wkgenius()2004-06-28 12:05:18 在 VC/MFC / 基础类 提问
            我用Direct   Show写一个程序,要对视频文件进行切割,比如对一个mpeg文件进行切割,现在的问题是这样,我用的是Direct   Show   Editing   Service,使用了IAMTimeline,每切割一次都要将视频解码然后再重新编码,但是由于编码是有损的,所以多切割几次,视频的效果明显降低了,请问如何才能不对视频进行重新编码,而只是进行切割呢?比如只是将原来的文件截掉一部分,多谢各位指教!!! 
       
    后面他自已解决了:
         3 楼wkgenius()回复于 2004-06-28 22:50:00 得分 0 
       我看了一下msdn,觉得可以用DirectShow的Editing   Service来实现,就是用Smart   Render   Engine,就是将原文件和压缩文件的压缩格式设置成一样,这样就不会进行重新编码,可是我试了一下好像不对,应该是我写错了,请各位指点一下,最好是能有简单的源代码,非常感谢!   
  比如说我要将C:\a.avi截掉文件后面的一半,结果保存在C:\b.avi中,该怎么做?
Top          4 楼wkgenius()回复于 2004-06-29 16:22:29 得分 0 
               问题已经解决了,就是使用Smart   Render   Engine,之前不行的原因是我的时间计算错了,嘿嘿。
原文件和压缩文件的压缩格式设置成一样? 怎么设呀

解决方案 »

  1.   

    Writing a Project to a File
      
    Microsoft DirectShow 9.0 Writing a Project to a File
    This is preliminary documentation and subject to change.This article describes how to write a video editing project to a file. First it describes how to write a file with the basic render engine. Then it describes smart recompression with the smart render engine. For an overview of how Microsoft® DirectShow® Editing Services renders projects, see About the Render Engines.Using the Basic Render EngineStart by building the front end of the graph, as follows: Create the render engine. 
    Specify the timeline. 
    Set the render range. (Optional) 
    Build the front end of the graph. 
    The following code example shows these steps.IRenderEngine *pRender = NULL; 
    hr = CoCreateInstance(CLSID_RenderEngine, NULL, CLSCTX_INPROC,
        IID_IRenderEngine, (void**) &pRender);hr = pRender->SetTimelineObject(pTL);
    hr = pRender->ConnectFrontEnd( );Next, add multiplexer and file-writing filters to the filter graph. The easiest way to do this is with the Capture Graph Builder, a DirectShow component for building capture graphs. The capture graph builder exposes the ICaptureGraphBuilder2 interface. Perform the following steps: Create an instance of the capture graph builder. 
    Obtain a pointer to the graph and pass it to the graph builder. 
    Specify the name and media type of the output file. This step also obtains a pointer to the mux filter, which is required later. 
    The following code example shows these steps.CoCreateInstance(CLSID_CaptureGraphBuilder2, NULL, CLSCTX_INPROC, 
        IID_ICaptureGraphBuilder2, (void **)&pBuilder);// Get a pointer to the graph front end.
    IGraphBuilder *pGraph;
    pRender->GetFilterGraph(&pGraph);
    pBuilder->SetFiltergraph(pGraph);// Create the file-writing section.
    IBaseFilter *pMux;
    pBuilder->SetOutputFileName(&MEDIASUBTYPE_Avi, 
        OLESTR("Output.avi"), &pMux, NULL);Finally, connect the output pins on the front end to the mux filter. Retrieve the number of groups. 
    For each pin, obtain a pointer to the pin. 
    Optionally, create an instance of a compression filter to compress the stream. The type of compressor will depend on the media type of the group. You can use the System Device Enumerator to enumerate the available compression filters. For more information, see Enumerating Devices and Filters. 
    Optionally, set compression parameters such as the key-frame rate. This step is discussed in detail later in the article. 
    Call ICaptureGraphBuilder2::RenderStream. This method takes pointers to the pin, the compression filter (if any), and the multiplexer. 
    The following code example shows how to connect the output pins.long NumGroups;
    pTimeline->GetGroupCount(&NumGroups);// Loop through the groups and get the output pins.
    for (i = 0; i < NumGroups; i++)
    {
        IPin *pPin;
        if (pRender->GetGroupOutputPin(i, &pPin) == S_OK) 
        {
            IBaseFilter *pCompressor;
            // Create a compressor filter. (Not shown.)
            // Set compression parameters. (Not shown.)        // Connect the pin.
            pBuilder->RenderStream(NULL, NULL, pPin, pCompressor, pMux);
            pCompressor->Release();
            pPin->Release();
        }
    }To set compression parameters (step 4, previously), use the IAMVideoCompression interface. This interface is exposed on the output pins of compression filters. Enumerate the compression filter's pins, and query each output pin for IAMVideoCompression. (For information about enumerating pins, see Enumerating Pins.) Be sure to release all the interface pointers that you obtained during this step.After you build the filter graph, call the IMediaControl::Run method on the filter graph manager. As the filter graph runs, it writes the data to a file. Use event notification to wait for playback to complete. (See Responding to Events.) When playback finishes, you must explicitly call IMediaControl::Stop to stop the filter graph. Otherwise, the file is not written correctly.Using the Smart Render EngineTo get the benefits of smart recompression, use the smart render engine in place of the basic render engine. The steps in building the graph are almost the same. The major difference is that compression is handled in the front end of the graph, not in the file-writing section. Important   Do not use the smart render engine to read or write Windows Media files. 
    Each video group has a property that specifies the compression format for that group. The compression format must exactly match the group's uncompressed format in height, width, bit depth, and frame rate. The smart render engine uses the compression format when it constructs the graph. Before you set the compression format, make sure to set the uncompressed format for that group by calling IAMTimelineGroup::SetMediaType.To set a group's compression format, call the IAMTimelineGroup::SetSmartRecompressFormat method. This method takes a pointer to an SCompFmt0 structure. The SCompFmt0 structure has two members: nFormatId, which must be zero, and MediaType, which is an AM_MEDIA_TYPE structure. Initialize the AM_MEDIA_TYPE structure with the format information. Note   If you want the final project to have the same format as one of your source files, you can get the AM_MEDIA_TYPE structure directly from the source file, using the media detector. See IMediaDet::get_StreamMediaType. 
    Cast the SCompFmt0 variable to a pointer of type long, as shown in the following example.SCompFmt0 *pFormat = new SCompFmt0;
    memset(pFormat, 0, sizeof(SCompFmt0));
    pFormat->nFormatId = 0;// Initialize pFormat->MediaType. (Not shown.)pGroup->SetSmartRecompressFormat( (long*) pFormat );The smart render engine automatically searches for a compatible compression filter. You can also specify a compression filter for a group by calling ISmartRenderEngine::SetGroupCompressor.To build the graph, use the same steps that were described for the Basic Render Enginer in the previous section. The only differences are the following: Use the smart render engine, not the basic render engine. The class identifier is CLSID_SmartRenderEngine. 
    Set compression parameters after you build the front end but before you render the output pins. Call the ISmartRenderEngine::GetGroupCompressor method to obtain a pointer to a group's compression filter. Then query for the IAMVideoCompression interface, as described previously. 
    When you render the output pins, there is no need to insert a compression filter. The stream is already compressed. 
      

  2.   

    谢谢两位。to yxz_lp, 那sdk我也看过,按sdk的那样直接输出的话,他是解码后输出到文件的,不能实现切割。示例中两行注解要到底怎么设呢,特别是对于mp4格式:        // Create a compressor filter. (Not shown.) 
            // Set compression parameters. (Not shown.) 
    for (i = 0; i  < NumGroups; i++) 

        IPin *pPin; 
        if (pRender- >GetGroupOutputPin(i, &pPin) == S_OK)  
        { 
            IBaseFilter *pCompressor; 
            // Create a compressor filter. (Not shown.) 
            // Set compression parameters. (Not shown.)         // Connect the pin. 
            pBuilder- >RenderStream(NULL, NULL, pPin, pCompressor, pMux); 
            pCompressor- >Release(); 
            pPin- >Release(); 
        }