# FFmpegSource2 Documentation

Opens files using ffmpeg and nothing else. May be frame accurate on good days. The source is MIT licensed and can be obtained from https://spaceboyz.net/svn/aegisub/trunk/FFmpegSource2. The precompiled binary is GPL licensed. If you are religious you may consider this the second coming.

## Compatibility - Video

- AVI, MKV, MP4, FLV: Frame accurate
- WMV: Frame accurate(?) but avformat seems to pick keyframes relatively far away
- OGM: Messed up first frame and seeking produces smearing with seekmode=3, incredibly slow seeking without, remux to mkv or avi
- VOB: No rff flags applied, frame accurate?
- MPG: Seeking seems to be off by one or two frames now and then
- M2TS, TS: Linear access only (seekmode=-1)
- Image files: Most formats can be opened if seekmode=-1 is set

## Compatibility - Audio

- All formats are written to separate wave64 files
- No wave64 reader is provided

## Usage

FFIndex("string source, string cachefile = source + ".ffindex", int indexmask = 0, int dumpmask = 0, string audiofile = source, bool overwrite = false)
Used to invoke indexing separately and to write audio tracks to disk as wave64 files

FFVideoSource(string source, int track, bool cache = true, string cachefile = source + ".ffindex", int fpsnum = -1, int fpsden = 1, string pp, int threads = -1, string timecodes, int seekmode = 1)
Opens video, will invoke indexing with the defaults if no preexisting index is found

FFPP(clip, string pp)
Separate postprocessing which also seems to include a few simple deinterlacers

SWScale(clip, width = -1, height = -1, resizer = "BICUBIC", colorspace = "")
Separate postprocessing which also seems to include a few simple deinterlacers

source: Source file.

indexmask & dumpmask: Which audio tracks to index/write to disk. Dumping a track also implies indexing since the same work has to be done anyway. It is a binary mask meaning that 7 corresponds to writing tracks 1-3. Non-audio tracks are ignored. -1 writes all tracks.

audiofile: The base name to use for the decoded audio. Track number and delay is appended.

overwrite: Forces reindexing even if a valid index already exists. May be useful for trackmask changes or testing.

track: Track number as seen by the relevant demuxer, starts from 0, -1 means it will pick the first suitable track.

fpsnum & fpsden: For VFR -> CFR conversion. Setting fpsnum <= 0 means a 1:1 relation with the encoded frames.

timecodes: File to output timecodes to, if the file exists it will be overwritten.

cache: Write indexing information to a file for later use. This setting does not control if The video index is loaded which it always is if it exists.

cachefile Where to write the cache information.

pp: See the table below for a full description, an empty string means no processing. It is recommended to avoid the autoq option since it's currently unknown what effect it will have on the processing.

threads: Sets the number of decoder threads used. Defaults to the number of cpus reported by windows. Ignored by lavc if the used decoder doesn't implement it.

seekmode: Force how seeking is handled, has no effect on matroska files which always use the equivalent of seekmode=1
-1: linear access without rewind, 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, the definition of slow but should make some formats "usable"
1: safe normal, bases seeking decisions on the reported keyframe positions
2: unsafe normal, same as 1 but no error will be thrown if the exact destination has to be guessed
3: aggressive, seek in the forward direction even if no closer keyframe is known to exist, only useful for testing and containers where avformat doesn't report keyframes properly

width & height: Width and height to resize to. Value below or equal to 0 is the same as specifying the input dimensions.

resizer: Selects the resizer used for resampling the chroma planes and normal resizing. The available methods are: FAST_BILINEAR, BILINEAR, BICUBIC, X, POINT, AREA, BICUBLIN, GAUSS, SINC, LANCZOS and SPLINE.

colorspace: The colorspace to convert to. The names are YV12, YUY2, RGB24, RGB32 and the empty string for same as input.

## PP string format

    Available postprocessing filters:
    Filters                        Options
    short  long name       short   long option     Description
    *      *               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 -> more deblocking
           2. flatness threshold: default=39, lower -> more deblocking
                           the h & 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. <= 2. <= 3.            larger -> stronger filtering
    fq     forceQuant                   force quantizer
    Usage:
    [:[:...]][[,|/][-][:...]]...
    long form example:
    vdeblock:autoq/hdeblock:autoq/linblenddeint    default,-vdeblock
    short form example:
    vb:a/hb:a/lb                                   de,-vb
    more examples:
    tn:64:128:256

## Compiling

zlib from http://www.zlib.net/

FFmpeg svn from http://ffmpeg.mplayerhq.hu/

Required FFmpeg Configuration: ./configure --enable-memalign-hack --enable-gpl --enable-swscale --enable-postproc

Suggested Additional Options: --enable-w32threads --disable-encoders --disable-muxers --disable-debug

Note that --enable-w32threads is required for multithreaded decoding to work.

## Changes

- 2.00 beta 3
  - Compiled with libfaad2 again (has anyone seen a single aac file lavc can open right now?)
  - More API changes (and even more are likely to come)
  - Several access violations and memory leaks on opening and indexing files fixed
  - Added a VFR to CFR mode
  - Readded FFAudioSource support for other containers (glitches still present now and then but no separate raw cache is required and possibly less buggy
  - Renamed the dll to FFMS2.dll, FFMS2 is now the official short name of the project
  - Updated FFmpeg to rev 15522
- 2.00 beta 2
  - More API changes (and more are likely to come)
  - Includes a simple CLI indexing application
  - FFIndex now takes a few more arguments
  - Readded FFAudioSource (only matroska supported for now)
  - Updated FFmpeg to rev 15396
- 2.00 beta 1
  - Can now be used as a stand alone library for making indices and retrieving frames
  - Rewrote most things
  - Updated FFmpeg to rev 15301