Skip to main content

Subtitle filter for VapourSynth

Project description

Subtext

Subtext is a subtitle renderer that uses libass and ffmpeg.

.. function:: TextFile(clip clip, string file[, string charset="UTF-8", float scale=1, int debuglevel=0, string fontdir="", float linespacing=0, int[] margins=[0, 0, 0, 0], float sar=0, string style="", bint blend=True, int matrix, string matrix_s, int transfer, string transfer_s, int primaries, string primaries_s, int range]) :module: sub

TextFile renders text subtitles. Supported formats include ASS, JACOsub, MicroDVD, SAMI, SRT, WebVTT, and some other obscure ones.

TextFile has two modes of operation. With blend=True (the default), it returns clip with the subtitles burned in. With blend=False, it returns an RGB24 clip containing the rendered subtitles, with a Gray8 frame attached to each frame in the _Alpha frame property. These Gray8 frames can be extracted using std.PropToClip.

Parameters: clip Input clip.

  file
     Subtitle file to be rendered.

  charset
     Character set of the subtitle, in iconv format.

  scale
     Font scale.

  debuglevel
     Debug level. Increase to make libass more chatty.
     See `ass_utils.h <https://github.com/libass/libass/blob/master/libass/ass_utils.h>`_
     in libass for the list of meaningful values.

  fontdir
     Directory with additional fonts.

  linespacing
     Space between lines, in pixels.

  margins
     Additional margins, in pixels. Negative values are not
     allowed. The order is top, bottom, left, right.

  sar
     Storage aspect ratio.

  style
     Custom ASS style for subtitle formats other than ASS. If empty
     (the default), libavcodec's default style is used. This
     parameter has no effect on ASS subtitles.

  blend
     If True, the subtitles will be blended into *clip*. Otherwise,
     the bitmaps will be returned untouched.

  matrix

  matrix_s

  transfer

  transfer_s

  primaries

  primaries_s

  range
     If blend=True, these will be passed to resize.Bicubic when
     converting the RGB24 subtitles to YUV. The default matrix is
     "709".

.. function:: Subtitle(clip clip, string text[, int start=0, int end=clip.numFrames, int debuglevel=0, string fontdir="", float linespacing=0, int[] margins=[0, 0, 0, 0], float sar=0, string style="sans-serif,20,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,2,0,7,10,10,10,1", bint blend=True, int matrix, string matrix_s, int transfer, string transfer_s, int primaries, string primaries_s, int range]) :module: sub

Instead of rendering a subtitle file, Subtitle renders the string text. Otherwise it works the same as TextFile.

Parameters: text String to be rendered. This can include ASS tags to enable rich text and animation.

  style
     Custom ASS style to be used.
  
  start, end
     Subtitle will be shown from *start* up until *end*. By default this will be for all frames in *clip*.

The other parameters have the same meanings as with TextFile.

.. function:: ImageFile(clip clip, string file[, int id=-1, int[] palette, bint gray=False, bint info=False, bint flatten=False, bint blend=True, int matrix, string matrix_s, int transfer, string transfer_s, int primaries, string primaries_s, int range]) :module: sub

ImageFile renders image-based subtitles such as VOBSUB and PGS.

Parameters: clip If blend is True, the subtitles will be burned into this clip, Otherwise, only the frame rate and number of frames will be obtained from this clip.

  *file*
     Name of the subtitle file. For VOBSUB, it must the name of the
     idx file. The corresponding sub file must be in the same
     folder, and it must have the same name.

  *id*
     Id of the subtitle track to render. There may be several
     subtitle tracks in the same file. If this is -1, the first
     supported subtitle track will be rendered. Use info=True to
     see a list of all subtitle tracks, including their ids.

     Default: -1.

  *palette*
     Custom palette. This is an array of at most 256 integers. Each
     element's least significant four bytes must contain the values
     for alpha, red, green, and blue, in that order, from most
     significant to least.

     Additionally, the special value 2**42 means that the
     corresponding element of the original palette is used. This
     way it is possible to override only the third element, without
     overriding the first and second ones, for example.

     An alpha value of 255 means the colour will be completely
     opaque, and a value of 0 means the colour will be completely
     transparent.

  *gray*
     If True, the subtitles will be turned gray.

     Default: False.

  *info*
     If this is True, a list of all supported subtitle tracks found
     in the file will be printed on each frame of the output. The
     information printed about each track includes the id, the
     language (if known), the resolution, and the format.

     Default: False.

  *flatten*
     If this is True, ImageFile will output a clip with exactly as
     many frames as there are pictures in the subtitle file.

     If this is True, *blend* has no effect (no automatic blending).

     Default: False.

The other parameters have the same meanings as with TextFile.

Example with manual blending::

sub = core.sub.TextFile(clip=YUV420P10_video, file="asdf.ass", blend=False) mask = core.std.PropToClip(clip=sub, prop='_Alpha')

gray10 = core.query_video_format( mask.format.color_family, YUV420P10_video.format.sample_type, YUV420P10_video.format.bits_per_sample, mask.format.subsampling_w, mask.format.subsampling_h )

sub = core.resize.Bicubic(clip=sub, format=YUV420P10_video.format.id, matrix_s="470bg") mask = core.resize.Bicubic(clip=mask, format=gray10.id)

hardsubbed_video = core.std.MaskedMerge(clipa=YUV420P10_video, clipb=sub, mask=mask)

Example with automatic blending (will use BT709 matrix)::

