( Diese Seite in flag-germany.gif Deutsch )

DirectShowSource(string filename [, float fps, bool seek, bool audio, bool video, bool convertfps, bool seekzero, int timeout, string pixel_type])

Description

filename: DirectShowSource reads filename using MS DirectShow, the same multimedia playback system which Windows Media Player uses. It can read most formats which Media Player can play, including MPEG, MP3, and some QuickTime files, as well as AVI files that AVISource doesn't support (like DV type 1, or files using DirectShow-only codecs). Try reading AVI files with AVISource first, and if that doesn't work then try this filter instead. Since v2.53 there is also support for GraphEdit (grf) files.

There are some caveats:

  1. Some decoders (notably MS MPEG-4) will produce upside-down video. You'll have to use FlipVertical.
  2. DirectShow video decoders are not required to support frame-accurate seeking. In most cases seeking will work, but on some it might not.
  3. DirectShow video decoders are not even required to tell you the frame rate of the incoming video. Most do, but the ASF decoder doesn't. You have to specify the frame rate using the fps parameter, like this: DirectShowSource("video.asf", fps=15).
  4. This version automatically detects the Microsoft DV codec and sets it to decode at full (instead of half) resolution. I guess this isn't a caveat. :-)
  5. Also this version attempts to disable any decoder based deinterlacing.

fps: This is sometimes needed to specify the framerate of the video. If the framerate or the number of frames is incorrect (this can happen with asf or mov clips), use this option to force the correct framerate.

seek = true (in v2.53): There is full seeking support (available on most file formats). If problems occur try enabling the seekzero option first, if seeking still cause problems completely disable seeking. With seeking disabled the audio stream returns silence and the video stream the last rendered frame when trying to seek backwards. Note the Avisynth cache may provide limited access to the previous few frames, beyond that the last frame rendered will be returned.

audio = true (in v2.53): There is audio support in DirectShowSource. DirectShowSource is able to open formats like WAV/DTS/AC3/MP3, provided you can play them in WMP for example (more exact: provided they are rendered correctly in graphedit). The channel ordening is the same as in the [wave-format-extensible format], because the input is always decompressed to WAV. For more information, see also GetChannel. AviSynth loads 8, 16, 24 and 32 bit int PCM samples, and float PCM format, and any number of channels.

video = true (in v2.52): When setting it to false, it lets you open the audio only.

convertfps = false (in v2.56): It turns variable framerate video (vfr) into constant framerate video (cfr) by adding frames. This is useful when you want to open vfr video (for example mkv, rmvb, mp4, asf or wmv with hybrid video) in AviSynth. It is most useful when the fps parameter is set to the least common multiple of the component vfr rates, e.g. 120 or 119.880.

seekzero = false (in v2.56): An option to restrict seeking only back to the beginning. It allows limited seeking with unindexed ASF. Seeking forwards is of course done the hard way (by reading all samples).

timeout = 60000 (in milliseconds; 60000 ms = 1 min) (in v2.56): To set time to wait when DirectShow refuses to render. Positive values return blank frames and/or silence. Negative values cause a runtime AviSynth exception to be thrown.

pixel_type (in v2.56): The pixel type of the resulting clip, it can be "YV12", "YUY2", "ARGB", "RGB32", "RGB24", "YUV", "RGB" or "AUTO". It limits the acceptable video stream subformats for the IPin negotiation. Note the graph builder may add a format converter to satisfy your request, so make sure the codec in use can actually decode to your chosen format. The M$ format converter is just adequate. The "YUV" and "RGB" pseudo-types restrict the negotiation to all supported yuv or rgb formats respectively.

Examples

Opens an avi with the first available RGB format (without audio):

DirectShowSource("F:\TestStreams\xvid.avi",fps=25, audio=false, pixel_type="RGB")

Opens a DV clip with the MS DV decoder:

DirectShowSource("F:\DVCodecs\Analysis\Ced_dv.avi") # MS-DV

