Clip properties

From Avisynth wiki
(Difference between revisions)
Jump to: navigation, search
m (move PixelType; AudioDuration notes)
m (AudioDuration tweak)
 
Line 104: Line 104:
  
 
==== Audio ====
 
==== Audio ====
<div style="width:50em; padding:1em; margin-left:0.5em; margin-bottom:1em; line-height:150%; border:1px solid black">
+
<div style="width:55em; padding:1em; margin-left:0.5em; margin-bottom:1em; line-height:150%; border:1px solid black">
'''Audio Duration: Precision vs. Convenience'''
+
'''Audio Duration Notes'''
  
The easiest way to get a clip’s duration in seconds is {{FuncArg|AudioDuration}}. However, due to the limits of single-precision, floating-point math, the duration of very long clips starts to lose ''precision''; see the [[#Examples|Examples]] below for an illustration. There is an alternative,  {{FuncArg|AudioLength}}, which returns the exact number of audio samples: divide by {{FuncArg|AudioRate}} and you have the precise duration. However, this is limited by the range a of 32-bit integer; with a long enough clip, the result wraps around to a negative number! There are two ways around this: first, {{FuncArg|AudioLengthS}} returns the exact number of audio samples as a string; and second, {{FuncArg|AudioLengthLo}} and {{FuncArg|AudioLengthHi}} together can store the full 64-bit value.
+
The easiest way to get a clip’s duration in seconds is {{Term|AudioDuration}}. However, due to the limits of 32-bit floating-point math, the result is very close (within milliseconds per 24-hour day), but not exact.
 +
 
 +
{{Term|AudioLength}} returns a clip’s exact audio duration in samples. However, this is limited by the range a of 32-bit integer; with a long enough clip (at 48kHz sample rate, somewhat over 12 hours), the result wraps around to a negative number.
 +
 
 +
For an accurate sample count over long durations, {{Term|AudioLengthS}} returns the number as a string, and {{Term|AudioLengthHi}}×10<sup>9</sup>+{{Term|AudioLengthLo}} returns the full 64-bit value. Unfortunately, attempting to do precise arithmetic using either of these numbers within AviSynth runs into the same 32-bit math issues as mentioned above.
 
</div>
 
</div>
 
* ''int'' clip.{{Term|AudioRate}}
 
* ''int'' clip.{{Term|AudioRate}}

Latest revision as of 12:31, 4 November 2017

You can access a variety of clip properties in AviSynth scripts. For example, if the variable clip holds a video clip, then clip.Height is its height in pixels, clip.FrameCount is its length in frames, and so on.

Clip properties can be accessed like script variables, except that they are read-only (in C terminology, they cannot be L-values).

Contents


The full list of properties:

[edit] Content Properties

  • bool clip.HasAudio
Returns true if the clip has audio, false otherwise.
  • bool clip.HasVideo
Returns true if the clip has video, false otherwise.

[edit] Video: Resolution

  • int clip.Width
Returns the width of the clip in pixels.
  • int clip.Height
Returns the height of the clip in pixels.

[edit] Video: Framerate and Duration

(see also: AudioDuration and related properties)
  • int clip.FrameCount
Returns the total number of video frames contained in the clip.
  • float clip.FrameRate
Returns approximate framerate. Video framerate is actually a ratio of two 32-bit integers;
so for the precise number, use FrameRateNumerator and FrameRateDenominator.
  • int clip.FrameRateNumerator
Returns the framerate numerator.
  • int clip.FrameRateDenominator
Returns the framerate denominator.

[edit] Video: Interlacing

  • bool clip.IsFieldBased
Returns true if the clip is field-based. What this means is explained here.
  • bool clip.IsFrameBased
Returns true if the clip is frame-based. What this means is explained here.
  • bool clip.GetParity([ int f ])
Returns true if frame f (default 0) is the top field of a field-based clip, or if it is a full frame with top field first of a frame-based clip.

[edit] Video: Color Format

  • string clip.PixelType (from v2.60)
Returns the pixel type as a string, eg "RGB32".
  • bool clip.IsPlanar
Returns true if the color format is Planar, false otherwise.
  • bool clip.IsInterleaved
Returns true if the color format is Interleaved, false otherwise.
  • bool clip.IsRGB
Returns true if the color format is RGB, false otherwise.
(applies to all RGB clips, whether Planar or Interleaved, RGB or RGBA)
  • bool clip.IsRGB24
Returns true if the color format is RGB24, false otherwise.
  • bool clip.IsRGB32
Returns true if the color format is RGB32, false otherwise.
  • bool clip.IsYUV
Returns true if the color format is YUV, false otherwise.
(note that IsYUV returns false for a YUVA clip, and vice versa)
  • bool clip.IsYUY2 (clip)
Returns true if the color format is YUY2, false otherwise.
  • bool clip.IsY8 (from v2.60)
Returns true if the color format is Y8, false otherwise.
  • bool clip.IsYV12
Returns true if the color format is YV12, false otherwise.
  • bool clip.IsYV16 (from v2.60)
Returns true if the clip color format is YV16, false otherwise.
  • bool clip.IsYV24 (v2.60)
Returns true if the color format is YV24, false otherwise.
  • bool clip.IsYV411 (from v2.60)
Returns true if the color format is YV411, false otherwise.
  • bool clip.Is420
AVS+ Returns true if the color format is 4:2:0, false otherwise.
  • bool clip.Is422
AVS+ Returns true if the color format is 4:2:2, false otherwise.
  • bool clip.Is444
AVS+ Returns true if the color format is 4:4:4, false otherwise.
  • bool clip.IsY
AVS+ Returns true if the color format is Y-plane only, false otherwise.
  • bool clip.IsYUVA
AVS+ Returns true if the color format is YUVA, false otherwise.
  • bool clip.IsRGB48
AVS+ Returns true if the color format is 16-bit RGB (RGB48), false otherwise.
  • bool clip.IsRGB64
AVS+ Returns true if the color format is 16-bit RBGA (RGB64), false otherwise.
  • bool clip.IsPackedRGB
AVS+ Returns true if the color format is Interleaved RGB (RGB24/32/48/64), false otherwise.
  • bool clip.IsPlanarRGB
AVS+ Returns true if the color format is Planar RGB, false otherwise.
(note that IsPlanarRGB returns false for a Planar RGBA clip, and vice versa)
  • bool clip.IsPlanarRGBA
AVS+ Returns true if the color format is Planar RGBA, false otherwise.
(note that IsPlanarRGBA returns false for a Planar RGB clip, and vice versa)
  • bool clip.HasAlpha
AVS+ Returns true if the color format has an alpha channel; (RGBA or YUVA), false otherwise.
  • int clip.ComponentSize
AVS+ Returns 1 for 8-bit formats, 2 for 10/12/14/16-bit formats, 4 for 32-bit float.
  • int clip.NumComponents
AVS+ Returns 1 for Y-only formats, 3 for RGB and YUV, 4 for RGBA and YUVA.
  • int clip.BitsPerComponent
AVS+ Returns bit depth per channel – 8, 10, 12, 14, 16 or 32.

[edit] Audio

Audio Duration Notes

The easiest way to get a clip’s duration in seconds is AudioDuration. However, due to the limits of 32-bit floating-point math, the result is very close (within milliseconds per 24-hour day), but not exact.

AudioLength returns a clip’s exact audio duration in samples. However, this is limited by the range a of 32-bit integer; with a long enough clip (at 48kHz sample rate, somewhat over 12 hours), the result wraps around to a negative number.

For an accurate sample count over long durations, AudioLengthS returns the number as a string, and AudioLengthHi×109+AudioLengthLo returns the full 64-bit value. Unfortunately, attempting to do precise arithmetic using either of these numbers within AviSynth runs into the same 32-bit math issues as mentioned above.

  • int clip.AudioRate
Returns the audio sample rate.
  • float clip.AudioDuration (from v2.60)
Returns the audio duration in seconds.
  • int clip.AudioLength
Returns the total number of audio samples, per audio channel.
  • float clip.AudioLengthF
Returns the total number of audio samples as a float-point number.
No overflow limit, but there is a possible precision limit – see Examples below.
  • string clip.AudioLengthS (from v2.60)
Returns the total number of audio samples as a string.
  • int clip.AudioLengthLo([ int m ]) (from v2.60)
  • int clip.AudioLengthHi([ int d ]) (from v2.60)
clip.AudioLengthLo returns the total number of audio samples, modulo m, which is 109 by default.
clip.AudioLengthHi returns the total number of audio samples, divided by d, which is 109 by default.
Therefore, assuming m==d, the (possibly 64-bit) total equals AudioLengthHi × m + AudioLengthLo.
  • int clip.AudioChannels
Returns the number of audio channels.
  • int clip.AudioBits
Returns the audio bit depth, eg, 8, 16, 24 or 32.
  • bool clip.IsAudioFloat
Returns true if the audio format is Float.
  • bool clip.IsAudioInt
Returns true if the audio format is an integer type.


[edit] Examples

  • Clip duration = 10 seconds. All AudioLength forms agree.
ColorBars(width=440, height=440)
Trim(0, 299)
Info
Levels(0, 1.0, 255, 64, 255-64, coring=false)
Subtitle(
\   "\nAudioLength  = "  + String(AudioLength)
\ + "\nAudioLengthS = '" + AudioLengthS + "'"
\ + "\nAudioLengthF = " + String(AudioLengthF)
\ + "\nAudioLengthLo= " + String(AudioLengthLo)
\ + "\nAudioLengthHi= " + String(AudioLengthHi)
\ , font="courier", text_color=$ffffff, size=32, align=4, lsp=0)
AudioLength-10s.png


  • Clip duration approximately 24 hours.

Integer AudioLength overloads (wraps around to a negative number), while the floating-point form has lost several digits of precision.

ColorBars(width=440, height=440)
#Trim(0, 299)
Loop(24)
Info
...
AudioLength-24hr.png

Note the AudioLengthHi / AudioLengthLo arithmetic:

total = 4 × 109 + 147195848
total = 4147195848



Back to AviSynth Syntax.

Personal tools