Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. convert mpg to avi in directshow

convert mpg to avi in directshow

Scheduled Pinned Locked Moved C / C++ / MFC
questionlearning
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    liur17
    wrote on last edited by
    #1

    Recently I try to convert mpg file to avi programmly, but it doesn't work , i am a beginner:) ,the code list below, anyone can give me suggestion? thanks. hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **)&pGraph); IBaseFilter *pSrcFilter = NULL; hr = pGraph->AddSourceFilter(lpMpgFile, L"Source Filter", &pSrcFilter); hr = CoCreateInstance(CLSID_CaptureGraphBuilder2, NULL, CLSCTX_INPROC, IID_ICaptureGraphBuilder2, (void **)&pBuilder); pBuilder->SetFiltergraph(pGraph); hr = pBuilder->SetOutputFileName(&MEDIASUBTYPE_Avi, lpOutputAviFile, &pMux, NULL); hr = pGraph->AddFilter(pMux, L"Mux Filter"); IBaseFilter *pMpeg2Splitter= NULL; hr = CoCreateInstance(CLSID_MPEG2Demultiplexer, 0, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void **)&pMpeg2Splitter); hr = pGraph->AddFilter(pMpeg2Splitter, L"Mpeg2 Splitter"); IMpeg2Demultiplexer *pDemux = NULL; hr = pMpeg2Splitter->QueryInterface(IID_IMpeg2Demultiplexer, (void**)&pDemux); AM_MEDIA_TYPE pMediaType; memset(&pMediaType, 0x0, sizeof(pMediaType)); pMediaType.majortype = MEDIATYPE_Video; pMediaType.subtype = MEDIASUBTYPE_MPEG2_VIDEO; pMediaType.formattype = FORMAT_MPEG2Video; pMediaType.bFixedSizeSamples = FALSE; pMediaType.bTemporalCompression = TRUE; pMediaType.lSampleSize = 0; MPEG2VIDEOINFO video_info; memset(&video_info, 0x0, sizeof(MPEG2VIDEOINFO)); pMediaType.cbFormat = sizeof(MPEG2VIDEOINFO); pMediaType.pbFormat = (BYTE *)&video_info; AM_MEDIA_TYPE pMediaAudioType; memset(&pMediaAudioType, 0x0, sizeof(pMediaAudioType)); pMediaAudioType.majortype = MEDIATYPE_Audio; pMediaAudioType.subtype = MEDIASUBTYPE_MPEG1Payload; pMediaAudioType.formattype = FORMAT_WaveFormatEx; pMediaAudioType.bFixedSizeSamples = FALSE; pMediaAudioType.bTemporalCompression = FALSE; pMediaAudioType.lSampleSize = 0; MPEG1WAVEFORMAT audio_info; memset(&audio_info, 0x0, sizeof(MPEG1WAVEFORMAT)); pMediaAudioType.cbFormat = sizeof(MPEG1WAVEFORMAT); pMediaAudioType.pbFormat = (BYTE *)&audio_info; IPin *pPin0 = NULL; hr = pDemux->CreateOutputPin(&pMediaType, L"Video Output", &pPin0); IMPEG2StreamIdMap *pStreamIdMap = NULL; hr = pPin0->QueryInterface(IID_IMPEG2StreamIdMap, (void **)&pStreamIdMap); hr = pStreamIdMap->MapStreamId(0xC0, MPEG2_PROGRAM_ELEMENTARY_STREAM, 0, 0); IPin *pPin1 = NULL; hr = pDemux->CreateOutputPin(&pMediaAudioType, L"Audio Output", &pPin1); IMPEG2StreamIdMap *pStreamIdMap1 = NULL; hr = pPin1->QueryInterface(IID_IMPEG2StreamIdMap, (void **)&pStreamIdMap1); hr = pStreamIdMap1->MapStre

    T M H 3 Replies Last reply
    0
    • L liur17

      Recently I try to convert mpg file to avi programmly, but it doesn't work , i am a beginner:) ,the code list below, anyone can give me suggestion? thanks. hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **)&pGraph); IBaseFilter *pSrcFilter = NULL; hr = pGraph->AddSourceFilter(lpMpgFile, L"Source Filter", &pSrcFilter); hr = CoCreateInstance(CLSID_CaptureGraphBuilder2, NULL, CLSCTX_INPROC, IID_ICaptureGraphBuilder2, (void **)&pBuilder); pBuilder->SetFiltergraph(pGraph); hr = pBuilder->SetOutputFileName(&MEDIASUBTYPE_Avi, lpOutputAviFile, &pMux, NULL); hr = pGraph->AddFilter(pMux, L"Mux Filter"); IBaseFilter *pMpeg2Splitter= NULL; hr = CoCreateInstance(CLSID_MPEG2Demultiplexer, 0, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void **)&pMpeg2Splitter); hr = pGraph->AddFilter(pMpeg2Splitter, L"Mpeg2 Splitter"); IMpeg2Demultiplexer *pDemux = NULL; hr = pMpeg2Splitter->QueryInterface(IID_IMpeg2Demultiplexer, (void**)&pDemux); AM_MEDIA_TYPE pMediaType; memset(&pMediaType, 0x0, sizeof(pMediaType)); pMediaType.majortype = MEDIATYPE_Video; pMediaType.subtype = MEDIASUBTYPE_MPEG2_VIDEO; pMediaType.formattype = FORMAT_MPEG2Video; pMediaType.bFixedSizeSamples = FALSE; pMediaType.bTemporalCompression = TRUE; pMediaType.lSampleSize = 0; MPEG2VIDEOINFO video_info; memset(&video_info, 0x0, sizeof(MPEG2VIDEOINFO)); pMediaType.cbFormat = sizeof(MPEG2VIDEOINFO); pMediaType.pbFormat = (BYTE *)&video_info; AM_MEDIA_TYPE pMediaAudioType; memset(&pMediaAudioType, 0x0, sizeof(pMediaAudioType)); pMediaAudioType.majortype = MEDIATYPE_Audio; pMediaAudioType.subtype = MEDIASUBTYPE_MPEG1Payload; pMediaAudioType.formattype = FORMAT_WaveFormatEx; pMediaAudioType.bFixedSizeSamples = FALSE; pMediaAudioType.bTemporalCompression = FALSE; pMediaAudioType.lSampleSize = 0; MPEG1WAVEFORMAT audio_info; memset(&audio_info, 0x0, sizeof(MPEG1WAVEFORMAT)); pMediaAudioType.cbFormat = sizeof(MPEG1WAVEFORMAT); pMediaAudioType.pbFormat = (BYTE *)&audio_info; IPin *pPin0 = NULL; hr = pDemux->CreateOutputPin(&pMediaType, L"Video Output", &pPin0); IMPEG2StreamIdMap *pStreamIdMap = NULL; hr = pPin0->QueryInterface(IID_IMPEG2StreamIdMap, (void **)&pStreamIdMap); hr = pStreamIdMap->MapStreamId(0xC0, MPEG2_PROGRAM_ELEMENTARY_STREAM, 0, 0); IPin *pPin1 = NULL; hr = pDemux->CreateOutputPin(&pMediaAudioType, L"Audio Output", &pPin1); IMPEG2StreamIdMap *pStreamIdMap1 = NULL; hr = pPin1->QueryInterface(IID_IMPEG2StreamIdMap, (void **)&pStreamIdMap1); hr = pStreamIdMap1->MapStre

      T Offline
      T Offline
      toxcct
      wrote on last edited by
      #2

      why doen't it work ? what error do you get ?


      [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

      1 Reply Last reply
      0
      • L liur17

        Recently I try to convert mpg file to avi programmly, but it doesn't work , i am a beginner:) ,the code list below, anyone can give me suggestion? thanks. hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **)&pGraph); IBaseFilter *pSrcFilter = NULL; hr = pGraph->AddSourceFilter(lpMpgFile, L"Source Filter", &pSrcFilter); hr = CoCreateInstance(CLSID_CaptureGraphBuilder2, NULL, CLSCTX_INPROC, IID_ICaptureGraphBuilder2, (void **)&pBuilder); pBuilder->SetFiltergraph(pGraph); hr = pBuilder->SetOutputFileName(&MEDIASUBTYPE_Avi, lpOutputAviFile, &pMux, NULL); hr = pGraph->AddFilter(pMux, L"Mux Filter"); IBaseFilter *pMpeg2Splitter= NULL; hr = CoCreateInstance(CLSID_MPEG2Demultiplexer, 0, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void **)&pMpeg2Splitter); hr = pGraph->AddFilter(pMpeg2Splitter, L"Mpeg2 Splitter"); IMpeg2Demultiplexer *pDemux = NULL; hr = pMpeg2Splitter->QueryInterface(IID_IMpeg2Demultiplexer, (void**)&pDemux); AM_MEDIA_TYPE pMediaType; memset(&pMediaType, 0x0, sizeof(pMediaType)); pMediaType.majortype = MEDIATYPE_Video; pMediaType.subtype = MEDIASUBTYPE_MPEG2_VIDEO; pMediaType.formattype = FORMAT_MPEG2Video; pMediaType.bFixedSizeSamples = FALSE; pMediaType.bTemporalCompression = TRUE; pMediaType.lSampleSize = 0; MPEG2VIDEOINFO video_info; memset(&video_info, 0x0, sizeof(MPEG2VIDEOINFO)); pMediaType.cbFormat = sizeof(MPEG2VIDEOINFO); pMediaType.pbFormat = (BYTE *)&video_info; AM_MEDIA_TYPE pMediaAudioType; memset(&pMediaAudioType, 0x0, sizeof(pMediaAudioType)); pMediaAudioType.majortype = MEDIATYPE_Audio; pMediaAudioType.subtype = MEDIASUBTYPE_MPEG1Payload; pMediaAudioType.formattype = FORMAT_WaveFormatEx; pMediaAudioType.bFixedSizeSamples = FALSE; pMediaAudioType.bTemporalCompression = FALSE; pMediaAudioType.lSampleSize = 0; MPEG1WAVEFORMAT audio_info; memset(&audio_info, 0x0, sizeof(MPEG1WAVEFORMAT)); pMediaAudioType.cbFormat = sizeof(MPEG1WAVEFORMAT); pMediaAudioType.pbFormat = (BYTE *)&audio_info; IPin *pPin0 = NULL; hr = pDemux->CreateOutputPin(&pMediaType, L"Video Output", &pPin0); IMPEG2StreamIdMap *pStreamIdMap = NULL; hr = pPin0->QueryInterface(IID_IMPEG2StreamIdMap, (void **)&pStreamIdMap); hr = pStreamIdMap->MapStreamId(0xC0, MPEG2_PROGRAM_ELEMENTARY_STREAM, 0, 0); IPin *pPin1 = NULL; hr = pDemux->CreateOutputPin(&pMediaAudioType, L"Audio Output", &pPin1); IMPEG2StreamIdMap *pStreamIdMap1 = NULL; hr = pPin1->QueryInterface(IID_IMPEG2StreamIdMap, (void **)&pStreamIdMap1); hr = pStreamIdMap1->MapStre

        M Offline
        M Offline
        Mark Salsbery
        wrote on last edited by
        #3

        A few potential problems... SetOutputFileName() adds the AVI mux filter to the graph - you don't need to add it manually. I'm not sure why you're using the MPEG2 splitter AND muxer. Regardless, you'll need an mpeg2 decoder for it to work (I don't think there's one included with Windows). I would try simplifying your graph building first. Compare your method to the method shown here: Building the Recompression Graph[^] Also testing it in graphedit.exe can help to make sure you're using the correct filters. MArk

        Mark Salsbery Microsoft MVP - Visual C++ This episode brought to you by the letter Z

        L 1 Reply Last reply
        0
        • L liur17

          Recently I try to convert mpg file to avi programmly, but it doesn't work , i am a beginner:) ,the code list below, anyone can give me suggestion? thanks. hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **)&pGraph); IBaseFilter *pSrcFilter = NULL; hr = pGraph->AddSourceFilter(lpMpgFile, L"Source Filter", &pSrcFilter); hr = CoCreateInstance(CLSID_CaptureGraphBuilder2, NULL, CLSCTX_INPROC, IID_ICaptureGraphBuilder2, (void **)&pBuilder); pBuilder->SetFiltergraph(pGraph); hr = pBuilder->SetOutputFileName(&MEDIASUBTYPE_Avi, lpOutputAviFile, &pMux, NULL); hr = pGraph->AddFilter(pMux, L"Mux Filter"); IBaseFilter *pMpeg2Splitter= NULL; hr = CoCreateInstance(CLSID_MPEG2Demultiplexer, 0, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void **)&pMpeg2Splitter); hr = pGraph->AddFilter(pMpeg2Splitter, L"Mpeg2 Splitter"); IMpeg2Demultiplexer *pDemux = NULL; hr = pMpeg2Splitter->QueryInterface(IID_IMpeg2Demultiplexer, (void**)&pDemux); AM_MEDIA_TYPE pMediaType; memset(&pMediaType, 0x0, sizeof(pMediaType)); pMediaType.majortype = MEDIATYPE_Video; pMediaType.subtype = MEDIASUBTYPE_MPEG2_VIDEO; pMediaType.formattype = FORMAT_MPEG2Video; pMediaType.bFixedSizeSamples = FALSE; pMediaType.bTemporalCompression = TRUE; pMediaType.lSampleSize = 0; MPEG2VIDEOINFO video_info; memset(&video_info, 0x0, sizeof(MPEG2VIDEOINFO)); pMediaType.cbFormat = sizeof(MPEG2VIDEOINFO); pMediaType.pbFormat = (BYTE *)&video_info; AM_MEDIA_TYPE pMediaAudioType; memset(&pMediaAudioType, 0x0, sizeof(pMediaAudioType)); pMediaAudioType.majortype = MEDIATYPE_Audio; pMediaAudioType.subtype = MEDIASUBTYPE_MPEG1Payload; pMediaAudioType.formattype = FORMAT_WaveFormatEx; pMediaAudioType.bFixedSizeSamples = FALSE; pMediaAudioType.bTemporalCompression = FALSE; pMediaAudioType.lSampleSize = 0; MPEG1WAVEFORMAT audio_info; memset(&audio_info, 0x0, sizeof(MPEG1WAVEFORMAT)); pMediaAudioType.cbFormat = sizeof(MPEG1WAVEFORMAT); pMediaAudioType.pbFormat = (BYTE *)&audio_info; IPin *pPin0 = NULL; hr = pDemux->CreateOutputPin(&pMediaType, L"Video Output", &pPin0); IMPEG2StreamIdMap *pStreamIdMap = NULL; hr = pPin0->QueryInterface(IID_IMPEG2StreamIdMap, (void **)&pStreamIdMap); hr = pStreamIdMap->MapStreamId(0xC0, MPEG2_PROGRAM_ELEMENTARY_STREAM, 0, 0); IPin *pPin1 = NULL; hr = pDemux->CreateOutputPin(&pMediaAudioType, L"Audio Output", &pPin1); IMPEG2StreamIdMap *pStreamIdMap1 = NULL; hr = pPin1->QueryInterface(IID_IMPEG2StreamIdMap, (void **)&pStreamIdMap1); hr = pStreamIdMap1->MapStre

          H Offline
          H Offline
          Hamid Taebi
          wrote on last edited by
          #4

          Do you get any error?


          WhiteSky


          1 Reply Last reply
          0
          • M Mark Salsbery

            A few potential problems... SetOutputFileName() adds the AVI mux filter to the graph - you don't need to add it manually. I'm not sure why you're using the MPEG2 splitter AND muxer. Regardless, you'll need an mpeg2 decoder for it to work (I don't think there's one included with Windows). I would try simplifying your graph building first. Compare your method to the method shown here: Building the Recompression Graph[^] Also testing it in graphedit.exe can help to make sure you're using the correct filters. MArk

            Mark Salsbery Microsoft MVP - Visual C++ This episode brought to you by the letter Z

            L Offline
            L Offline
            liur17
            wrote on last edited by
            #5

            Thanks you very much! I get the root of problem by using graphedit.exe: the input mpg file is a mpeg-1 file, so the file source filer outputs mpeg1-stream, but mpeg2demultiplexer requires mpeg2-stream, when it's running, it popup many DCDSPFilter.ax window and show a error message: These filters cannot agree on a connection, verify type compatibility of input pin and output pin. after I change the mpeg2demultiplexer to mpeg1streamsplitter and add the mpeg1 decoder, it runs OK. But this remains a problem: how can I get the type of mpeg file? I have to identify the file type(mpeg1 or mpeg2) programmly so that I can add the according filter. ???

            M 1 Reply Last reply
            0
            • L liur17

              Thanks you very much! I get the root of problem by using graphedit.exe: the input mpg file is a mpeg-1 file, so the file source filer outputs mpeg1-stream, but mpeg2demultiplexer requires mpeg2-stream, when it's running, it popup many DCDSPFilter.ax window and show a error message: These filters cannot agree on a connection, verify type compatibility of input pin and output pin. after I change the mpeg2demultiplexer to mpeg1streamsplitter and add the mpeg1 decoder, it runs OK. But this remains a problem: how can I get the type of mpeg file? I have to identify the file type(mpeg1 or mpeg2) programmly so that I can add the according filter. ???

              M Offline
              M Offline
              Mark Salsbery
              wrote on last edited by
              #6

              liur17 wrote:

              how can I get the type of mpeg file? I have to identify the file type(mpeg1 or mpeg2) programmly so that I can add the according filter. ???

              2 possible ways I can think of: 1) After the successful AddSourceFilter() call, obtain a IFileSourceFilter interface from the source filter and use the IFileSourceFilter::GetCurFile() method to get the media type (looking for MPEG subtypes). 2) Let intelligent connect insert the necessary filters for you. Use AddSourceFilter() and SetOutputFileName() like you're doing, add the compressor filter you want for the destination AVI file, and use RenderStream() to connect the filters added by AddSourceFilter() and SetOutputFileName(), with the intermediate compressor filter. If you have suitable MPEG filters installed, intelligent connect will insert them for you. If not, RenderStream() will fail. A second call to RenderStream() will connect an audio stream to the AVI muxer if it's available (again, see here[^] for an example. You can try this in graphedit by manually adding a filesource async filter, setting the input filename, add a filewriter filter, set the output filename, add an AVI Mux filter, and connect the filesource to the filewriter filter. Mark

              Mark Salsbery Microsoft MVP - Visual C++ This episode brought to you by the letter Z

              L 1 Reply Last reply
              0
              • M Mark Salsbery

                liur17 wrote:

                how can I get the type of mpeg file? I have to identify the file type(mpeg1 or mpeg2) programmly so that I can add the according filter. ???

                2 possible ways I can think of: 1) After the successful AddSourceFilter() call, obtain a IFileSourceFilter interface from the source filter and use the IFileSourceFilter::GetCurFile() method to get the media type (looking for MPEG subtypes). 2) Let intelligent connect insert the necessary filters for you. Use AddSourceFilter() and SetOutputFileName() like you're doing, add the compressor filter you want for the destination AVI file, and use RenderStream() to connect the filters added by AddSourceFilter() and SetOutputFileName(), with the intermediate compressor filter. If you have suitable MPEG filters installed, intelligent connect will insert them for you. If not, RenderStream() will fail. A second call to RenderStream() will connect an audio stream to the AVI muxer if it's available (again, see here[^] for an example. You can try this in graphedit by manually adding a filesource async filter, setting the input filename, add a filewriter filter, set the output filename, add an AVI Mux filter, and connect the filesource to the filewriter filter. Mark

                Mark Salsbery Microsoft MVP - Visual C++ This episode brought to you by the letter Z

                L Offline
                L Offline
                liur17
                wrote on last edited by
                #7

                I got it. Thank you for your kind reply.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups