Skip to main content

Inverse telecine filter for VapourSynth

Project description

VIVTC

VIVTC is a set of filters that can be used for inverse telecine. It is a rewrite of some of tritical's TIVTC filters.

.. function:: VFM(clip clip, int order[, int field=2, int mode=1, bint mchroma=1, int cthresh=9, int mi=80, bint chroma=1, int blockx=16, int blocky=16, int y0=16, int y1=16, float scthresh=12, int micmatch=1, bint micout=0, clip clip2]) :module: vivtc

VFM is a field matching filter that recovers the original progressive frames from a telecined stream. VFM's output will contain duplicated frames, which is why it must be further processed by a decimation filter, like VDecimate.

Unlike TFM, VFM does not have any postprocessing capabilities.

You can however script your own like this (make sure the deinterlacer and VFM reference field is the same to avoid jerkiness)::

  import vapoursynth as vs
  import functools

  input_clip = vs.core.std.BlankClip(format=vs.YUV420P8, length=1000, color=[255, 128, 128])

  def postprocess(n, f, clip, deinterlaced):
     if f.props['_Combed'] > 0:
        return deinterlaced
     else:
        return clip

  matched_clip = vs.core.vivtc.VFM(input_clip, 1)
  deinterlaced_clip = vs.core.eedi3.eedi3(matched_clip, field=1)
  postprocessed_clip = vs.core.std.FrameEval(matched_clip, functools.partial(postprocess, clip=matched_clip, deinterlaced=deinterlaced_clip), prop_src=matched_clip)
  decimated_clip = vs.core.vivtc.VDecimate(postprocessed_clip)
  decimated_clip.set_output()

VFM adds the following properties to every frame it outputs: VFMMics Array of five integers.

     It will contain the mic values for the five possible matches
     (p/c/n/b/u). Some of them may be unset (-1), depending on *micout*
     and *micmatch*.

     These numbers represent the highest concentration of combed pixels
     found in any block in the frame.

  _Combed
     1 if VFM thinks the frame is combed, 0 if not.

  VFMMatch
     Match used for the frame.

     0 = p

     1 = c

     2 = n

     3 = b

     4 = u

  VFMSceneChange
     1 if VFM thinks the frame is a scene change, 0 if not.

