FFmpegSource

From Avisynth wiki
(Difference between revisions)
Jump to: navigation, search
m (1 revision)
(add archived downloads sections)
(27 intermediate revisions by 4 users not shown)
Line 1: Line 1:
Opens files using FFmpeg and nothing else. May be frame accurate on good days. The source is MIT licensed and can be obtained from [http://code.google.com/p/ffmpegsource/source/checkout code.google.com/p/ffmpegsource/source/checkout]. The precompiled binary is GPL3 licensed.  
+
{{FilterCat|External_filters|Plugins|Source_filters}}
 +
{{Filter5
 +
|1={{Author/Myrsloik}}, et al.
 +
|2=v2.23.1
 +
|3=[https://github.com/FFMS/ffms2/releases FFMS2 v2.23.1]
 +
|4=[http://forum.doom9.org/member.php?u=135430 10bithack version]
 +
|5=[https://github.com/FFMS/ffms2/blob/master/doc/ffms2-avisynth.md User Manual]
 +
|6=Source filters
 +
|7=[https://opensource.org/licenses/MIT MIT] / binary is [https://www.gnu.org/licenses/gpl.txt GPLv3]
 +
|8=[https://forum.doom9.org/showthread.php?t=127037 Doom9 Thread]}}
  
==Source for this page==
+
== Description ==
This page is a copy of the [http://ffmpegsource.googlecode.com/svn/trunk/doc/ffms2-avisynth.html original FFMS2 documentation]. It may or may not be outdated. If you want to be sure you're reading the latest version, use the original documentation.
+
<div style="max-width:62em" >
 +
Opens files using [https://www.ffmpeg.org/ FFmpeg] and nothing else. May be frame accurate on good days. The source is MIT licensed and can be obtained from the [https://github.com/FFMS/ffms2/ GitHub repository]. The precompiled binary is GPL3 licensed.
 +
<br>
 +
</div>
 +
== Requirements ==
 +
<div style="max-width:62em" >
 +
* AviSynth 2.6.0 or [https://sourceforge.net/projects/avisynth2/ greater]
 +
* Supported color formats: [[RGB24]], [[RGB32]], [[YUY2]], [[Y8]], [[YV12]], [[YV16]], [[YV24]], [[YV411]]<br>
 +
:([[High_bit-depth_Support_with_Avisynth#Importing_High_Bit-depth_Video_into_AviSynth|10-bit formats]] are supported with the 10bithack version - see alternate download above)
 +
</div>
 +
== Limitations ==
 +
<div style="max-width:62em" >
 +
*Because of LAVF's demuxer, most raw streams (such as elementary h264 and other mpeg video streams) will fail to work properly.
  
==Limitations==
+
*'''FFAudioSource''' will have to remake any index implicitly created by '''FFVideoSource''' and therefore code like
 +
<div {{ListItemContinue}} >
 +
&nbsp;&nbsp;<code>AudioDub( FFVideoSource(X), FFAudioSource(X) )</code> <br>
 +
will require two indexing passes. Apart from the time consumed this is harmless. To work around it open the audio first: <br>
 +
&nbsp;&nbsp;<code>A = FFAudioSource(X)</code><br>
 +
&nbsp;&nbsp;<code>V = FFVideoSource(X)</code><br>
 +
&nbsp;&nbsp;<code>AudioDub(V, A)</code> <br>
 +
('''FFmpegSource2''' does this for you with a single function call) or use '''FFIndex''', like so: <br>
 +
&nbsp;&nbsp;<code>FFIndex(X)</code><br>
 +
&nbsp;&nbsp;<code>AudioDub( FFVideoSource(X), FFAudioSource(X) )</code>.
 +
</div>
 +
*Interlaced H.264 mostly works these days, but seeking may occasionally result in corruption.
 +
*Transport Streams will not decode reliably without {{FuncArg|seekmode}} -1.
 +
*Open-GOP H.264 will sometimes produces corruption when seeking.
 +
</div>
 +
== Known Issues ==
 +
<div style="max-width:62em" >
 +
(''NOTE this section does not appear in the [http://github.com/FFMS/ffms2/blob/master/doc/ffms2-avisynth.md latest documentation] and may be obsolete'')
 +
* Interlaced H.264 is decoded in an odd way; each field gets its own full-height frame and the fieldrate is reported as the framerate, and furthermore one of the fields (odd or even) may "jump around". To get the correct behavior, you can try setting {{FuncArg|fpsnum}} and {{FuncArg|fpsden}} so that the framerate is halved (may or may not work). This issue is caused by libavcodec.
 +
</div>
 +
== Compatibility ==
 +
<div style="max-width:62em" >
 +
===Video===
  
* Requires [http://haali.su/mkv/ Haali's Media Splitter] if you want to seek in OGM or MPEG PS/TS. Trying to do non-linear access in those containers without it will end in tears.
+
*AVI, MKV, MP4, FLV: Frame accurate
* Haali's splitter requires transport streams to be cut at packet boundaries. Use [http://forum.doom9.org/showthread.php?t=125447 TsRemux] to fix the stream before trying to open it.
+
*WMV: Frame accurate(?) but avformat seems to pick keyframes relatively far away
* Because of LAVF's demuxer most raw streams will fail to work properly such as elementary h264 and other mpeg video streams.
+
*OGM: Frame accurate(?)
* FFAudioSource() will have to remake any index implicitly created by FFVideoSource() and therefore code like
+
*VOB, MPG: Seeking seems to be off by one or two frames now and then
 
+
*M2TS, TS: Seeking seems to be off a few frames here and there
AudioDub(FFVideoSource(X), FFAudioSource(X))
+
**As MP4 container supports MPEG2/4 video stream, when seeking is off, you can try copying the stream to MP4 container (maybe without audio.) With FFmpeg: <code>ffmpeg -i file.m2ts -c:v copy -an file.mp4</code>. You might have to specify <code>-fflags +genpts</code> before <code>-i</code>.
 
+
*Image files: Most formats can be opened if seekmode=-1 is set, no animation support
will require two indexing passes. Apart from the time consumed this is harmless. To work around it open the audio first
+
 
+
A = FFAudioSource(X)
+
V = FFVideoSource(X)
+
AudioDub(V, A)
+
 
+
or use FFIndex():
+
FFIndex(X)
+
AudioDub(FFVideoSource(X), FFAudioSource(X))
+
 
+
==Known issues==
+
 
+
* Interlaced H.264 is decoded in an odd way; each field gets its own full-height frame and the fieldrate is reported as the framerate, and furthermore one of the fields (odd or even) may "jump around". To get the correct behavior, you can try setting <tt>fpsnum</tt> and <tt>fpsden</tt> so that the framerate is halved (may or may not work). This issue is caused by libavcodec.
+
 
+
* Decoding some M2TS files using Haali's splitter will cause massive blocking and other corruption issues. You can work around the issue either by remuxing the file to MKV (using GDSMux (make sure you untick "minimize output file size" in the Global settings tab) or eac3to), or (if you will be doing linear decoding only) by setting <tt>demuxer="lavf"</tt> in <tt>FFIndex</tt> and using <tt>seekmode=0</tt> with <tt>FFVideoSource</tt>. The cause of this issue is unknown but being investigated.
+
 
+
==Compatibility==
+
===Video===
+
* AVI, MKV, MP4, FLV: Frame accurate
+
* WMV: Frame accurate(?) but avformat seems to pick keyframes relatively far away
+
* OGM: Frame accurate(?)
+
* VOB, MPG: Seeking seems to be off by one or two frames now and then
+
* M2TS, TS: Seeking seems to be off a few frames here and there
+
* Image files: Most formats can be opened if seekmode=-1 is set, no animation support
+
  
 
===Audio===
 
===Audio===
  
Seeking should be sample-accurate with most codecs in AVI, MKV, MP4 and FLV with two notable exceptions, namely '''MP3''' and '''AC3''' where FFmpeg's decoders seem to be completely broken (with MP3 in particular you can feed the decoder the same encoded data three times in a row and get a different decoded result every time). Still, results should usually be "good enough" for most purposes.
+
Seeking should be sample-accurate with most codecs in AVI, MKV, MP4 and FLV.  
  
Decoding linearly will almost always work correctly.
+
Decoding linearly will almost always give correct results, and forward-seeks from trimming should result in at most a few hundred samples of corruption.
 +
<br>
 +
</div>
 +
== Indexing and You ==
 +
<div style="max-width:62em" >
 +
Before '''FFMS2''' can open a file, it must be indexed first so that keyframe/sample positions are known and seeking is easily accomplished. This is done automatically when using '''FFVideoSource''' or '''FFAudioSource''', but if you want to you can invoke the indexing yourself by calling '''FFIndex''', or by running <tt>ffmsindex.exe</tt>. By default the index is written to a file so it can be reused the next time you open the same file, but this behavior can be turned off if desired.
  
== Indexing and You==
+
If you wonder why '''FFMS2''' takes so long opening files, the indexing is the answer. If you want a progress report on the indexing, you can use the supplied <tt>ffmsindex.exe</tt> command line program.
 +
<br>
 +
</div>
 +
== Function Reference ==
 +
<div style="max-width:62em" >
 +
=== FFmpegSource2 ===
 +
{{FuncDef|FFmpegSource2(string ''source'' [, int ''vtrack'', int ''atrack'' , <br>
 +
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bool ''cache'', string ''cachefile'', int ''fpsnum'', int ''fpsden'', <br>
 +
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int ''threads'', string ''timecodes'', int ''seekmode'', bool ''overwrite'', <br>
 +
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int ''width'', int ''height'', string ''resizer'', string ''colorspace'', <br>
 +
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int ''rffmode'', int ''adjustdelay'', bool ''utf8'', string ''varprefix'' ] )
 +
}}
  
Before FFMS2 can open a file, it must be indexed first so that keyframe/sample positions are known and seeking is easily accomplished. This is done automatically when using <tt>FFVideoSource()</tt> or <tt>FFAudioSource()</tt>, but if you want to you can invoke the indexing yourself by calling <tt>FFIndex()</tt>, or by running <tt>ffmsindex.exe</tt>. By default the index is written to a file so it can be reused the next time you open the same file, but this behavior can be turned off if desired.
+
:{{Par2|source|string|(required)}}
 +
::Path of the file to be opened.
  
If you wonder why FFMS2 takes so long opening files, the indexing is the answer. If you want a progress report on the indexing, you can use the supplied <tt>ffmsindex.exe</tt> commandline program.
+
:{{Par2|vtrack|int|-1}}
 +
::The video track number to open, as seen by the relevant demuxer. Track numbers start from zero, and are guaranteed to be continous (i.e. there must be a track 1 if there is a track 0 and a track 2). {{FuncArg|vtrack}}=-1 (the default) means open the first video track. Note that this filter's idea about what ''track'' has what ''number'' may be completely different from what some other application might think.  
  
== Function reference==
+
:{{Par2|atrack|int|-2}}
 +
::The audio track to open. {{FuncArg|atrack}}=-1 means select the first available track. {{FuncArg|atrack}}=-2 (the default) means audio is disabled.
  
===FFIndex===
+
:{{Par2|cache|bool|true}}
 +
::If set to true (the default), this filter will first check if the {{FuncArg|cachefile}} contains a valid index, and if it does, that index will be used. If no index is found, all video tracks will be indexed, and the indexing data will be written to {{FuncArg|cachefile}} afterwards. If set to false, this filter will not look for an existing index file; instead all video tracks will be indexed when the script is opened, and the indexing data will be discarded after the script is closed; you will have to index again next time you open the script.
  
'''FFIndex(string source, string cachefile = source + ".ffindex", int indexmask = -1, int dumpmask = 0, string audiofile = "%sourcefile%.%trackzn%.w64", int errorhandling = 3,  bool overwrite = false, bool utf8 = false, string demuxer = "default")'''
+
:{{Par2|cachefile|string|source + ".ffindex"}}
 +
::The filename of the index file (where the indexing data is saved). Defaults to <tt>sourcefilename.ffindex</tt>.  
  
Indexes a number of tracks in a given source file and writes the index file to disk, where it can be picked up and used by <tt>FFVideoSource</tt> or <tt>FFAudioSource</tt>. Normally you do not need to call this function manually; it's invoked automatically if necessary by <tt>FFVideoSource</tt>/<tt>FFAudioSource</tt>. It does, however, give you more control over how indexing is done and it can also dump audio tracks to WAVE64 files while indexing is in progress.
+
:{{Par2|fpsnum|int|-1}}
 +
:{{Par2|fpsden|int|1}}
 +
::Controls the framerate of the output; used for VFR to CFR conversions. If {{FuncArg|fpsnum}} is less than or equal to zero (the default), the output will contain the same frames that the input did, and the frame rate reported to Avisynth will be set based on the input clip's average frame duration. If {{FuncArg|fpsnum}} is greater than zero, this filter will force a constant frame rate, expressed as a rational number where {{FuncArg|fpsnum}} is the numerator and {{FuncArg|fpsden}} is the denominator. This may naturally cause dropped or duplicated frames to achieve the desired frame rate, and the output is not guaranteed to have the same number of frames that the input did.
  
Note that this function returns an integer, not a clip (since it doesn't open video, nor audio). The return value isn't particularly interesting, but for the record it's 0 if the index file already exists (and is valid) and overwrite was not enabled, 1 if the index file was created and no previous index existed, and 2 if the index file was created by overwriting an existing, valid index file.
+
:{{Par2|threads|int|-1}}
 +
::The number of decoding threads to request from [http://ffmpeg.org/libavcodec.html '''libavcodec''']. Setting it to less than or equal to zero means it defaults to the number of logical CPUs as reported by Windows. Note that this setting might be completely ignored under a number of conditions; most commonly because a lot of decoders actually do not support multithreading. Default -1.
  
====Arguments====
+
:{{Par2|timecodes|string|""}}
{{Par|source|string|filename}}
+
::Filename to write [http://matroska.org/technical/specs/notes.html Matroska v2 timecodes] for the opened video track. If the file exists, it will be truncated and overwritten. Set to the empty string to disable timecodes writing (this is the default).  
The source file to index.
+
  
{{Par|cachefile|string|source + ".ffindex"}}
+
:{{Par2|seekmode|int|1}}
The filename of the index file (where the indexing data is saved). Defaults to <tt>sourcefilename.ffindex</tt>.
+
::Controls how seeking is done. Mostly useful for getting uncooperative files to work. Valid modes are:
 +
::*-1: Linear access without rewind; i.e. will throw an error if each successive requested frame number isn't bigger than the last one. Only intended for opening images but might work on well with some obscure video format.
 +
::*0: Linear access (i.e. if you request frame n without having requested all frames from 0 to n-1 in order first, all frames from 0 to n will have to be decoded before n can be delivered). The definition of slow, but should make some formats "usable".
 +
::*1: Safe normal (the default). Bases seeking decisions on the keyframe positions reported by libavformat.
 +
::*2: Unsafe normal. Same as mode 1, but no error will be thrown if the exact seek destination has to be guessed.
 +
::*3: Aggressive. Seeks in the forward direction even if no closer keyframe is known to exist. Only useful for testing and containers where libavformat doesn't report keyframes properly.
  
{{Par|indexmask|int|-1}}
+
:{{Par2|overwrite|bool|false}}
A binary mask representing what audio tracks should be indexed (all video tracks are always indexed; you have no choice in the matter). The mask is constructed by bitshifting 1 left by the track number; if multiple tracks are desired, bitwise OR each value so created together to get the full mask. In other words, the mask is a bit field where each bit is a track number (the least significant bit is track number 0). Since Avisynth doesn't have any bitwise operators at all, constructing the mask inside an Avisynth script is a rather annoying task.
+
::If set to true, this filter will reindex the source file and overwrite the index file even if the index file already exists and is valid. Mostly useful for trackmask changes and testing.
  
Since the mask works like it does, and FFMS2 is designed to run on a machine that uses two's complement integers, -1 means index all tracks (the default) and 0 means index none.<br />
+
:{{Par2|width|int|-1}}
Note that FFMS2's idea about what track has what number may be completely different from what any other application might think.
+
:{{Par2|height|int|-1}}
 +
::Sets the resolution of the output video, in pixels. Setting either dimension to less than or equal to zero (which is the default) means the resolution of the first decoded video frame is used for that dimension. These parameters are mostly useful because FFMS2 supports video streams that change resolution mid-stream; since Avisynth does not, these parameters are used to set single resolution for the output.  
  
{{Par|dumpmask|int|0}}
+
:{{Par2|resizer|string|"BICUBIC"}}
The same as indexmask, but the tracks flagged by this mask are dumped to disk as decompressed Wave64 files. This mask overrides indexmask if set to nonzero (more specifically, they are bitwise OR'ed together), since dumping a track indexes it at the same time.
+
::The resizing algorithm to use if rescaling the image is necessary. If the video uses subsampled chroma but your chosen output colorspace does not, the chosen resizer will be used to upscale the chroma planes, even if you did not request an image rescaling. The available choices are <code>FAST_BILINEAR</code>, <code>BILINEAR</code>, <code>BICUBIC</code> (default), <code>X</code>, <code>POINT</code>, <code>AREA</code>, <code>BICUBLIN</code>, <code>GAUSS</code>, <code>SINC</code>, <code>LANCZOS</code> and <code>SPLINE</code>. Note that <code>SPLINE</code> is completely different from Avisynth's builtin Spline [[Resize|resizers]].  
  
{{Par|audiofile|string|"%sourcefile%.%trackzn%.w64"}}
+
:{{Par2|colorspace|string|""}}
A string representing a filename template that determines where the audio tracks set to be dumped by the <tt>dumpmask</tt> will be written. You can use a number of variables here; make sure you include a track number variable if you're dumping multiple tracks, or you'll get really weird results when FFMS2 tries to write multiple tracks to the same file. Available variables:
+
::Convert the output from whatever it was to the given colorspace, which can be one of <code>YV12</code>, <code>YUY2</code>, <code>RGB24</code> or <code>RGB32</code>. Setting this to an empty string (the default) means keeping the same colorspace as the input.  
  
:'''%sourcefile%''' - same as the source argument, i.e. the file the audio is decoded from
+
:{{Par2|rffmode|int|0}}
:'''%trackn%''' - the track number
+
::Controls how RFF flags in the video stream are treated (RFF = ''Repeat First Field''; used in 3:2 pulldown<sup>[http://wayback.archive.org/web/20150120040340/http://msdn.microsoft.com/en-us/library/windows/desktop/aa367729%28v=vs.85%29.aspx]</sup>). In other words, it's equivalent to the "field operation" mode switch in [[DVD2AVI]]/[[DGIndex]]. Valid modes are:
:'''%trackzn%''' - the track number, zero padded to two digits
+
::*0: Ignore all flags (the default mode).
:'''%samplerate%''' - sample rate in Hertz
+
::*1: Honor all pulldown flags.
:'''%channels%''' - number of channels
+
::*2: Equivalent to DVD2AVI's "force film" mode.
:'''%bps%''' - bits per sample
+
::Note that using modes 1 or 2 will make FFMS2 throw an error if the video stream has no RFF flags at all. When using either of those modes, it will also make the output be assumed as CFR, disallow vertical scaling and disallow setting the output colorspace. <code>FFPICT_TYPE</code> will also not be set as the output is a combination of several frames. Other subtle behavior changes may also exist.
:'''%delay%''' - delay, or more exactly the first timestamp encountered in the audio stream
+
  
 +
:{{Par2|adjustdelay|int|-1}}
 +
::Controls how audio delay is handled, i.e. what happens if the first audio sample in the file doesn't have a timestamp of zero. The following arguments are valid:
 +
::*-3: No adjustment is made; the first decodable audio sample becomes the first sample in the output.
 +
::*-2: Samples are created (with silence) or discarded so that sample 0 in the decoded audio starts at time zero.
 +
::*-1: Samples are created (with silence) or discarded so that sample 0 in the decoded audio starts at the same time as frame 0 of the first video track. This is the default, and probably what most people want.
 +
::*Any integer >= 0: Same as -1, but adjust relative to the video track with the given track number instead. If the provided track number isn't a video track, an error is raised.
 +
::-2 obviously does the same thing as -1 if the first video frame of the first video track starts at time zero. In some containers this will always be the case, in others (most notably 188-byte MPEG TS) it will almost never happen.
  
{{Par|errorhandling|int|3}}
+
:{{Par2|utf8|bool|false}}
Controls what happens if an audio decoding error is encountered during indexing. Possible values are:
+
::If set to true, this filter will assume that the .avs script is encoded as UTF-8 and therefore interpret all filenames as UTF-8 encoded strings. This makes it possible to open files with odd filenames that otherwise would not be openable.  
  
:'''0:''' Raise an error and abort indexing. No index file is written.
+
::'''NOTE:''' You must make sure you save the .avs file without a BOM (byte-order marker) or Avisynth will refuse to open it. Notepad will write a BOM, so use something else.
:'''1:''' Clear the affected track (effectively making it silent) and continue.
+
:'''2:''' Stop indexing the track but keep all the index entries so far, effectively ending the track where the error occured.
+
:'''3:''' Pretend it's raining and continue anyway. This is the default; if you encounter odd noises in the audio, try mode 0 instead and see if it's FFMS2's fault.
+
  
{{Par|overwrite|bool|false}}
+
::You should also note that setting this parameter incorrectly will cause all file openings to fail unless your filenames are exclusively 7-bit ASCII compatible.  
If set to true, <tt>FFIndex()</tt> will reindex the source file and overwrite the index file even if the index file already exists and is valid. Mostly useful for trackmask changes and testing.
+
  
{{Par|utf8|bool|false}}
+
:{{Par2|varprefix|string|""}}
If set to true, FFMS will assume that the .avs script is encoded as UTF-8 and therefore interpret all filenames as UTF-8 encoded strings. This makes it possible to open files with funny filenames that otherwise would not be openable. You only need to set this parameter on the first FFMS2 function you call in a script; subsequent uses will have no further effect.<br />
+
::A string that is added as a prefix to all [[#Exported_AviSynth_variables|exported]] Avisynth variables. This makes it possible to differentiate between variables from different clips.  
'''NOTE:''' You must make sure you save the file without a BOM (byte-order marker) or Avisynth will refuse to open it. Notepad will write a BOM, so use something else.<br />
+
You should also note that setting this parameter incorrectly will cause all file openings to fail unless your filenames are exclusively 7-bit ASCII compatible.
+
  
{{Par|demuxer|string|"default"}}
+
* Note, ''FFMS2'' is a shorter name (added in v2.22) for ''FFmpegSource2''. The syntax is the same for both.
Forces FFMS to use a given demuxer, namely one of:
+
 
+
:'''default''': probe for the best source module, i.e. choose automatically. This is the default (duh).
+
:'''lavf''': use libavformat.
+
:'''matroska''': use Haali's Matroska parser. Obviously only works for Matroska and WebM files.
+
:'''haalimpeg''': use Haali's DirectShow MPEG TS/PS parser. Only works if Haali Media Splitter is installed and only on MPEG TS/PS files (.ts/.m2ts/.mpg/.mpeg).
+
:'''haaliogg:''' use Haali's DirectShow Ogg parser. As above, only works if Haali Media Splitter is installed, and only on Ogg files (.ogg/.ogm).
+
 
+
You should only use this parameter if you know exactly what you're doing and exactly why you want to force another demuxer.
+
 
+
 
+
===FFVideoSource===
+
'''FFVideoSource(string source, int track = -1, bool cache = true, string cachefile = source + ".ffindex", int fpsnum = -1, int fpsden = 1, string pp = "", int threads = -1, string timecodes = "", int seekmode = 1, int rffmode = 0, int width = -1, int height = -1, string resizer = "BICUBIC", string colorspace = "", bool utf8 = false, string varprefix = "")'''
+
  
 +
=== Other Functions ===
 +
For complete documentation see the [http://github.com/FFMS/ffms2/blob/master/doc/ffms2-avisynth.md#function-reference FFMS2 GitHub page].
 +
{{PluginFilterTable2}}
 +
{{PluginFilterRow|FFmpegSource|FFIndex|
 +
Indexes a number of tracks in a given source file and writes the index file to disk, where it can be picked up and used by <tt>FFVideoSource</tt> or <tt>FFAudioSource</tt>.
 +
|
 +
}}
 +
{{PluginFilterRow|FFmpegSource|FFAudioSource|
 +
Opens audio. Invokes indexing of all tracks if no valid index file is found, or if the requested track isn't present in the index.
 +
|
 +
}}
 +
{{PluginFilterRow|FFmpegSource|FFVideoSource|
 
Opens video. Will invoke indexing of all video tracks (but no audio tracks) if no valid index file is found.
 
Opens video. Will invoke indexing of all video tracks (but no audio tracks) if no valid index file is found.
 +
| [[RGB24]], [[RGB32]], [[YUY2]], [[Y8]], [[YV12]], [[YV16]], [[YV24]], [[YV411]]
 +
}}
 +
{{PluginFilterRow|FFmpegSource|FFmpegSource2|
 +
A convenience function that combines the functionality of '''FFVideoSource''' and '''FFAudioSource''' (see above).
 +
| [[RGB24]], [[RGB32]], [[YUY2]], [[Y8]], [[YV12]], [[YV16]], [[YV24]], [[YV411]]
 +
}}
 +
{{PluginFilterRow|FFmpegSource|FFMS2|
 +
A shorter '''FFmpegSource2''' alias, this feature was added in v2.22.
 +
| [[RGB24]], [[RGB32]], [[YUY2]], [[Y8]], [[YV12]], [[YV16]], [[YV24]], [[YV411]]
 +
}}
 +
{{PluginFilterRow|FFmpegSource|FFImageSource|
 +
A convenience alias for '''FFVideoSource''', with the options set optimally for using it as an image reader. Disables caching and seeking for maximum compatiblity.
 +
| [[RGB24]], [[RGB32]], [[YUY2]], [[Y8]], [[YV12]], [[YV16]], [[YV24]], [[YV411]]
 +
}}
 +
{{PluginFilterRow|FFmpegSource|FFSetLogLevel|
 +
Sets the FFmpeg logging level, i.e. how much diagnostic spam it prints to STDERR.
 +
|
 +
}}
 +
{{PluginFilterRow|FFmpegSource|FFGetLogLevel|
 +
Returns the current log level, as an integer.
 +
|
 +
}}
 +
{{PluginFilterRow|FFmpegSource|FFGetVersion|
 +
Returns the '''FFMS2''' version, as a string.
 +
|
 +
}}
 +
{{PluginFilterRowNote|
 +
'''Note''': the following functions are provided by <tt>[http://raw.githubusercontent.com/FFMS/ffms2/master/etc/FFMS2.avsi FFMS2.avsi]</tt> and are not available unless that script has been imported or [[Plugins#Plugin_Autoload_and_Name_Precedence|autoloaded]].
 +
}}
 +
{{PluginFilterRow|FFmpegSource|FFFormatTime|
 +
A helper function used to format a time given in milliseconds into a h:mm:ss.ttt string. Used internally by '''FFInfo'''.
 +
|
 +
}}
 +
{{PluginFilterRow|FFmpegSource|FFInfo|
 +
A helper function similar to Avisynth's internal [[Info|Info()]] function; shows general information about the current frame.
 +
|
 +
}}
 +
|}
 +
</div>
  
====Arguments====
+
== Exported AviSynth variables ==
{{Par|source|string|filename}}
+
<div style="max-width:62em" >
The source file to open.
+
All variable names are prefixed by the {{FuncArg|varprefix}} argument to the respective '''FFVideoSource''' or '''FFAudioSource''' call that generated them.  
  
{{Par|track|int|-1}}
+
'''NOTE''': these exported variables are mostly [[Runtime_environment|Runtime variables]], requiring [[ScriptClip]] etc to read them.
The video track number to open, as seen by the relevant demuxer. Track numbers start from zero, and are guaranteed to be countinous (i.e. there must be a track 1 if there is a track 0 and a track 2). -1 means open the first video track. Note that FFMS2's idea about what track has what number may (or may not) be completely different from what some other application might think. Trying to open an audio track with <tt>FFVideoSource</tt> will naturally fail.</dd>
+
<br>
 +
<br>
 +
<code>'''FFSAR_NUM, FFSAR_DEN, FFSAR'''</code>
  
{{Par|cache|bool|true}}
+
The playback aspect ratio specified by the container. <tt>FFSAR_NUM</tt> and <tt>FFSAR_DEN</tt> make up the rational number of the ratio; <tt>FFSAR</tt> is only provided for convenience and may not be set in case it cannot be calculated (i.e. if <tt>FFSAR_DEN</tt> is zero).
If set to true (the default), <tt>FFVideoSource</tt> will first check if the <tt>cachefile</tt> contains a valid index, and if it does, that index will be used. If no index is found, all video tracks will be indexed, and the indexing data will be written to <tt>cachefile</tt> afterwards. If set to false, <tt>FFVideoSource</tt> not look for an existing index file; instead all video tracks will be indexed when the script is opened, and the indexing data will be discarded after the script is closed; you will have to index again next time you open the script.
+
<br>
 +
<br>
  
{{Par|cachefile|string|source + ".ffindex"}}
+
<code>'''FFCROP_LEFT, FFCROP_RIGHT, FFCROP_TOP, FFCROP_BOTTOM'''</code>
The filename of the index file (where the indexing data is saved). Defaults to <tt>sourcefilename.ffindex</tt>. Note that if you didn't change this parameter from its default value and <tt>FFVideoSource</tt> encounters an index file that doesn't seem to match the file it's trying to open, it will automatically reindex and then overwrite the old index file. On the other hand, if you <em>do</em> change it, <tt>FFVideoSource</tt> will assume you have your reasons and throw an error instead if the index doesn't match the file.
+
  
{{Par|fpsnum|int|-1}}
+
The on-playback cropping specified by the container.
{{Par|fpsden|int|1}}
+
<br>
Forces a given (constant) framerate, expressed as a rational number where <tt>fpsnum</tt> is the numerator and <tt>fpsden</tt> is the denominator. Used for VFR to CFR conversion, as it will make <tt>FFVideoSource</tt> drop or duplicate frames to convert VFR to CFR if <tt>fpsnum</tt> is greater than 0. Setting <tt>fpsnum</tt> to a number less than or equal to zero means no frames will be dropped or duplicated.
+
<br>
  
{{Par|pp|string|"" [DEPRECATED]}}
+
<code>'''FFCOLOR_SPACE'''</code>
Sets a chain of postprocessing filters, expressed as a string (see the "PP string format" section below). Mostly useful to do quantizer-based deblocking/deringing, but can also do simple deinterlacing and a few other odd things.
+
  
{{Par|threads|int|-1}}
+
The colorimetry the input claims to be using. Only meaningful for YUV inputs. The source for this variable is a metadata flag that can arbitrarily be set or manipulated at will by incompetent users or buggy programs without changing the actual video content, so blindly trusting its correctness is not recommended.
The number of decoding threads to request from libavcodec. Setting it to less than or equal to zero means it defaults to the number of logical CPU's reported by Windows. Note that this setting might be completely ignored by libavcodec under a number of conditions; most commonly because a lot of decoders actually do not support multithreading. You may also have a libavcodec without threading support compiled in at all.
+
  
{{Par|timecodes|string|""}}
+
The value is exported as a cryptic numerical constant that matches the values in the MPEG-2 specification. You can find the gory details in the FFMS2 API documentation, but the important ones are:
Filename to write Matroska v2 timecodes for the opened video track to. If the file exists, it will be truncated and overwritten. Set to the empty string to disable timecodes writing (this is the default).
+
<div {{BoxWidthIndent|56|1}} >
 +
0: RGB (usually indicates the stream isn't actually YUV, but RGB flagged as YUV)
 +
1: ITU-R Rec.709
 +
2: Unknown or unspecified
 +
5 and 6: ITU-R Rec.601
 +
</div>
 +
<code>'''FFCOLOR_RANGE'''</code>
  
{{ParR|seekmode|int|1|1-3}}
+
The color range the input video claims to be using. Much like <tt>FFCOLOR_SPACE</tt>, the source for this variable is a metadata flag that can freely be set to arbitrary values, so trusting it blindly might not be a good idea.
Controls how seeking is done. Mostly useful for getting uncooperative files to work. Only has an effect on files opened with the libavformat demuxer; on other files the equivalent of mode 1 is always used. Valid modes are:
+
: '''-1:''' Linear access without rewind; i.e. will throw an error if each successive requested frame number isn't bigger than the last one. Only intended for opening images but might work on well with some obscure video format.
+
: '''0:''' Linear access (i.e. if you request frame <tt>n</tt> without having requested frames 0 to <tt>n-1</tt> in order first, all frames from 0 to <tt>n</tt> will have to be decoded before <tt>n</tt> can be delivered). The definition of slow, but should make some formats "usable".
+
: '''1:''' Safe normal. Bases seeking decisions on the keyframe positions reported by libavformat.
+
: '''2:''' Unsafe normal. Same as mode 1, but no error will be thrown if the exact seek destination has to be guessed.
+
: '''3:''' Aggressive. Seeks in the forward direction even if no closer keyframe is known to exist. Only useful for testing and containers where libavformat doesn't report keyframes properly.
+
  
{{ParR|rffmode|int|0|0-2}}
+
Note that using <tt>SWScale</tt>() or the width/height/colorspace parameters to '''FFVideoSource''' may under some circumstances change the output color range.
Controls how RFF flags in the video stream are treated; in other words it's equivalent to the "field operation" mode switch in DVD2AVI/DGIndex. Valid modes are:
+
<div {{BoxWidthIndent|56|1}} >
: '''0:''' Ignore all flags (the default mode).
+
0: Unknown/unspecified
: '''1:''' Honor all pulldown flags.
+
1: Limited range (usually 16-235)
: '''2:''' Equivalent to DVD2AVI's "force film" mode.
+
2: Full range (0-255)
 +
</div>
 +
<code>'''FFPICT_TYPE'''</code>
  
Note that using modes 1 or 2 will make <tt>FFVideoSource</tt> throw an error if the video stream has no RFF flags at all. When using either of those modes, it will also make the output be assumed as CFR, disallow vertical scaling and disallow setting the output colorspace. <tt>FFPICT_TYPE</tt> will also not be set as the output is a combination of several frames. Other subtle behavior changes may also exist.<br />
+
The picture type of the most recently requested frame as the ASCII number of the character listed below. Use <tt>Chr</tt>() to convert it to an actual letter in AviSynth. Use {{FuncArg|after_frame}}<tt>=true</tt> in AviSynth's conditional scripting for proper results. Only set when {{FuncArg|rffmode}}<tt>=0</tt>. The FFmpeg source definition of the characters:
Also note that "force film" is mostly useless and only here for completeness' sake, since if your source really is safe to force film on, using mode 0 will have the exact same effect while being considerably more efficient.
+
<div {{BoxWidthIndent|56|1}} >
 +
I: Intra
 +
P: Predicted
 +
B: Bi-dir predicted
 +
S: S(GMC)-VOP MPEG4
 +
i: Switching Intra
 +
p: Switching Predicted
 +
b: FF_BI_TYPE (no good explanation available)
 +
?: Unknown
 +
</div>
 +
<code>'''FFVFR_TIME'''</code>
  
{{Par|width|int|-1}}
+
The actual time of the source frame in milliseconds. Only set when no type of CFR conversion is being done ({{FuncArg|rffmode}} and {{FuncArg|fpsnum}} left at their defaults).
{{Par|height|int|-1}}
+
<br>
Sets the resolution of the output video, in pixels. Setting either dimension to less than or equal to zero means the resolution of the first decoded video frame is used for that dimension. These parameters are mostly useful because FFMS2 supports video streams that change resolution mid-stream; since Avisynth does not, these parameters are used to set single resolution for the output.
+
<br>
 +
<code>'''FFCHANNEL_LAYOUT'''</code>
  
{{Par|resizer|string|"BICUBIC"}}
+
The audio channel layout of the audio stream. This is exported as a very cryptic integer that is constructed in the same way as the <tt>dwChannelMask</tt> property of the Windows <tt>WAVEFORMATEXTENSIBLE</tt> struct. If you don't know what a <tt>WAVEFORMATEXTENSIBLE</tt> is or what the <tt>dwChannelMask</tt> does, don't worry about it.
The resizing algorithm to use if rescaling the image is necessary. If the video uses subsampled chroma but your chosen output colorspace does not, the chosen resizer will be used to upscale the chroma planes, even if you did not request an image rescaling. The available choices are <tt>FAST_BILINEAR</tt>, <tt>BILINEAR</tt>, <tt>BICUBIC</tt> (default), <tt>X</tt>, <tt>POINT</tt>, <tt>AREA</tt>, <tt>BICUBLIN</tt>, <tt>GAUSS</tt>, <tt>SINC</tt>, <tt>LANCZOS</tt> and <tt>SPLINE</tt>. Note that <tt>SPLINE</tt> is completely different from Avisynth's builtin Spline resizers.
+
<br>
 +
<br>
 +
<code>'''FFVAR_PREFIX'''</code>
  
{{Par|colorspace|string|""}}
 
Convert the output from whatever it was to the given colorspace, which can be one of <tt>YV12</tt>, <tt>YUY2</tt>, <tt>RGB24</tt> or <tt>RGB32</tt>. Setting this to an empty string (the default) means keeping the same colorspace as the input.
 
 
{{Par|utf8|bool|false}}
 
Does the same thing as in <tt>FFIndex()</tt>; see that function for details.
 
 
{{Par|varprefix|string|""}}
 
A string that is added as a prefix to all exported Avisynth variables. This makes it possible to differentiate between variables from different clips. For convenience the last used FFMS function in a script sets the global variable <tt>FFVAR_PREFIX</tt> to its own variable prefix so that <tt>FFInfo()</tt> can default to it.
 
 
 
===FFAudioSource===
 
'''FFAudioSource(string source, int track = -1, bool cache = true, string cachefile = source + ".ffindex", int adjustdelay = -1, bool utf8 = false, string varprefix = "")'''
 
 
Opens audio. Invokes indexing of all tracks if no valid index file is found, or if the requested track isn't present in the index.
 
 
====Arguments====
 
 
Are exactly the same as to <tt>FFVideoSource</tt>, with one exception:
 
 
{{Par|adjustdelay|int|-1}}
 
Controls how audio delay is handled, i.e. what happens if the first audio sample in the file doesn't have a timestamp of zero. The following arguments are valid:
 
 
:'''-3:''' No adjustment is made; the first decodable audio sample becomes the first sample in the output.
 
:'''-2:''' Samples are created (with silence) or discarded so that sample 0 in the decoded audio starts at time zero.
 
:'''-1:''' Samples are created (with silence) or discarded so that sample 0 in the decoded audio starts at the same time as frame 0 of the first video track. This is the default, and probably what most people want.
 
:'''Any integer &gt;= 0:''' Same as -1, but adjust relative to the video track with the given track number instead. If the provided track number isn't a video track, an error is raised.
 
 
-2 obviously does the same thing as -1 if the first video frame of the first video track starts at time zero. In some containers this will always be the case, in others (most notably 188-byte MPEG TS) it will almost never happen.
 
 
===FFmpegSource2===
 
'''FFmpegSource2(string source, int vtrack = -1, int atrack = -2, bool cache = true,    string cachefile = source + ".ffindex", int fpsnum = -1, int fpsden = 1,    string pp = "", int threads = -1, string timecodes = "", int seekmode = 1,    bool overwrite = false, int width = -1, int height = -1,    string resizer = "BICUBIC", string colorspace = "", int rffmode = 0,    int adjustdelay = -1, bool utf8 = false, string varprefix = "")'''
 
 
 
A convenience function that combines the functionality of <tt>FFVideoSource</tt> and <tt>FFAudioSource</tt>. The arguments do the same thing as in <tt>FFVideoSource</tt> and <tt>FFAudioSource</tt>; see those functions for details. <tt>vtrack</tt> and <tt>atrack</tt> are the video and audio track to open, respectively; setting <tt>atrack</tt> &lt;= -2 means audio is disabled.
 
 
'''Note:''' this function is provided by <tt>FFMS2.avsi</tt> and is not available unless that script has been imported or autoloaded.
 
 
===FFImageSource===
 
'''FFImageSource(string source, int width = -1, int height = -1,  string resizer = "BICUBIC", string colorspace = "", bool utf8 = false)'''
 
 
A convenience alias for <tt>FFVideoSource</tt>, with the options set optimally for using it as an image reader. Disables caching and seeking for maximum compatiblity.
 
 
'''Note:''' this function is provided by <tt>FFMS2.avsi</tt> and is not available unless that script has been imported or autoloaded.
 
 
===FFPP [DEPRECATED]===
 
'''FFPP(clip, string pp)'''
 
 
A postprocessing filter. See the <tt>pp</tt> argument to <tt>FFVideoSource</tt> and the "PP string format" section below. In general, using <tt>FFVideoSource</tt>'s <tt>pp</tt> argument instead of this function is recommended (if possible), since if it's used there it has access to video quantizers and can adapt better to the video, particularly when doing deblocking/deringing.
 
 
Postprocessing support is deprecated and will be removed in a future version of FFMS2.
 
 
===SWScale===
 
'''SWScale(clip, int width = -1, int height = -1, string resizer = "BICUBIC", string colorspace = "")'''
 
 
An image resizing and colorspace conversion filter. Does nothing special; it's almost always a better idea to just use Avisynth's builtins instead. Might potentially be useful for testing or odd experiments just because it does things in a different way from Avisynth. See the relevant arguments to <tt>FFVideoSource</tt> for details.
 
 
===FFFormatTime===
 
'''FFFormatTime(int ms)'''
 
 
A helper function used to format a time given in milliseconds into a h:mm:ss.ttt string. Used internally by <tt>FFInfo</tt>.
 
 
'''Note:''' this function is provided by <tt>FFMS2.avsi</tt> and is not available unless that script has been imported or autoloaded.
 
 
===FFInfo===
 
'''FFInfo(clip c, bool framenum = true, bool frametype = true, bool cfrtime = true, bool vfrtime = true, string varprefix = "")'''
 
 
A helper function similar to Avisynth's internal <tt>Info()</tt> function; shows general information about the current frame. Note that not all values are exported in all source modes, so some information may not always be shown. The arguments can be used to disable the drawing of certain information if so desired. Use the varprefix argument to determine which clip you want information about.
 
 
'''Note:''' this function is provided by <tt>FFMS2.avsi</tt> and is not available unless that script has been imported or autoloaded.
 
 
===FFSetLogLevel===
 
'''FFSetLogLevel(int Level = -8)'''
 
 
Sets the FFmpeg logging level, i.e. how much diagnostic spam it prints to STDERR. Since most applications that open Avisynth scripts do not provide a way to display things printed to STDERR, and since it's rather hard to make any sense of the printed messages unless you're quite familiar with FFmpeg internals, the usefulness of this function is rather limited for end users. It's mostly intended for debugging. Defaults to quiet (no messages printed); a list of meaningful values can be found in <tt>libavutil/log.h</tt>.
 
 
===FFGetLogLevel===
 
'''FFGetLogLevel()'''
 
 
Returns the current log level, as an integer.
 
 
==Exported Avisynth variables==
 
 
All variable names are prefixed by the <tt>varprefix</tt> argument to the respective <tt>FFVideoSource</tt> or <tt>FFAudioSource</tt> call that generated them.
 
 
'''FFSAR_NUM, FFSAR_DEN, FFSAR:'''
 
The playback aspect ratio specified by the container. FFSAR_NUM and FFSAR_DEN make up the rational number of the ratio and FFSAR is only provided for convenience and may not be set in case it cannot be calculated (FFSAR_DEN=0).
 
 
'''FFCROP_LEFT, FFCROP_RIGHT, FFCROP_TOP, FFCROP_BOTTOM:'''
 
The on playback cropping specified by the container.
 
 
'''FFCOLOR_SPACE:'''
 
The colorimetry the input claims to be using. Only meaningful for YUV inputs. The source for this variable is a metadata flag that can arbitrarily be set or manipulated at will by incompetent users or buggy programs without changing the actual video content, so blindly trusting its correctness is not recommended.<br />
 
The value is exported as a cryptic numerical constant that matches the values in the MPEG-2 specification. You can find the gory details in the FFMS2 API documentation, but the important ones are:<br />
 
:'''0:''' RGB (usually indicates the stream isn't actually YUV, but RGB flagged as YUV)<br />
 
:'''1:''' ITU-R Rec.709<br />
 
:'''2:''' Unknown or unspecified<br />
 
:'''5 and 6:''' ITU-R Rec.601<br />
 
 
'''FFCOLOR_RANGE:'''
 
The color range the input video claims to be using. Much like FFCOLOR_SPACE, the source for this variable is a metadata flag that can freely be set to arbitrary values, so trusting it blindly might not be a good idea.<br />
 
Note that using SWScale() or the width/height/colorspace parameters to FFVideoSource may under some circumstances change the output color range.<br />
 
:'''0:''' Unknown/unspecified<br />
 
:'''1:''' Limited-range (usually 16-235)<br />
 
:'''2:''' Full-range (0-255)<br />
 
 
'''FFPICT_TYPE:'''
 
The picture type of the most recently requested frame as the ascii number of the character listed below. Use Chr() to convert it to an actual letter in avisynth. Use after_frame=true in Avisynth's conditional scripting for proper results. Only set when rffmode=0. The FFmpeg source definition of the characters:
 
 
:'''I''': Intra
 
:'''P''': Predicted
 
:'''B''': Bi-dir predicted
 
:'''S''': S(GMC)-VOP MPEG4
 
:'''i''': Switching Intra
 
:'''p''': Switching Predicted
 
:'''b''': FF_BI_TYPE (no good explanation available)
 
:'''?''': Unknown
 
 
'''FFVFR_TIME:'''
 
The actual time of the source frame in milliseconds. Only set when no type of CFR conversion is being done (rffmode and fpsnum left at their defaults).
 
 
'''FFCHANNEL_LAYOUT:'''
 
The audio channel layout of the audio stream. This is exported as a very cryptic integer that is constructed in the same way as the <tt>dwChannelMask</tt> property of the Windows <tt>WAVEFORMATEXTENSIBLE</tt> struct. If you don't know what the <tt>WAVEFORMATEXTENSIBLE</tt> is or what the <tt>dwChannelMask</tt> does, don't worry about it.
 
 
'''FFVAR_PREFIX:'''
 
 
The variable prefix of the last called FFMS source function. Note that this is a global variable.
 
The variable prefix of the last called FFMS source function. Note that this is a global variable.
 
+
<br>
==PP string format==
+
<br>
 
+
== Archived Downloads ==
Available postprocessing filters:
+
<div style="max-width:82em; min-width:42em;" >
{| class="wikitable" style="margin:auto; background:#FFFFFF;"
+
{|class="wikitable sortable" style="height:100px; width:100%" border="1" cellpadding="4"
|-
+
!colspan="2"| Filters!!colspan="2" |Options!!rowspan="2"|Description
+
|-
+
! short !! long name !! short !!width="100"| long option
+
|-
+
| *  || *              ||a ||  autoq          || CPU power dependent enabler
+
|-
+
|    ||                ||c ||  chrom          || chrominance filtering enabled
+
|-
+
|    ||                ||y ||  nochrom        || chrominance filtering disabled
+
|-
+
|    ||                ||n ||  noluma        || luma filtering disabled
+
|-
+
| hb || hdeblock      || ||(2 threshold)      || horizontal deblocking filter; 1. difference factor: default=32, higher -&gt; more deblocking; 2. flatness threshold: default=39, lower -&gt; more deblocking the h &amp; v deblocking filters share these so you can't set different thresholds for h / v
+
|-
+
| vb || vdeblock      || ||(2 threshold)      || vertical deblocking filter
+
|-
+
| ha || hadeblock      || ||(2 threshold)      || horizontal deblocking filter
+
|-
+
| va || vadeblock      || ||(2 threshold)      || vertical deblocking filter
+
|-
+
| h1 || x1hdeblock    || ||                  || experimental h deblock filter 1
+
|-
+
| v1 || x1vdeblock    || ||                  || experimental v deblock filter 1
+
|-
+
| dr || dering        || ||                  || deringing filter
+
|-
+
| al || autolevels    || ||                  || automatic brightness / contrast
+
|-
+
| f  || fullyrange    || ||                  || stretch luminance to (0..255)
+
|-
+
| lb || linblenddeint  || ||                  || linear blend deinterlacer
+
|-
+
| li || linipoldeint  || ||                  || linear interpolating deinterlace
+
|-
+
| ci || cubicipoldeint || ||                  || cubic interpolating deinterlacer
+
|-
+
| md || mediandeint    || ||                  || median deinterlacer
+
|-
+
| fd || ffmpegdeint    || ||                  || ffmpeg deinterlacer
+
|-
+
| l5 || lowpass5      || ||                  || FIR lowpass deinterlacer
+
|-
+
| de || default        || ||                  || hb:a,vb:a,dr:a
+
|-
+
| fa || fast          || ||                  || h1:a,v1:a,dr:a
+
|-
+
| ac ||                || ||                  || ha:a:128:7,va:a,dr:a
+
 
|-
 
|-
| tn || tmpnoise      || ||(3 threshold)      || temporal noise reducer 1. &lt;= 2. &lt;= 3. larger -&gt; stronger filtering
+
!class="unsortable" width=12%| Version
 +
!class="unsortable" width=25%| Download
 +
!class="unsortable" width=25%| Mirror
 +
!class="unsortable"| Comments
 
|-
 
|-
| fq || forceQuant    || ||&lt;quantizer&gt;  || force quantizer
+
|ffms2-r1275+2-20190811
 +
|[https://www.mediafire.com/file/9dmplqvm17wpre0/ffms2-r1275+2-20190811.7z/file ffms2-r1275+2-20190811.7z]
 +
|
 +
|
 +
* Update to FFmpeg 4.2.
 +
* Switch to libdav1d for AV1 decoding.
 +
* Compiled by [https://forum.doom9.org/showthread.php?p=1881331#post1881331 HolyWu]
 
|-
 
|-
 +
|
 +
|
 +
|
 +
|
 
|}
 
|}
 +
<br>
  
===Usage===
+
==C Plugin==
 +
The C plugin supports the additional [[planar]] colorspaces in AviSynth 2.6. Also starting with <tt>r940+64</tt> it removes the Matroska demuxer too. This means that the *only* demuxer this build of FFMS2 uses is LAVF. The test this time is whether VP8 (and maybe VP9) bearing WebM files can be used correctly with the LAVF demuxer.<br>
 +
*'''Discussion''' - [https://forum.doom9.org/showthread.php?t=175173 Doom9 Thread]
  
<nowiki><filterName>[:<option>[:<option>...]][[,|/][-]<filterName>[:<option>...]]... </nowiki>
+
*'''Download''' - [https://www.mediafire.com/file/oicbdrc4malqzzn/ffms2_r1327%2B119-avs%2Bvsp.7z FFMS2 C-plugin 1327+119]
  
long form example:
+
<span style="color:red">'''Note:'''</span> C-plugins must be loaded using [[Plugins#LoadCPlugin|LoadCPlugin]].
vdeblock:autoq/hdeblock:autoq/linblenddeint    default,-vdeblock
+
<br>
short form example:
+
</div>
vb:a/hb:a/lb                                  de,-vb
+
more examples:
+
tn:64:128:256
+
  
[[Category:Plugins]]
+
== External Links ==
 +
<div style="max-width:62em" >
 +
*[https://forum.doom9.org/showthread.php?t=127037 Doom9 Forum] - FFmpegSource discussion.
 +
*[https://github.com/FFMS/ffms2 GitHub] - Source code repository.
 +
<br>
 +
</div>
 +
-----------------------------------------------
 +
'''Back to [[External_filters#Source_Filters|External Filters]] &larr;'''

Revision as of 02:13, 14 August 2019

Abstract
Author Myrsloik, et al.
Version v2.23.1
Download FFMS2 v2.23.1
Alt. Download 10bithack version
Documentation User Manual
Category Source filters
License MIT / binary is GPLv3
Discussion Doom9 Thread

Contents

Description

Opens files using FFmpeg and nothing else. May be frame accurate on good days. The source is MIT licensed and can be obtained from the GitHub repository. The precompiled binary is GPL3 licensed.

Requirements

(10-bit formats are supported with the 10bithack version - see alternate download above)

Limitations

  • Because of LAVF's demuxer, most raw streams (such as elementary h264 and other mpeg video streams) will fail to work properly.
  • FFAudioSource will have to remake any index implicitly created by FFVideoSource and therefore code like

  AudioDub( FFVideoSource(X), FFAudioSource(X) )
will require two indexing passes. Apart from the time consumed this is harmless. To work around it open the audio first:
  A = FFAudioSource(X)
  V = FFVideoSource(X)
  AudioDub(V, A)
(FFmpegSource2 does this for you with a single function call) or use FFIndex, like so:
  FFIndex(X)
  AudioDub( FFVideoSource(X), FFAudioSource(X) ).

  • Interlaced H.264 mostly works these days, but seeking may occasionally result in corruption.
  • Transport Streams will not decode reliably without seekmode -1.
  • Open-GOP H.264 will sometimes produces corruption when seeking.

Known Issues

(NOTE this section does not appear in the latest documentation and may be obsolete)

  • Interlaced H.264 is decoded in an odd way; each field gets its own full-height frame and the fieldrate is reported as the framerate, and furthermore one of the fields (odd or even) may "jump around". To get the correct behavior, you can try setting fpsnum and fpsden so that the framerate is halved (may or may not work). This issue is caused by libavcodec.

Compatibility

Video

  • AVI, MKV, MP4, FLV: Frame accurate
  • WMV: Frame accurate(?) but avformat seems to pick keyframes relatively far away
  • OGM: Frame accurate(?)
  • VOB, MPG: Seeking seems to be off by one or two frames now and then
  • M2TS, TS: Seeking seems to be off a few frames here and there
    • As MP4 container supports MPEG2/4 video stream, when seeking is off, you can try copying the stream to MP4 container (maybe without audio.) With FFmpeg: ffmpeg -i file.m2ts -c:v copy -an file.mp4. You might have to specify -fflags +genpts before -i.
  • Image files: Most formats can be opened if seekmode=-1 is set, no animation support

Audio

Seeking should be sample-accurate with most codecs in AVI, MKV, MP4 and FLV.

Decoding linearly will almost always give correct results, and forward-seeks from trimming should result in at most a few hundred samples of corruption.

Indexing and You

Before FFMS2 can open a file, it must be indexed first so that keyframe/sample positions are known and seeking is easily accomplished. This is done automatically when using FFVideoSource or FFAudioSource, but if you want to you can invoke the indexing yourself by calling FFIndex, or by running ffmsindex.exe. By default the index is written to a file so it can be reused the next time you open the same file, but this behavior can be turned off if desired.

If you wonder why FFMS2 takes so long opening files, the indexing is the answer. If you want a progress report on the indexing, you can use the supplied ffmsindex.exe command line program.

Function Reference

FFmpegSource2

FFmpegSource2(string source [, int vtrack, int atrack ,
     bool cache, string cachefile, int fpsnum, int fpsden,
     int threads, string timecodes, int seekmode, bool overwrite,
     int width, int height, string resizer, string colorspace,
     int rffmode, int adjustdelay, bool utf8, string varprefix ] )

string  source = (required)
Path of the file to be opened.
int  vtrack = -1
The video track number to open, as seen by the relevant demuxer. Track numbers start from zero, and are guaranteed to be continous (i.e. there must be a track 1 if there is a track 0 and a track 2). vtrack=-1 (the default) means open the first video track. Note that this filter's idea about what track has what number may be completely different from what some other application might think.
int  atrack = -2
The audio track to open. atrack=-1 means select the first available track. atrack=-2 (the default) means audio is disabled.
bool  cache = true
If set to true (the default), this filter will first check if the cachefile contains a valid index, and if it does, that index will be used. If no index is found, all video tracks will be indexed, and the indexing data will be written to cachefile afterwards. If set to false, this filter will not look for an existing index file; instead all video tracks will be indexed when the script is opened, and the indexing data will be discarded after the script is closed; you will have to index again next time you open the script.
string  cachefile = source + ".ffindex"
The filename of the index file (where the indexing data is saved). Defaults to sourcefilename.ffindex.
int  fpsnum = -1
int  fpsden = 1
Controls the framerate of the output; used for VFR to CFR conversions. If fpsnum is less than or equal to zero (the default), the output will contain the same frames that the input did, and the frame rate reported to Avisynth will be set based on the input clip's average frame duration. If fpsnum is greater than zero, this filter will force a constant frame rate, expressed as a rational number where fpsnum is the numerator and fpsden is the denominator. This may naturally cause dropped or duplicated frames to achieve the desired frame rate, and the output is not guaranteed to have the same number of frames that the input did.
int  threads = -1
The number of decoding threads to request from libavcodec. Setting it to less than or equal to zero means it defaults to the number of logical CPUs as reported by Windows. Note that this setting might be completely ignored under a number of conditions; most commonly because a lot of decoders actually do not support multithreading. Default -1.
string  timecodes = ""
Filename to write Matroska v2 timecodes for the opened video track. If the file exists, it will be truncated and overwritten. Set to the empty string to disable timecodes writing (this is the default).
int  seekmode = 1
Controls how seeking is done. Mostly useful for getting uncooperative files to work. Valid modes are:
  • -1: Linear access without rewind; i.e. will throw an error if each successive requested frame number isn't bigger than the last one. Only intended for opening images but might work on well with some obscure video format.
  • 0: Linear access (i.e. if you request frame n without having requested all frames from 0 to n-1 in order first, all frames from 0 to n will have to be decoded before n can be delivered). The definition of slow, but should make some formats "usable".
  • 1: Safe normal (the default). Bases seeking decisions on the keyframe positions reported by libavformat.
  • 2: Unsafe normal. Same as mode 1, but no error will be thrown if the exact seek destination has to be guessed.
  • 3: Aggressive. Seeks in the forward direction even if no closer keyframe is known to exist. Only useful for testing and containers where libavformat doesn't report keyframes properly.
bool  overwrite = false
If set to true, this filter will reindex the source file and overwrite the index file even if the index file already exists and is valid. Mostly useful for trackmask changes and testing.
int  width = -1
int  height = -1
Sets the resolution of the output video, in pixels. Setting either dimension to less than or equal to zero (which is the default) means the resolution of the first decoded video frame is used for that dimension. These parameters are mostly useful because FFMS2 supports video streams that change resolution mid-stream; since Avisynth does not, these parameters are used to set single resolution for the output.
string  resizer = "BICUBIC"
The resizing algorithm to use if rescaling the image is necessary. If the video uses subsampled chroma but your chosen output colorspace does not, the chosen resizer will be used to upscale the chroma planes, even if you did not request an image rescaling. The available choices are FAST_BILINEAR, BILINEAR, BICUBIC (default), X, POINT, AREA, BICUBLIN, GAUSS, SINC, LANCZOS and SPLINE. Note that SPLINE is completely different from Avisynth's builtin Spline resizers.
string  colorspace = ""
Convert the output from whatever it was to the given colorspace, which can be one of YV12, YUY2, RGB24 or RGB32. Setting this to an empty string (the default) means keeping the same colorspace as the input.
int  rffmode = 0
Controls how RFF flags in the video stream are treated (RFF = Repeat First Field; used in 3:2 pulldown[1]). In other words, it's equivalent to the "field operation" mode switch in DVD2AVI/DGIndex. Valid modes are:
  • 0: Ignore all flags (the default mode).
  • 1: Honor all pulldown flags.
  • 2: Equivalent to DVD2AVI's "force film" mode.
Note that using modes 1 or 2 will make FFMS2 throw an error if the video stream has no RFF flags at all. When using either of those modes, it will also make the output be assumed as CFR, disallow vertical scaling and disallow setting the output colorspace. FFPICT_TYPE will also not be set as the output is a combination of several frames. Other subtle behavior changes may also exist.
int  adjustdelay = -1
Controls how audio delay is handled, i.e. what happens if the first audio sample in the file doesn't have a timestamp of zero. The following arguments are valid:
  • -3: No adjustment is made; the first decodable audio sample becomes the first sample in the output.
  • -2: Samples are created (with silence) or discarded so that sample 0 in the decoded audio starts at time zero.
  • -1: Samples are created (with silence) or discarded so that sample 0 in the decoded audio starts at the same time as frame 0 of the first video track. This is the default, and probably what most people want.
  • Any integer >= 0: Same as -1, but adjust relative to the video track with the given track number instead. If the provided track number isn't a video track, an error is raised.
-2 obviously does the same thing as -1 if the first video frame of the first video track starts at time zero. In some containers this will always be the case, in others (most notably 188-byte MPEG TS) it will almost never happen.
bool  utf8 = false
If set to true, this filter will assume that the .avs script is encoded as UTF-8 and therefore interpret all filenames as UTF-8 encoded strings. This makes it possible to open files with odd filenames that otherwise would not be openable.
NOTE: You must make sure you save the .avs file without a BOM (byte-order marker) or Avisynth will refuse to open it. Notepad will write a BOM, so use something else.
You should also note that setting this parameter incorrectly will cause all file openings to fail unless your filenames are exclusively 7-bit ASCII compatible.
string  varprefix = ""
A string that is added as a prefix to all exported Avisynth variables. This makes it possible to differentiate between variables from different clips.
  • Note, FFMS2 is a shorter name (added in v2.22) for FFmpegSource2. The syntax is the same for both.

Other Functions

For complete documentation see the FFMS2 GitHub page.

Filter Description Color format
FFIndex

Indexes a number of tracks in a given source file and writes the index file to disk, where it can be picked up and used by FFVideoSource or FFAudioSource.

FFAudioSource

Opens audio. Invokes indexing of all tracks if no valid index file is found, or if the requested track isn't present in the index.

FFVideoSource

Opens video. Will invoke indexing of all video tracks (but no audio tracks) if no valid index file is found.

RGB24, RGB32, YUY2, Y8, YV12, YV16, YV24, YV411
FFmpegSource2

A convenience function that combines the functionality of FFVideoSource and FFAudioSource (see above).

RGB24, RGB32, YUY2, Y8, YV12, YV16, YV24, YV411
FFMS2

A shorter FFmpegSource2 alias, this feature was added in v2.22.

RGB24, RGB32, YUY2, Y8, YV12, YV16, YV24, YV411
FFImageSource

A convenience alias for FFVideoSource, with the options set optimally for using it as an image reader. Disables caching and seeking for maximum compatiblity.

RGB24, RGB32, YUY2, Y8, YV12, YV16, YV24, YV411
FFSetLogLevel

Sets the FFmpeg logging level, i.e. how much diagnostic spam it prints to STDERR.

FFGetLogLevel

Returns the current log level, as an integer.

FFGetVersion

Returns the FFMS2 version, as a string.

Note: the following functions are provided by FFMS2.avsi and are not available unless that script has been imported or autoloaded.

FFFormatTime

A helper function used to format a time given in milliseconds into a h:mm:ss.ttt string. Used internally by FFInfo.

FFInfo

A helper function similar to Avisynth's internal Info() function; shows general information about the current frame.

Exported AviSynth variables

All variable names are prefixed by the varprefix argument to the respective FFVideoSource or FFAudioSource call that generated them.

NOTE: these exported variables are mostly Runtime variables, requiring ScriptClip etc to read them.

FFSAR_NUM, FFSAR_DEN, FFSAR

The playback aspect ratio specified by the container. FFSAR_NUM and FFSAR_DEN make up the rational number of the ratio; FFSAR is only provided for convenience and may not be set in case it cannot be calculated (i.e. if FFSAR_DEN is zero).

FFCROP_LEFT, FFCROP_RIGHT, FFCROP_TOP, FFCROP_BOTTOM

The on-playback cropping specified by the container.

FFCOLOR_SPACE

The colorimetry the input claims to be using. Only meaningful for YUV inputs. The source for this variable is a metadata flag that can arbitrarily be set or manipulated at will by incompetent users or buggy programs without changing the actual video content, so blindly trusting its correctness is not recommended.

The value is exported as a cryptic numerical constant that matches the values in the MPEG-2 specification. You can find the gory details in the FFMS2 API documentation, but the important ones are:

0: RGB (usually indicates the stream isn't actually YUV, but RGB flagged as YUV)
1: ITU-R Rec.709
2: Unknown or unspecified
5 and 6: ITU-R Rec.601

FFCOLOR_RANGE

The color range the input video claims to be using. Much like FFCOLOR_SPACE, the source for this variable is a metadata flag that can freely be set to arbitrary values, so trusting it blindly might not be a good idea.

Note that using SWScale() or the width/height/colorspace parameters to FFVideoSource may under some circumstances change the output color range.

0: Unknown/unspecified
1: Limited range (usually 16-235)
2: Full range (0-255)

FFPICT_TYPE

The picture type of the most recently requested frame as the ASCII number of the character listed below. Use Chr() to convert it to an actual letter in AviSynth. Use after_frame=true in AviSynth's conditional scripting for proper results. Only set when rffmode=0. The FFmpeg source definition of the characters:

I: Intra
P: Predicted
B: Bi-dir predicted
S: S(GMC)-VOP MPEG4
i: Switching Intra
p: Switching Predicted
b: FF_BI_TYPE (no good explanation available)
?: Unknown

FFVFR_TIME

The actual time of the source frame in milliseconds. Only set when no type of CFR conversion is being done (rffmode and fpsnum left at their defaults).

FFCHANNEL_LAYOUT

The audio channel layout of the audio stream. This is exported as a very cryptic integer that is constructed in the same way as the dwChannelMask property of the Windows WAVEFORMATEXTENSIBLE struct. If you don't know what a WAVEFORMATEXTENSIBLE is or what the dwChannelMask does, don't worry about it.

FFVAR_PREFIX

The variable prefix of the last called FFMS source function. Note that this is a global variable.

Archived Downloads

Version Download Mirror Comments
ffms2-r1275+2-20190811 ffms2-r1275+2-20190811.7z
  • Update to FFmpeg 4.2.
  • Switch to libdav1d for AV1 decoding.
  • Compiled by HolyWu


C Plugin

The C plugin supports the additional planar colorspaces in AviSynth 2.6. Also starting with r940+64 it removes the Matroska demuxer too. This means that the *only* demuxer this build of FFMS2 uses is LAVF. The test this time is whether VP8 (and maybe VP9) bearing WebM files can be used correctly with the LAVF demuxer.

Note: C-plugins must be loaded using LoadCPlugin.

External Links



Back to External Filters
Personal tools