locked
Playing video from an own buffer RRS feed

  • Question

  • DirectShow developers,

     

    Is there a way to play a video stored in a own buffer ?

     

    A trivial example: I read all video data from file into buffer:

     

    unsigned char *buff = malloc( 5 * 1024 * 1024 * sizeof(unsigned char) );  // 5 MB

    fread(buff, 1, 5*1024*1024, file_in);

     

    How can I redirect the video reader / renderer to this buffer?

     

    Thank you for all tips

    Thursday, July 24, 2008 11:34 PM

All replies

  • Yes, you can definitely do this. The easiest way is to make your own source filter to replace the file source filter. The Async filter sample should give you some idea of how to do what you want.

    Friday, July 25, 2008 12:44 AM
  • Ok, I'm going take a look about it.

    After I've created the filter, how can I implement it into my player?

    Here is the code of my testing env. (player):

     

    #include <dshow.h>

     

    IGraphBuilder *pGB = NULL;

    IMediaControl *pMC = NULL;

    IVideoWindow *pVW = NULL;

     

    INT APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)

    {

    // input

    WCHAR lpMediaNC[]=L"F:\\Resource\\GirlsGirlsGirls\\dance.wmv";

    WCHAR lpMediaC[]=L"F:\\Resource\\GirlsGirlsGirls\\dance_coded.wmv";

    WCHAR *lpMedia=lpMediaNC;

     

    // dialog window

    HWND hWnd=CreateDialog(hInstance, MAKEINTRESOURCE(IDD_VPLAYER), NULL, (DLGPROC)__MainDlgProc);

     

    // init

    if(FAILED(CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC, IID_IGraphBuilder, (void **)&pGB))) return 1;

    if(FAILED(pGB->QueryInterface(IID_IVideoWindow, (void **)&pVW))) return 3;

    if(FAILED(pGB->QueryInterface(IID_IMediaControl, (void **)&pMC))) return 4;

    if(FAILED(pGB->RenderFile(lpMedia, NULL))) return 5;

     

    // run

    if(FAILED(pMC->Run())) return 6;

     

    // window stuff

    MessageProcessing(hWnd);

     

    // release

    RELEASE(pVW);

    RELEASE(pMC);

    RELEASE(pGB);

     

    return 0;

    }

    Friday, July 25, 2008 1:15 AM
  • You can add your filter to an empty graph and render the output pin on your filter, and the rest of the graph should be constructed automatically by DirectShow.

    Friday, July 25, 2008 1:19 AM
  • I 've adapted the async filter for my own use and need some tips from advacned DShow user -

     

    how can I modify the filter to make streaming the video during playback because loading a +700 MB movie into memory is not very effective

    // or what way need I go to reach my purpose

     

    Thank you

    Saturday, July 26, 2008 1:18 PM
  • You basically just need to handle the buffer management intelligently internally in your filter. You could read blocks of data of a certain size, then discard the blocks when you no longer need them. If you need to seek back to a previous position you just read those blocks again.

     

    If you don't want to buffer the whole file in memory, why isn't the standard file source filter adequate?

    Sunday, July 27, 2008 4:22 PM
  • I do not really know if the "async" example is modified by its creator to read the entire file into memory or it's interface is created to allow buffering when needed by player or splitter. But if a standard source file filter does streaming, of course it will be ok.

    I'm new in DShow filters, so I dont know what current interface does in real.

    Sunday, July 27, 2008 9:56 PM
  • I'm not sure about the details of the async sample, since I haven't looked at the implementation. However, the standard source filter definitely streams, so it should work fine unless you have some special needs.

    Sunday, July 27, 2008 11:02 PM