Opens a variable framerate mkv as 119.88 by adding frames (ensuring sync):

DirectShowSource("F:\Guides\Hybrid\vfr_startrek.mkv", fps=119.88, convertfps=true)

Opens a realmedia *rmvb clip:

DirectShowSource("F:\test.rmvb", fps=24, convertfps=true)

Opens a GraphEdit file:

DirectShowSource("F:\graph.grf")

See below for some audio examples.

Troubleshooting video and audio problems

AviSynth will by default try to open only the media it can open without any problems. If one component cannot be opened it will simply not be added to the output. This will also mean that if there is a problem, you will not see the error. To get the error message to the missing component, use audio=false or video=false and disable the component that is actually working. This way AviSynth will print out the error message of the component that doesn't work.

"The Filter Graph won't talk to me" !!!

This is a common error that occurs when DirectShow isn't able to deliver any format that is readable to AviSynth. Try creating a filter graph manually and see if you are able to construct a filter graph that delivers any output AviSynth can open. If not, you might need to download additional DirectShow filters that can deliver correct material.

The samplerate is wrong!

Some filters might have problems reporting the right samplerate, and then correct this when the file is actually playing. Unfortunately there is no way for AviSynth to correct this once the file has been opened. Use "AssumeSampleRate" and set the correct samplerate to fix this problem.

My sound is choppy

Unfortunately Directshow is not required to support sample exact seeking. Open the sound another way, or demux your video file and serve it to AviSynth another way. Otherwise you can specify "seekzero = true" or "seek = false" as parameters or use the EnsureVBRMP?3Sync filter to enforce linear access to the Directshow audio stream.

Common tasks

This section will describe various tasks that might not be 100% obvious. :)

Opening GRF files

GraphEdit GRF-files are automatically detected by a .grf filename extension and loaded by DirectShowSource. For AviSynth to be able to connect to it, you must leave pins open in GraphEdit of media types that AviSynth is able to connect to. AviSynth will not attempt to disconnect any filters, so it is important that the output type is correct.

Downmixing AC3 to stereo

There are essentially two ways to do this. The first is to set the downmixing in the configuration of your AC3 decoder itself, and the second one is to use the external downmixer of "Trombettworks":

1) Install AC3filter. Open the AC3 file in WMP6.4 and select the file properties. Set the output of AC3Filter on 2/0 - stereo. If you want the best possible quality, select PCM Float as Sample format.

ac3downmix1a.jpg ac3downmix1b.jpg

Make the following script:

v = Mpeg2Source("e:\movie.d2v")
a = DirectShowSource("e:\Temp\Test2\test.ac3")
AudioDub(v,a)

Finally, open the script in vdub and convert the audio stream to MP3 (of course you can also demux the downmixed WAV stream if needed).

2) Register the directshow filter [Channel Downmixer by Trombettworks] (under start -> run):

regsvr32 ChannelDownmixer.ax

Open the AC3 file in WMP6.4 and select the file properties. Set the output of AC3Filter on 3/2+SW 5.1 channels (this downmixer can't handle PCM Float, thus PCM 16 bit is selected here). In the properties of the downmixer, the number of input and output channels should be detected automatically. Check whether this is indeed correct.

ac3downmix2a.jpg ac3downmix2b.jpg
ac3downmix2c.jpg

Make the following script:

v = Mpeg2Source("e:\movie.d2v")
a = DirectShowSource("e:\Temp\Test2\test.ac3")
AudioDub(v,a)

Finally, open the script in vdub and convert the audio stream to MP3 (of course you can also demux the downmixed WAV stream if needed).

For some reason, I can't get this to work with DTS streams :(

Changes

v2.56 convertfps turns vfr into constant cfr by adding frames
  seekzero restricts seeking to begining only
  timeout controls response to recalcitrant graphs
  pixel_type specifies/restricts output video pixel format