Skip to content

AviVideoWriter Class#

Provides a convenient way to save AVI video files using Video for Windows (VfW).

Inheritance Hierarchy#

System.Object
  Basler.Pylon.AviVideoWriter

Syntax#

C#

public class AviVideoWriter : IVideoWriter

VB

Public Class AviVideoWriter
    Implements IVideoWriter

The AviVideoWriter type exposes the following members.

Constructors#

NameDescription
Public methodAviVideoWriter Initializes a new instance of the AviVideoWriter class
 

Properties#

NameDescription
Public propertyImageDataBytesWritten Returns the number of image data written to the .avi file in bytes.
Public propertyIsOpen Returns the open state of the video file.
 

Methods#

NameDescription
Public methodCanWriteWithoutConversion(IImage) Checks whether the image passed can be added to the video file without prior conversion.
Public methodCanWriteWithoutConversion(PixelType, Int32, Int32, Int32, ImageOrientation) Checks whether the given data/image can be added to the video file without prior conversion.
Public methodClose Closes the file.
Public methodCreate(String, Double, ICamera) Creates and opens a file for video writing.
Public methodCreate(String, Double, PixelType, Int32, Int32) Creates and opens a file for video writing.
Public methodCreate(String, Double, PixelType, Int32, Int32, ImageOrientation, String, Int32, Int32, Int32, Byte[], Boolean, IntPtr) Creates and opens a file for video writing.
Public methodDispose Releases all resources used by the AviVideoWriter
Public methodWrite(IImage) Writes an image to the video.
Public methodWrite(T)(T[], PixelType, Int32, Int32, Int32, ImageOrientation) Adds the image to the video.
 

AviVideoWriter.CanWriteWithoutConversion Method (IImage)#

Checks whether the image passed can be added to the video file without prior conversion.

Syntax#

C#

public virtual bool CanWriteWithoutConversion(
    IImage image
)

VB

Public Overridable Function CanWriteWithoutConversion ( 
    image As IImage
) As Boolean

Parameters#

 

image
Type: Basler.Pylon.IImage
Image or grabresult to check.

Return Value#

Type: Boolean
Returns true if the image will added to the video stream without prior conversion when Write() is called. Returns false if the image will be automatically converted when Write() is called. Returns false if the image cannot be added at all. See the preconditions of Write() for more information.

Implements#

IVideoWriter.CanWriteWithoutConversion(IImage)

Remarks#

Thread Safety: This method is thread-safe.

Error Safety: Does not throw exceptions.

AviVideoWriter.CanWriteWithoutConversion Method (PixelType, Int32, Int32, Int32, ImageOrientation)#

Checks whether the given data/image can be added to the video file without prior conversion.

Syntax#

C#

public virtual bool CanWriteWithoutConversion(
    PixelType pixelType,
    int width,
    int height,
    int paddingX,
    ImageOrientation orientation
)

VB

Public Overridable Function CanWriteWithoutConversion ( 
    pixelType As PixelType,
    width As Integer,
    height As Integer,
    paddingX As Integer,
    orientation As ImageOrientation
) As Boolean

Parameters#

 

pixelType
Type: Basler.Pylon.PixelType
The pixel type of the image.
width
Type: System.Int32
Width of the image.
height
Type: System.Int32
Height of the image.
paddingX
Type: System.Int32
The number of extra data bytes at the end of each row.
orientation
Type: Basler.Pylon.ImageOrientation
Orientation of the video. Most codecs support ImageOrientation.BottomUp only.

Return Value#

Type: Boolean
Returns true if the image will added to the video stream without prior conversion when Write() is called. Returns false if the image will be automatically converted when Write() is called. Returns false if the image cannot be added at all. See the preconditions of Write() for more information.

Implements#

IVideoWriter.CanWriteWithoutConversion(PixelType, Int32, Int32, Int32, ImageOrientation)

Remarks#

Thread Safety: This method is thread-safe.

Error Safety: Does not throw exceptions.