Parameters: clip Input clip. YUV420P8, YUV422P8, YUV440P8, YUV444P8, and GRAY8 are supported. Must have constant format and dimensions.

  order
     Sets the field order of the clip. Normally the field order is
     obtained from the ``_FieldBased`` frame property. This parameter
     is only used for those frames where the ``_FieldBased`` property
     has an invalid value or doesn't exist.

     If the field order is wrong, VFM's output will be visibly wrong
     in mode 0.

     0 - bottom field first

     1 - top field first

  field
     Sets the field to match from. This is the field that VFM will take
     from the current frame in case of p or n matches. It is recommended
     to make this the same as the field order, unless you experience
     matching failures with that setting. In certain circumstances
     changing the field that is used to match from can have a large
     impact on matching performance.

     0 - bottom field

     1 - top field

     2 - same as the field order

     3 - opposite of the field order

     0 and 1 will disregard the ``_FieldBased`` frame property. 2 and 3
     will adapt to the field order obtained from the ``_FieldBased``
     property.

     Default: 2.

  mode
     Sets the matching mode or strategy to use. Plain 2-way matching
     (option 0) is the safest of all the options in the sense that it won't
     risk creating jerkiness due to duplicate frames when possible, but if
     there are bad edits or blended fields it will end up outputting combed
     frames when a good match might actually exist. 3-way matching + trying
     the 4th/5th matches if all 3 of the original matches are detected as
     combed (option 5) is the most risky in terms of creating jerkiness,
     but will almost always find a good frame if there is one. The other
     settings (options 1, 2, 3, and 4) are all somewhere in between options
     0 and 5 in terms of risking jerkiness and creating duplicate frames vs.
     finding good matches in sections with bad edits, orphaned fields,
     blended fields, etc.
     
     Note that the combed condition here is not the same as the ``_Combed``
     frame property. Instead it's a combination of relative and absolute
     threshold comparisons and can still lead to the match being changed
     even when the ``_Combed`` flag is not set on the original frame.

     0 = 2-way match (p/c)
     
     1 = 2-way match + 3rd match on combed (p/c + n)
     
     2 = 2-way match + 3rd match (same order) on combed (p/c + u)
     
     3 = 2-way match + 3rd match on combed + 4th/5th matches if still combed (p/c + n + u/b)
     
     4 = 3-way match (p/c/n)
     
     5 = 3-way match + 4th/5th matches on combed (p/c/n + u/b)

     The parantheses at the end indicate the matches that would be used
     for each mode assuming order=1 and field=1.

     Default: 1.

  mchroma
     Sets whether or not chroma is included during the match comparisons.
     In most cases it is recommended to leave this enabled. Only if your
     clip has bad chroma problems such as heavy rainbowing or other
     artifacts should you set this to false. Setting this to false could
     also be used to speed things up at the cost of some accuracy.

     Default: true.

  cthresh
     This is the area combing threshold used for combed frame detection.
     This essentially controls how "strong" or "visible" combing must be
     to be detected. Larger values mean combing must be more visible and
     smaller values mean combing can be less visible or strong and still
     be detected. Valid settings are from -1 (every pixel will be detected
     as combed) to 255 (no pixel will be detected as combed). This is
     basically a pixel difference value. A good range is between 8 to 12.

     Default: 9.

  mi
     The number of combed pixels inside any of the *blockx* by *blocky*
     size blocks on the frame for the frame to be detected as combed.
     While *cthresh* controls how "visible" the combing must be, this
     setting controls "how much" combing there must be in any localized
     area (a window defined by the *blockx* and *blocky* settings) on the
     frame. The minimum is 0, the maximum is *blocky* * *blockx* (at which
     point no frames will ever be detected as combed).

     Default: 80.

  chroma
     Sets whether or not chroma is considered in the combed frame decision.
     Only disable this if your source has chroma problems (rainbowing, etc)
     that are causing problems for the combed frame detection with *chroma*
     enabled. Actually, using chroma=false is usually more reliable, except
     in case there is chroma-only combing in the source.

     Default: true.

  blockx

  blocky
     Sets the size of the window used during combed frame detection. This
     has to do with the size of the area in which *mi* number of pixels are
     required to be detected as combed for a frame to be declared combed.
     See the *mi* parameter description for more info. Possible values are
     any power of 2 between 4 and 512.

     Defaults: 16, 16.

  y0

  y1
     The rows from *y0* to *y1* will be excluded from the field matching
     decision.
     This can be used to ignore subtitles, a logo, or other things that may
     interfere with the matching.
     Set *y0* equal to *y1* to disable.

     Defaults: 16, 16.

  scthresh
     Sets the scenechange threshold as a percentage of maximum change on the
     luma plane.
     Good values are in the 8 to 14 range.

     Default: 12.

  micmatch
     When micmatch is greater than 0, tfm will take into account the mic
     values of matches when deciding what match to use as the final match.
     Only matches that could be used within the current matching mode are
     considered. micmatch has 3 possible settings:

     0 - disabled. Modes 1, 2 and 3 effectively become identical to mode 0.
     Mode 5 becomes identical to mode 4.

     1 - micmatching will be used only around scene changes. See the
     *scthresh* parameter.

     2 - micmatching will be used everywhere.

     Default: 1.

  micout
     If true, VFM will calculate the mic values for all possible matches
     (p/c/n/b/u).
     Otherwise, only the mic values for the matches allowed by *mode* will
     be calculated.

     Default: false.

  clip2
     Clip that VFM will use to create the output frames. If *clip2* is used,
     VFM will perform all calculations based on *clip*, but will copy the
     chosen fields from *clip2*. This can be used to work around VFM's video
     format limitations. For example if you have a YUV444P16 input clip::

        yv12 = vs.core.resize.Bicubic(clip=original, format=vs.YUV420P8)
        fieldmatched = vs.core.vivtc.VFM(clip=yv12, order=1, chroma=False, clip2=original)

     .. note::
        In this example chroma is ignored because the used conversion to YUV420P8
        will not accurately preserve it.

.. function:: VDecimate(clip clip[, int cycle=5, bint chroma=1, float dupthresh=1.1, float scthresh=15, int blockx=32, int blocky=32, clip clip2, string ovr="", bint dryrun=0]) :module: vivtc

VDecimate is a decimation filter. It drops one in every cycle frames -- the one that is most likely to be a duplicate (mode 0 in TDecimate).