hardsubbed_video = core.sub.TextFile(clip=YUV420P10_video, file="asdf.ass")

Example with a custom palette and automatic blending::

def rgba(r, g, b, a=255): if r < 0 or r > 255 or g < 0 or g > 255 or b < 0 or b > 255 or a < 0 or a > 255: raise vs.Error("Colours must be in the range [0, 255].")

   return (a << 24) + (r << 16) + (g << 8) + b

unused = 1 << 42

src = core.ffms2.Source("video.mp4")

Override only the third element of the palette. Set it to some kind of green.

ret = core.sub.ImageFile(src, "subtitles.sup", palette=[unused, unused, rgba(0, 192, 128)])

Project details


Release history Release notifications | RSS feed

This version

6.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_subtext-6.0.tar.gz (25.1 kB view details)

Uploaded Source

Built Distributions

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

vapoursynth_subtext-6.0-py3-none-win_amd64.whl (10.6 MB view details)

Uploaded Python 3Windows x86-64

vapoursynth_subtext-6.0-py3-none-manylinux_2_28_x86_64.whl (10.1 MB view details)

Uploaded Python 3manylinux: glibc 2.28+ x86-64

vapoursynth_subtext-6.0-py3-none-manylinux_2_28_aarch64.whl (9.8 MB view details)

Uploaded Python 3manylinux: glibc 2.28+ ARM64

vapoursynth_subtext-6.0-py3-none-macosx_15_0_x86_64.whl (9.5 MB view details)

Uploaded Python 3macOS 15.0+ x86-64

vapoursynth_subtext-6.0-py3-none-macosx_15_0_arm64.whl (8.7 MB view details)

Uploaded Python 3macOS 15.0+ ARM64

File details

Details for the file vapoursynth_subtext-6.0.tar.gz.

File metadata

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

File hashes

Hashes for vapoursynth_subtext-6.0.tar.gz
Algorithm Hash digest
SHA256 fef3f1e45ff9314cf7e02425cd74f046059850d172c7ac139159bbd8e96c213f
MD5 67ceb3f897a0a87f334b5fb0bf4ab286
BLAKE2b-256 7ab47e61e5bb9d9de937547cbd7b780b19f202b39a881f2121f68c901f3b9a8f

See more details on using hashes here.

Provenance

The following attestation bundles were made for vapoursynth_subtext-6.0.tar.gz:

Publisher: build.yml on vapoursynth/subtext

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_subtext-6.0-py3-none-win_amd64.whl.

File metadata

File hashes

Hashes for vapoursynth_subtext-6.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 827bee1476a839efb5ab157569d270009b7613f1467b6dba73171305e048d5de
MD5 0f9bc8a2171be2d7e8a584f15e3bbe20
BLAKE2b-256 6eb522c4dba1f2be52b456e99174defa9965bdb5f829d6a5aee49136e278f07e

See more details on using hashes here.

Provenance

The following attestation bundles were made for vapoursynth_subtext-6.0-py3-none-win_amd64.whl:

Publisher: build.yml on vapoursynth/subtext

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_subtext-6.0-py3-none-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for vapoursynth_subtext-6.0-py3-none-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c46fe1e26480421b028fb17f94b65dbb405e37316e6ccbf02f0045ea066795b8
MD5 8ee805692a3cde422b023028b474c46f
BLAKE2b-256 1b01640526cb3e96266c880864484cde1a9542895a01dadfe362d3130ecc7b1e

See more details on using hashes here.

Provenance

The following attestation bundles were made for vapoursynth_subtext-6.0-py3-none-manylinux_2_28_x86_64.whl:

Publisher: build.yml on vapoursynth/subtext

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_subtext-6.0-py3-none-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for vapoursynth_subtext-6.0-py3-none-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 88ec3a0ae5b4e37832aa8a35e276981952e07815c6de92013da75002146dab03
MD5 e8707d91061907cb25aaf4b2db2798f0
BLAKE2b-256 5bce56eaf0dfd623caab4aa68003225f6735a248c7b944305f36a086422b5137

See more details on using hashes here.

Provenance

The following attestation bundles were made for vapoursynth_subtext-6.0-py3-none-manylinux_2_28_aarch64.whl:

Publisher: build.yml on vapoursynth/subtext

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_subtext-6.0-py3-none-macosx_15_0_x86_64.whl.

File metadata

File hashes

Hashes for vapoursynth_subtext-6.0-py3-none-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 b347f5201f8c978bb4a0293d9ef5be6a156b62adb2452d0e4e35eef178bc06f2
MD5 2c0a45141e2129b5da545070adde27d8
BLAKE2b-256 ae19ec64833b961626bb3ac1176d623da04750601b742441bea80d7c6aebe58c

See more details on using hashes here.

Provenance

The following attestation bundles were made for vapoursynth_subtext-6.0-py3-none-macosx_15_0_x86_64.whl:

Publisher: build.yml on vapoursynth/subtext

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_subtext-6.0-py3-none-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for vapoursynth_subtext-6.0-py3-none-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 5405fa77c17afee54eacb93f1547b16b3c9d16984f8f57b1c64ecd5935abf4c1
MD5 d3eab3178fc136b35942fd0ab0724445
BLAKE2b-256 5fadc83eecb70bd5a740064289104eeee001c5d0fba4dcf162a6dc333b80449a

See more details on using hashes here.

Provenance

The following attestation bundles were made for vapoursynth_subtext-6.0-py3-none-macosx_15_0_arm64.whl:

Publisher: build.yml on vapoursynth/subtext

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