AviVideoWriter.Close Method#

Closes the file.

Syntax#

C#

public virtual void Close()

VB

Public Overridable Sub Close

Implements#

IVideoWriter.Close()

Remarks#

Thread Safety: This method is thread-safe.

Error Safety: Does not throw exceptions.

AviVideoWriter.Create Method (String, Double, ICamera)#

Creates and opens a file for video writing.

Syntax#

C#

public virtual void Create(
    string filename,
    double playbackFramesPerSecond,
    ICamera camera
)

VB

Public Overridable Sub Create ( 
    filename As String,
    playbackFramesPerSecond As Double,
    camera As ICamera
)

Parameters#

 

filename
Type: System.String
File name of the video file to be created. If the file doesn't have the .avi extension, it will be appended automatically. Existing files will be overwritten.
playbackFramesPerSecond
Type: System.Double
Playback speed in frames per second.
camera
Type: Basler.Pylon.ICamera
The camera from which the current settings are read.

Implements#

IVideoWriter.Create(String, Double, ICamera)

Remarks#

This overload reads the PixelType, Width, and Height parameters from the camera passed. Default compression options appropriate for the format will be used.

Preconditions:  

  • The file is writable.
  • The camera must be open.
  • The pixel type can be either PixelType.Mono8, PixelType.BGR8packed, or PixelType.BGRA8packed.
  Thread Safety: This method is thread-safe.

Error Safety: Can throw exceptions if the file cannot be created successfully or the preconditions are not met.

AviVideoWriter.Create Method (String, Double, PixelType, Int32, Int32)#

Creates and opens a file for video writing.

Syntax#

C#

public virtual void Create(
    string filename,
    double playbackFramesPerSecond,
    PixelType pixelType,
    int width,
    int height
)

VB

Public Overridable Sub Create ( 
    filename As String,
    playbackFramesPerSecond As Double,
    pixelType As PixelType,
    width As Integer,
    height As Integer
)

Parameters#

 

filename
Type: System.String
File name of the video file to be created. If the file doesn't have the .avi extension, it will be appended automatically. Existing files will be overwritten.
playbackFramesPerSecond
Type: System.Double
Playback speed in frames per second.
pixelType
Type: Basler.Pylon.PixelType
The pixel type of the images that will be added to the video writer. This input is used to derive the video format. Mono images result in target PixelType.Mono8. Color images with alpha channnel result in target PixelType.BGRA8packed. Other color images result in target PixelType.BGR8packed.
width
Type: System.Int32
Width of the video.
height
Type: System.Int32
Height of the video.

Implements#

IVideoWriter.Create(String, Double, PixelType, Int32, Int32)

Remarks#

Default compression options appropriate for the format will be used.

Preconditions:  

  • The file is writable.
  • Depending on the video format used not all pixel types may be supported.
  • width and height must be greater than 0.
  • The pixel type can be either PixelType.Mono8, PixelType.BGR8packed, or PixelType.BGRA8packed.
  Thread Safety: This method is thread-safe.

Error Safety: Can throw exceptions if the file cannot be created successfully or the preconditions are not met.

AviVideoWriter.Create Method (String, Double, PixelType, Int32, Int32, ImageOrientation, String, Int32, Int32, Int32, Byte[], Boolean, IntPtr)#

Creates and opens a file for video writing.

Syntax#

C#

public virtual bool Create(
    string filename,
    double playbackFramesPerSecond,
    PixelType pixelType,
    int width,
    int height,
    ImageOrientation orientation,
    string fccHandler,
    int quality,
    int bytesPerSecond,
    int autoKeyFrameInsertionRate,
    ref byte[] compressionParams,
    bool showDialog,
    IntPtr hParentWindow
)

VB