Parameters: clip Input clip. Must have constant format and dimensions, known length, integer sample type, and bit depth between 8 and 16 bits per sample.

  cycle
     Size of a cycle, in frames. One in every *cycle* frames will be
     decimated.

     Default: 5.

  chroma
     Controls whether the chroma is considered when calculating frame
     difference metrics.

     Default: true when the input clip has chroma.

  dupthresh
     This sets the threshold for duplicate detection. If the difference
     metric for a frame is less than or equal to this value then it is
     declared a duplicate. This value is a percentage of maximum change
     for a block defined by the *blockx* and *blocky* values, so 1.1 means
     1.1% of maximum possible change.

     Default: 1.1.

  scthresh
     Sets the threshold for detecting scene changes. This value is a
     percentage of maximum change for the luma plane. Good values are
     between 10 and 15.

     Default: 15.

  blockx

  blocky
     Sets the size of the blocks used for metric calculations. Larger blocks
     give better noise suppression, but also give worse detection of small
     movements. Possible values are any power of 2 between 4 and 512.

     Defaults: 32, 32.

  clip2
     This has the same purpose as VFM's *clip2* parameter.

  ovr
     Text file containing overrides. This can be used to manually choose
     what frames get dropped. Lines starting with # are ignored.

     Drop a specific frame::

        314 -
        
     Drop every fourth frame, starting at frame 1001, up to frame 5403::
     
        1001,5403 +++-+

     The frame numbers apply to the undecimated input clip, of course.

     The decimation pattern must contain *cycle* characters.

     If the overrides mark more than one frame per cycle, the first frame
     marked for decimation in the cycle will be dropped.

  dryrun
     If true, VDecimate will not drop any frames. Instead, it will attach
     the following properties to every frame:
     
        VDecimateDrop
           1 if VDecimate would normally drop the frame, 0 otherwise.

        VDecimateMaxBlockDiff
           This is the highest absolute difference between the current
           frame and the previous frame found in any *blockx*\ \*\ *blocky*
           block. It is known in Yatta as "DMetric".

        VDecimateTotalDiff
           This is the absolute difference between the current frame and
           the previous frame.

     Default: false.

Large parts of this document were copied from "TFM - READ ME.txt" and "TDecimate - READ ME.txt", written by Kevin Stone (aka tritical).

Project details


Release history Release notifications | RSS feed

This version

