FFmpegSource

From Avisynth wiki
Jump to: navigation, search
Abstract
Author Myrsloik
Version v2.20
Download FFMS2 v2.20
Category Source filters
License MIT / binary is GPLv3
Discussion Doom9 Thread


Contents

Description

Opens files using FFmpeg and (almost) nothing else. May be frame accurate on good days. The source is MIT licensed and can be obtained from http://github.com/FFMS/ffms2/. The precompiled binary is GPL3 licensed.


Requirements

- AviSynth 2.5.8 or later
- Supported color formats: RGB24, RGB32, YUY2, YV12


Limitations

  • Requires 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.
  • Haali's splitter requires transport streams to but cut at packed boundaries. Use TsRemux to fix the stream if you get an error message complaining about this.
  • 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)

or use FFIndex(), like so:

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 fpsnum and fpsden 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 demuxer="lavf" in FFIndex and using seekmode=0 with FFVideoSource. 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

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.

Decoding linearly will almost always work correctly.

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 commandline program.

Function Reference

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, YV12
SWScale

An image resizing and colorspace conversion filter. Does nothing special; it's almost always a better idea to just use Avisynth's builtins instead.

RGB24, RGB32, YUY2, YV12
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.

FFmpegSource2

A convenience function that combines the functionality of FFVideoSource and FFAudioSource.

RGB24, RGB32, YUY2, YV12
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, YV12
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.

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.

External Links





Back to External Filters

Personal tools