Public Overridable Function Create ( 
    filename As String,
    playbackFramesPerSecond As Double,
    pixelType As PixelType,
    width As Integer,
    height As Integer,
    orientation As ImageOrientation,
    fccHandler As String,
    quality As Integer,
    bytesPerSecond As Integer,
    autoKeyFrameInsertionRate As Integer,
    ByRef compressionParams As Byte(),
    showDialog As Boolean,
    hParentWindow As IntPtr
) As Boolean

Parameters#

 

filename
Type: System.String
Filen ame of the video file to be created. If the file doesn't have the .avi extension, it will be appended automatically. Existing files will be overwritten.
playbackFramesPerSecond
Type: System.Double
Playback speed in frames per second.
pixelType
Type: Basler.Pylon.PixelType
The pixel type of the images that will be added to the video writer. This input is used to derive the video format. Mono images result in target PixelType.Mono8. Color images with alpha channnel result in target PixelType.BGRA8packed. Other color images result in target PixelType.BGR8packed.
width
Type: System.Int32
Width of the video.
height
Type: System.Int32
Height of the video.
orientation
Type: Basler.Pylon.ImageOrientation
Orientation of the video. Most codecs support ImageOrientation.BottomUp only.
fccHandler
Type: System.String
The four-character code of the codec used for compression. This must be 4 characters or less. If you pass an empty string, the images will not be compressed.
quality
Type: System.Int32
Quality setting of the video. You can pass a value between 0 (worst quality) and 10000 (best quality).
bytesPerSecond
Type: System.Int32
Specifies the compressed bit rate. The value must be greater than 0. If you enter 0, auto keyframe insertion will be enabled.
autoKeyFrameInsertionRate
Type: System.Int32
Specifies that a key frame is inserted every nth image. For this to work, the bytesPerSecond parameter must be set to 0.
compressionParams
Type: System.Byte[]
Compression parameters to be used. On input, you can pass a null reference to use default compression parameters. If you pass an array, these values will be used. You can retrieve the array from a previous call to Create(). On successful return, the array will contain the parameters used to save the video.
showDialog
Type: System.Boolean
If set to true, a codec configuration dialog will be displayed. The user can choose from available codecs and configure the selected codec.
hParentWindow
Type: System.IntPtr
If you set showDialog to true, you can pass a window handle to be used as the parent window for the configuration dialog. If you set showDialog to false, this value will be ignored.

Return Value#

Type: Boolean
Returns true if the file was created successfully. Returns false if showDialog is set and the user clicked Cancel.

Remarks#

If a file with the same name already exists, it will be overwritten.

You can pass an empty array for the compressionOptions parameter. The function will then use the default options. If you pass a non-empty array, all codec-specific options are used from the compressionOptions parameter passed. The fccHandler, quality, bytesPerSecond, and autoKeyFrameInsertionRate parameters will be ignored On successful return, the array will contain the compression options used to write the file. You can use the returned array in subsequent calls to Create to use the same options.

You can set the showDialog parameter to true. The function will then show a configuration dialog and allow the user to select and configure the codec used. If the user clicks OK, the settings will be stored in compressionOptions and the function will try to create the file and return true. If the user clicks Cancel, the function will return false.

Preconditions:  

  • The file can be written to.
  • The Pixel type can be either PixelType.Mono8, PixelType.BGR8packed, or PixelType.BGRA8packed.
  • width and height must be greater than 0.
  Thread Safety: This method is thread-safe.

Error Safety: Can throw exceptions if the file cannot be created successfully or the preconditions are not met.

AviVideoWriter.Dispose Method#

Releases all resources used by the AviVideoWriter

Syntax#

C#

public void Dispose()

VB

Public Sub Dispose

AviVideoWriter.Write Method (IImage)#

Writes an image to the video.

Syntax#

C#

public virtual void Write(
    IImage image
)

VB

Public Overridable Sub Write ( 
    image As IImage
)

Parameters#

 

image
Type: Basler.Pylon.IImage
The image to be added.

Implements#

IVideoWriter.Write(IImage)

Remarks#

If required, the image is automatically converted to the target format.