2.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vapoursynth_vivtc-2.0.tar.gz (35.4 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

vapoursynth_vivtc-2.0-py3-none-win_amd64.whl (68.3 kB view details)

Uploaded Python 3Windows x86-64

vapoursynth_vivtc-2.0-py3-none-musllinux_1_2_x86_64.whl (37.9 kB view details)

Uploaded Python 3musllinux: musl 1.2+ x86-64

vapoursynth_vivtc-2.0-py3-none-musllinux_1_2_aarch64.whl (37.6 kB view details)

Uploaded Python 3musllinux: musl 1.2+ ARM64

vapoursynth_vivtc-2.0-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (37.6 kB view details)

Uploaded Python 3manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

vapoursynth_vivtc-2.0-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (37.7 kB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARM64manylinux: glibc 2.28+ ARM64

vapoursynth_vivtc-2.0-py3-none-macosx_11_0_arm64.whl (33.8 kB view details)

Uploaded Python 3macOS 11.0+ ARM64

vapoursynth_vivtc-2.0-py3-none-macosx_10_15_x86_64.whl (32.6 kB view details)

Uploaded Python 3macOS 10.15+ x86-64

File details

Details for the file vapoursynth_vivtc-2.0.tar.gz.

File metadata

  • Download URL: vapoursynth_vivtc-2.0.tar.gz
  • Upload date:
  • Size: 35.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for vapoursynth_vivtc-2.0.tar.gz
Algorithm Hash digest
SHA256 1ece4d86be43d764902fc8030511139b9cd39a33e54a50ed5bf76dfd9227dd32
MD5 32466701f580c2339f5e6d72c4f5b7ef
BLAKE2b-256 61d28e3a2324153e765f0764f0145a36f371c2e04140b8c3cb6831662963646c

See more details on using hashes here.

Provenance

The following attestation bundles were made for vapoursynth_vivtc-2.0.tar.gz:

Publisher: build.yml on vapoursynth/vivtc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vapoursynth_vivtc-2.0-py3-none-win_amd64.whl.

File metadata

File hashes

Hashes for vapoursynth_vivtc-2.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 554355240ac9ceb15711b387010ec5d025877beca2d9a8e85a3f392e42a96919
MD5 8334d7ab1c6bb129b0ca20b89396f115
BLAKE2b-256 dd87eb23822a82a81535583b3daa7349f284792697338b387403f431754675ae

See more details on using hashes here.

Provenance

The following attestation bundles were made for vapoursynth_vivtc-2.0-py3-none-win_amd64.whl:

Publisher: build.yml on vapoursynth/vivtc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vapoursynth_vivtc-2.0-py3-none-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for vapoursynth_vivtc-2.0-py3-none-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 fada79621bb09b92b047f155e56e7f2a5461d7075cd2ddf4c5c17fb3a418d14e
MD5 ff848feccadeec8a9168ea7aff1162ce
BLAKE2b-256 88477c2fda2dc4ef040e6129ec7aed00c0bf1268516517050bf865298d28f02c

See more details on using hashes here.

Provenance

The following attestation bundles were made for vapoursynth_vivtc-2.0-py3-none-musllinux_1_2_x86_64.whl:

Publisher: build.yml on vapoursynth/vivtc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vapoursynth_vivtc-2.0-py3-none-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for vapoursynth_vivtc-2.0-py3-none-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 bfe56d1650de5b9037356fb315ab03e31420ffd787007ffbd621b52ca4a458e2
MD5 ae28c4a594a6cfd32065a30ea2071158
BLAKE2b-256 11f59c1ac06d295ed7c8d44090175e2e8131f2ac007f66621ac34660853b1531

See more details on using hashes here.

Provenance

The following attestation bundles were made for vapoursynth_vivtc-2.0-py3-none-musllinux_1_2_aarch64.whl:

Publisher: build.yml on vapoursynth/vivtc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vapoursynth_vivtc-2.0-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for vapoursynth_vivtc-2.0-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ec5472da5a83253520cfa8f50975ddd3c6e368f2ded43e6e056acb48a10c3ce5
MD5 a1b77804d387abb14f6605225c6caa4a
BLAKE2b-256 f9602820cb976b65a41ced9b47189242996b855442ddbbbc046a4f936a9e6ffe

See more details on using hashes here.

Provenance

The following attestation bundles were made for vapoursynth_vivtc-2.0-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build.yml on vapoursynth/vivtc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vapoursynth_vivtc-2.0-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for vapoursynth_vivtc-2.0-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 6ec86839f279ba65f444e07a7cae4ec7dd3ac7fa0c12dd6111a221b9fcbd7838
MD5 b2158199e4e6d59fb417da1b308d4210
BLAKE2b-256 f7cb9eff1274836b1f808aa644624bc76107af984895133bd83077a815871554

See more details on using hashes here.

Provenance

The following attestation bundles were made for vapoursynth_vivtc-2.0-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl:

Publisher: build.yml on vapoursynth/vivtc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vapoursynth_vivtc-2.0-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for vapoursynth_vivtc-2.0-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3636e2256f00b930d51e7edfcda926ba978e733d06b7b7da66ecf6a728a4d308
MD5 18d252fc86f15769b9703234c04a7a0e
BLAKE2b-256 c4002838f7559623cea4cc70d6a52f2c352a4e43f0ea84bc0b4efd1ca2352c96

See more details on using hashes here.

Provenance

The following attestation bundles were made for vapoursynth_vivtc-2.0-py3-none-macosx_11_0_arm64.whl:

Publisher: build.yml on vapoursynth/vivtc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vapoursynth_vivtc-2.0-py3-none-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for vapoursynth_vivtc-2.0-py3-none-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 9808ec9befb22f10f8fe79615794a27d3a45317bd46727064c45bde665d734a1
MD5 bd0ef032421bcc7b92441edd90a971ac
BLAKE2b-256 4239c7474f1178968ea4ce70b2acafbbc169b7a279032b2027a7f1ee0c4be145

See more details on using hashes here.

Provenance

The following attestation bundles were made for vapoursynth_vivtc-2.0-py3-none-macosx_10_15_x86_64.whl:

Publisher: build.yml on vapoursynth/vivtc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page