# Can DirectShow create an Avi file ??

This topic is 4737 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi. I wonder if DirectShow can create an AVI file ?? or it can only maniplute an existing one. If it can, is it possible to take a buffer from the backbuffer and sae it as a frame in an AVI file ? Thanks

##### Share on other sites
It certainly is possible to create an AVI using DirectShow, off the top of my head I can't recall the exact method I used. Have a look in the SDK under DirectShow Tutorials->Recompressing an AVI. That will give you a bit of an incite into how DirectShow writes to files.

Also, you might want to look at the PushSource bitmap set sample in the SDK, this is almost the opposite of the sample grabber in fucntionality.

Kind regards.

Mark Colemanp

##### Share on other sites
yeah, I'm familiar with the example of the avi compression, I even used it to compress some avi's, but I need to create an Avi from nothing, meaning, to take a buffer from the backbuffer and create a frame in a new fresh avi file.

what is the interface I have to use that knows how to receieve a buffer from memory ??

Thanks.

##### Share on other sites
Reading from a buffer, e.g. Direct3D texture, is just locking it and copying the buffer?

##### Share on other sites
yeah, but is there an interface of DirectShow that accepts a buffer as input and adds it as a frame in a fresh clean AVI file ?? if yes, which one is it ??

Thanks

##### Share on other sites
To the best of my knowledge, there isn't. You'll have to write a custom filter to push data from your backbuffer into the filter graph. It's not hard.

##### Share on other sites
is there an example of how to do this ??

##### Share on other sites
There is. Take a look at this.
You'll just have to modify it to take the data from your source (direct3d backbuffer)

##### Share on other sites
that's exactly my problem, how do I set the source to be from the buffer?

Thanks

##### Share on other sites
I've never done it myself but I guess it would something like:

void copyBackBufferToMediaSample( IMediaSample* pSample ){  // assuming pBBSurface is a surface returned by IDirect3DDevice9::GetBackBuffer  D3DLOCKED_RECT lockedRect;  pBBSurface->LockRect( &lockedRect, NULL, D3DLOCK_READONLY );    BYTE* pOutBuffer;  pSample->GetPointer( &pOutBuffer );  // assuming bbHeight is the height of the backbuffer surface  for( int y=0 ; y<bbHeight ; y++ )  {    // Here I'm assuming that your input and output formats are ARGB    //and so I copy bbWidth*4 bytes per line, that is 4 bytes per pixel    memcpy( pOutBuffer, lockedRect.pBits, bbWidth*4 );    // also, I don't know how to get the output pitch here,    // I suppose that if you're exporting a simple bitmap    // off this filter you'll only have to align it to 4 bytes    // at the end of each scanline.    // assuming outPitch is the pitch of the outputted image    pOutBuffer += outPitch;    lockedRect.pbits += lockedRect.Pitch;  }}

I'm sorry for my bad english, I hope you'll understand.
Also, remember that I've never done this myself so I can be forgetting something here.