Preconditions
 
  • The file is open.
  • The image is valid.
  • The pixel type of the image is supported by pylon.
  • The width and height of the image match the values passed when opening the video file.

Thread Safety: This method is thread-safe.

Error Safety: Does not throw exceptions.

AviVideoWriter.Write(T) Method (T[], PixelType, Int32, Int32, Int32, ImageOrientation)#

Adds the image to the video.

Syntax#

C#

public virtual void Write<T>(
    T[] pixelData,
    PixelType pixelType,
    int width,
    int height,
    int paddingX,
    ImageOrientation orientation
)

VB

Public Overridable Sub Write(Of T) ( 
    pixelData As T(),
    pixelType As PixelType,
    width As Integer,
    height As Integer,
    paddingX As Integer,
    orientation As ImageOrientation
)

Parameters#

 

pixelData
Type: T[]
The data of the image to be written.
pixelType
Type: Basler.Pylon.PixelType
The pixel type of the image.
width
Type: System.Int32
Width of the image.
height
Type: System.Int32
Height of the image.
paddingX
Type: System.Int32
The number of extra data bytes at the end of each row in pixelData
orientation
Type: Basler.Pylon.ImageOrientation
Orientation of the image data in pixelData.

Type Parameters#

 

T
The data type of pixels stored in pixelData.

Implements#

IVideoWriter.Write(T)(T[], PixelType, Int32, Int32, Int32, ImageOrientation)

Remarks#

If required, the image is automatically converted to the target format.

Preconditions  

  • The file is open.
  • The pixel type of the image is supported by pylon.
  • The width and height of the image match the values passed when opening the video file.
  Thread Safety: This method is thread-safe.

Error Safety: Does not throw exceptions.

AviVideoWriter Constructor#

Initializes a new instance of the AviVideoWriter class

Syntax#

C#

public AviVideoWriter()

VB

Public Sub New

AviVideoWriter.CanWriteWithoutConversion Method#

Overload List#

NameDescription
Public methodCanWriteWithoutConversion(IImage) Checks whether the image passed can be added to the video file without prior conversion.
Public methodCanWriteWithoutConversion(PixelType, Int32, Int32, Int32, ImageOrientation) Checks whether the given data/image can be added to the video file without prior conversion.
 

AviVideoWriter.Create Method#

Overload List#

NameDescription
Public methodCreate(String, Double, ICamera) Creates and opens a file for video writing.
Public methodCreate(String, Double, PixelType, Int32, Int32) Creates and opens a file for video writing.
Public methodCreate(String, Double, PixelType, Int32, Int32, ImageOrientation, String, Int32, Int32, Int32, Byte[], Boolean, IntPtr) Creates and opens a file for video writing.
 

AviVideoWriter.Write Method#

Overload List#

NameDescription
Public methodWrite(IImage) Writes an image to the video.
Public methodWrite(T)(T[], PixelType, Int32, Int32, Int32, ImageOrientation) Adds the image to the video.
 

AviVideoWriter.ImageDataBytesWritten Property#

Returns the number of image data written to the .avi file in bytes.

Syntax#

C#

public long ImageDataBytesWritten { get; }

VB

Public ReadOnly Property ImageDataBytesWritten As Long
    Get

Property Value#

Type: Int64

Remarks#

This value is updated with each call to Write(). The value does not include .avi header data.

Return Value#

Type: Int64
Returns the number of image data bytes that have been written to the file. Returns 0 if no images have been written yet.

Thread Safety: This method is thread-safe.

Error Safety: Does not throw exceptions.

AviVideoWriter.IsOpen Property#

Returns the open state of the video file.

Syntax#

C#

public virtual bool IsOpen { get; }

VB

Public Overridable ReadOnly Property IsOpen As Boolean
    Get

Return Value#

Type: Boolean
Returns true if a file for video output has been opened.

Implements#

IVideoWriter.IsOpen

Remarks#

Thread Safety: This method is thread-safe.

Error Safety: Does not throw exceptions.