MAWT 0.4.0 Reference Manual

# MAWT - Movie Automation With TclTop

`MAWT` offers parts of the video functionality of FFmpeg at the Tcl scripting level. This is accomplished by wrapping parts of the FFmpeg library with the help of SWIG.

Important links:

- MAWT homepage
- BAWT homepage

# ::mawtTop

## Commandsmawt, Top

#### GetErrorMessage [::mawt]mawt, Top

Get the last error message issued by MAWT.

GetErrorMessage

See also: GetFfmpegVersion, GetVersion, SetDebugMode

Show source

    proc ::mawt::GetErrorMessage {} {

        # Get the last error message issued by MAWT.
        #
        # See also: GetFfmpegVersion GetVersion SetDebugMode

        return [mawtlib::MawtGetErrorMessage]
    }

#### GetFfmpegVersion [::mawt]mawt, Top

Get FFMPEG library version string.

GetFfmpegVersion

Returns the version of the wrapped FFMPEG library as a string. The version is returned as `Major.Minor.Patch`.

See also: GetVersion, SetDebugMode, GetErrorMessage

Show source

    proc ::mawt::GetFfmpegVersion {} {

        # Get FFMPEG library version string.
        #
        # Returns the version of the wrapped FFMPEG library as a string.
        # The version is returned as `Major.Minor.Patch`.
        #
        # See also: GetVersion SetDebugMode GetErrorMessage

        return [mawtlib::MawtGetFfmpegVersion]
    }

#### GetVersion [::mawt]mawt, Top

Get MAWT library version string.

GetVersion

Returns the version of the MAWT library as a string. The version is returned as `Major.Minor.Patch`.

See also: GetFfmpegVersion, SetDebugMode, GetErrorMessage

Show source

    proc ::mawt::GetVersion {} {

        # Get MAWT library version string.
        #
        # Returns the version of the MAWT library as a string.
        # The version is returned as `Major.Minor.Patch`.
        #
        # See also: GetFfmpegVersion SetDebugMode GetErrorMessage

        return [mawtlib::MawtGetVersion]
    }

#### SetDebugMode [::mawt]mawt, Top

Enable or disable the debug mode of the MAWT library.

SetDebugMode onOff

`onOff` | Boolean value to enable or disable the debug mode.

See also: GetFfmpegVersion, GetVersion, GetErrorMessage

Show source

    proc ::mawt::SetDebugMode {onOff} {

        # Enable or disable the debug mode of the MAWT library.
        #
        # onOff - Boolean value to enable or disable the debug mode.
        #
        # See also: GetFfmpegVersion GetVersion GetErrorMessage

        mawtlib::MawtSetDebugMode [expr {bool($onOff)}]
    }

#### VideoExport [::mawt]mawt, Top

Export video frames into a series of image files.

VideoExport movieFile imgFilePattern ?args?

`movieFile` | Movie file name.
`imgFilePattern` | Pattern for image output files. Must contain a printf like integer format specifier.
`args` | Options described below.
`-end <int>` | End frame. Default: Last video frame.
`-start <int>` | Start frame. Default: First video frame.

See also: VideoImport

Show source

    proc ::mawt::VideoExport {movieFile imgFilePattern args} {

        # Export video frames into a series of image files.
        #
        # movieFile      - Movie file name.
        # imgFilePattern - Pattern for image output files.
        #                  Must contain a printf like integer format specifier.
        # args           - Options described below.
        #
        # -start <int> - Start frame. Default: First video frame.
        # -end <int>   - End frame. Default: Last video frame.
        #
        # See also: VideoImport

        set startFrame -1
        set endFrame   -1
        foreach { key value } $args {
            switch -exact $key {
                "-start" {
                    set startFrame [expr {int($value)}]
                }
                "-end" {
                    set endFrame [expr {int($value)}]
                }
            }
        }

        set videoObj [mawt Video new $movieFile "r"]
        set numBytes [$videoObj Start]
        set tx [$videoObj GetWidth]
        set ty [$videoObj GetHeight]
        set vectorObj [mawt Vector new $numBytes]
        image create photo VideoFrame -width $tx -height $ty
        set numFrames [$videoObj GetNumFrames]
        if { $startFrame < 0 } {
            set startFrame 0
        }
        if { $endFrame < 0 || $endFrame > $numFrames } {
            set endFrame [expr {$numFrames - 1}]
        }

        set fmtStr "PNG"
        set optStr ""

        set numExportedImgs 0
        for { set i $startFrame } { $i <= $endFrame } { incr i } {
            $videoObj Lock
            $videoObj GetNextImage [$vectorObj Get] 0
            $videoObj Unlock
            $vectorObj ToPhoto VideoFrame $tx $ty
            set outFileName [format $imgFilePattern $i]
            set retVal [catch { VideoFrame write $outFileName -format "$fmtStr $optStr" } errMsg]
            if { $retVal != 0 } {
                puts "Error saving image:\n$errMsg"
                return false
            }
            incr numExportedImgs
        }
        $vectorObj destroy
        $videoObj destroy
        return $numExportedImgs
    }

#### VideoImport [::mawt]mawt, Top

Generate a video by importing a series of image files.

VideoImport imgFilePattern movieFile ?args?

`imgFilePattern` | Pattern for image output files. Must contain a printf like integer format specifier.
`movieFile` | Movie file name.
`args` | Options described below.
`-bitrate <float>` | Bitrate in MBit per second. Default: 4.0.
`-end <int>` | End frame. Default: Last video frame.
`-flip <bool>` | Flip images. Default: false.
`-fps <int>` | Frames per second. Default: 25.
`-start <int>` | Start frame. Default: First video frame.
`-verbose <bool>` | Print verbose messages. Default: false.

See also: VideoExport

Show source

    proc ::mawt::VideoImport {imgFilePattern movieFile args} {

        # Generate a video by importing a series of image files.
        #
        # imgFilePattern - Pattern for image output files.
        #                  Must contain a printf like integer format specifier.
        # movieFile      - Movie file name.
        # args           - Options described below.
        #
        # -start <int>     - Start frame. Default: First video frame.
        # -end <int>       - End frame. Default: Last video frame.
        # -fps <int>       - Frames per second. Default: 25.
        # -bitrate <float> - Bitrate in MBit per second. Default: 4.0.
        # -flip <bool>     - Flip images. Default: false.
        # -verbose <bool>  - Print verbose messages. Default: false.
        #
        # See also: VideoExport

        set startFrame -1
        set endFrame   -1
        set flip        0
        set verbose     0

        foreach { key value } $args {
            switch -exact $key {
                "-start" {
                    set startFrame [expr {int($value)}]
                }
                "-end" {
                    set endFrame [expr {int($value)}]
                }
                "-flip" {
                    set flip [expr {bool($value)}]
                }
                "-verbose" {
                    set verbose [expr {bool($value)}]
                }
            }
        }

        if { $startFrame < 0 } {
            set startFrame 0
        }
        if { $endFrame < 0 } {
            for { set i $startFrame } { true } { incr i } {
                set inFileName [format $imgFilePattern $i]
                if { ! [file exists $inFileName] } {
                    set endFrame [expr {$i -1}]
                    break
                }
            }
        }

        if { $verbose } {
            puts "Input files: $imgFilePattern"
            puts "Output file: $movieFile"
            puts "Start      : $startFrame"
            puts "End        : $endFrame"
        }
        set numImportedImgs 0
        for { set i $startFrame } { $i <= $endFrame } { incr i } {
            set inFileName [format $imgFilePattern $i]
            set phImg [image create photo -file $inFileName]
            set w [image width  $phImg]
            set h [image height $phImg]
            if { ! [info exists videoObj] } {
                set videoObj [mawt Video new $movieFile "w" -width $w -height $h {*}$args]
                set vectorObj [mawt Vector new [expr {$w * $h * 3}]]
            }
            $vectorObj FromPhoto $phImg 3 1 0
            image delete $phImg
            $videoObj WriteNextImage [$vectorObj Get] $w $h $flip
            incr numImportedImgs
        }
        if { $numImportedImgs > 0 } {
            $videoObj Close
            $vectorObj destroy
            $videoObj destroy
        }
        return $numImportedImgs
    }

## Classesmawt, Top

### Vector [::mawt]mawt, Top

constructor | Constructor for the class.
destructor | Destructor for the class.
FromByteArray | Create a Vector from a binary string.
FromPhoto | Not documented.
Get | Not documented.
ToByteArray | Copy a Vector into a binary string.
ToPhoto | Not documented.

#### constructor [::mawt::Vector]Vector, Top

Vector create numBytes

`numBytes` | Not documented.

Show source

    method constructor {numBytes} {

        if { $numBytes > 0 } {
            set mVec [mawtlib::new_UByte $numBytes]
        }
    }

#### destructor [::mawt::Vector]Vector, Top

OBJECT destroy

Show source

    method destructor {} {

        mawtlib::delete_UByte $mVec
    }

#### FromByteArray [::mawt::Vector]Vector, Top

Create a Vector from a binary string.

OBJECT FromByteArray str

`str` | Binary string.

Create a new Vector from given binary string `$str`.

See also: ToByteArray

Show source

    method FromByteArray {str} {

        # Create a Vector from a binary string.
        #
        # str - Binary string.
        #
        # Create a new Vector from given binary string $str.
        #
        # See also: ToByteArray

        set numBytes [string length $str]
        if { $numBytes == 0 } {
            error "String has zero length"
        }
        set mVec [mawtlib::new_UByte $numBytes]
        mawtlib::VectorFromByteArray $str $mVec $numBytes 0 0
    }

#### FromPhoto [::mawt::Vector]Vector, Top

OBJECT FromPhoto phImg numChans scale offset

`phImg` | Not documented.
`numChans` | Not documented.
`scale` | Not documented.
`offset` | Not documented.

Show source

    method FromPhoto {phImg numChans scale offset} {

        return [mawtlib::VectorFromPhoto $phImg $mVec $numChans $scale $offset]
    }

#### Get [::mawt::Vector]Vector, Top

OBJECT Get

Show source

    method Get {} {

        return $mVec
    }

#### ToByteArray [::mawt::Vector]Vector, Top

Copy a Vector into a binary string.

OBJECT ToByteArray numBytes ?srcOff? ?destOff?

`numBytes` | int
`srcOff` | int Optional, default `0`.
`destOff` | int Optional, default `0`.

Copy `$numBytes` elements into a Tcl binary string and return that string. `$srcOff` and `$destOff` may be used optionally to specify an offset into the source and the destination.

See also: FromByteArray

Show source

    method ToByteArray {numBytes {srcOff 0} {destOff 0}} {

        # Copy a Vector into a binary string.
        #
        # numBytes - int
        # srcOff   - int
        # destOff  - int
        #
        # Copy $numBytes elements into a Tcl binary string and return that string.
        # $srcOff and $destOff may be used optionally to specify
        # an offset into the source and the destination.
        #
        # See also: FromByteArray

        if { $numBytes == 0 } {
            error "Vector has zero length"
        }
        # First generate a binary string of appropriate size.
        set bytes [binary format a$numBytes 0]
        mawtlib::VectorToByteArray $mVec $bytes $numBytes $srcOff $destOff
        return $bytes
    }

#### ToPhoto [::mawt::Vector]Vector, Top

OBJECT ToPhoto phImg width height ?numChans? ?linesAreBottomUp?

`phImg` | Not documented.
`width` | Not documented.
`height` | Not documented.
`numChans` | Not documented. Optional, default `3`.
`linesAreBottomUp` | Not documented. Optional, default `0`.

Show source

    method ToPhoto {phImg width height {numChans 3} {linesAreBottomUp 0}} {

        mawtlib::VectorToPhoto $mVec $phImg $width $height $numChans $linesAreBottomUp
    }

### Video [::mawt]mawt, Top

constructor | Constructor for the class.
destructor | Destructor for the class.
Close | Close a video stream.
Create | Create a new empty video file.
GetDuration | Get video duration information as a dict.
GetDurationAsString | Get video duration information as a string.
GetFramerate | Not documented.
GetHeight | Get the height of a video stream.
GetImage | Get an image from a video stream.
GetNextImage | Get next image from a video stream.
GetNumFrames | Not documented.
GetWidth | Get the width of a video stream.
IsOpen | Not documented.
Lock | Lock a video stream.
Open | Open a video file.
Start | Start acquisition of a video stream.
Stop | Stop acquisition of a video stream.
Unlock | Unlock a video stream.
WriteNextImage | Write next image to a video stream.
WriteNextPhotoImage | Write next photo image to a video stream.

#### constructor [::mawt::Video]Video, Top

Video create fileName mode ?args?

`fileName` | Not documented.
`mode` | Not documented.
`args` | Optional arguments.

Show source

    method constructor {fileName mode args} {

        set mVideoFile ""
        set mVideoId   "NULL"
        set mNumBytes  -1

        set width     256
        set height    256
        set fps        25
        set bitrate     4.0

        foreach { key value } $args {
            switch -exact $key {
                "-width" {
                    set width [expr {int($value)}]
                }
                "-height" {
                    set height [expr {int($value)}]
                }
                "-fps" {
                    set fps [expr {int($value)}]
                }
                "-bitrate" {
                    set bitrate [expr {double($value)}]
                }
            }
        }

        if { $mode eq "r" } {
            my Open $fileName
        } else {
            my Create $fileName $width $height $fps $bitrate
        }
        set mMode $mode
    }

#### destructor [::mawt::Video]Video, Top

OBJECT destroy

Show source

    method destructor {} {

        if { [my IsOpen] } {
            my Close
        }
    }

#### Close [::mawt::Video]Video, Top

Close a video stream.

OBJECT Close

See also: Open

Show source

    method Close {} {

        # Close a video stream.
        #
        # See also: Open

        if { $mMode eq "r" } {
            mawtlib::MawtVideoClose $mVideoId
        } else {
            if {! [mawtlib::MawtVideoFinish $mVideoId] } {
                throw [list Video Close] [mawtlib::MawtGetErrorMessage]
            }
        }
        set mVideoId   "NULL"
        set mVideoFile ""
    }

#### Create [::mawt::Video]Video, Top

Create a new empty video file.

OBJECT Create fileName width height fps bitrate

`fileName` | Create the video stream in specified file.
`width` | Width of the video stream.
`height` | Height of the video stream.
`fps` | Framerate of the video streams (frames per second).
`bitrate` | Not documented.
`birate` | Bit rate of the video ostream in MBits/s.

Throws an error, if the file could not be openend.

See also: Close, WriteNextImage, WriteNextPhotoImage

Show source

    method Create {fileName width height fps bitrate} {

        # Create a new empty video file.
        #
        # fileName - Create the video stream in specified file.
        # width    - Width of the video stream.
        # height   - Height of the video stream.
        # fps      - Framerate of the video streams (frames per second).
        # birate   - Bit rate of the video ostream in MBits/s.
        #
        # Throws an error, if the file could not be openend.
        #
        # See also: Close WriteNextImage WriteNextPhotoImage

        if { [my IsOpen] } {
            my Close
        }
        set mVideoId [mawtlib::MawtVideoCreate $fileName $width $height $fps $bitrate]
        if { ! [my IsOpen] } {
            throw [list Video Create] [mawtlib::MawtGetErrorMessage]
        }
        set mVideoFile $fileName
    }

#### GetDuration [::mawt::Video]Video, Top

Get video duration information as a dict.

OBJECT GetDuration

Get the duration of current video stream. The duration is returned as a dictionary with the keys: `minutes`, `seconds`, `frames`.

See also: GetDurationAsString

Show source

    method GetDuration {} {

        # Get video duration information as a dict.
        #
        # Get the duration of current video stream.
        # The duration is returned as a dictionary with the
        # keys: `minutes`, `seconds`, `frames`.
        #
        # See also: GetDurationAsString

        set numFrames [mawtlib::MawtVideoGetNumFrames $mVideoId]
        set frameRate [expr int([mawtlib::MawtVideoGetFramerate $mVideoId] + 0.5)]

        set secs [expr $numFrames / $frameRate]
        dict set durDict minutes [expr {$secs / 60}]
        dict set durDict seconds [expr {$secs - [dict get $durDict minutes] * 60}]
        dict set durDict frames  [expr {$numFrames % $frameRate}]
        return $durDict
    }

#### GetDurationAsString [::mawt::Video]Video, Top

Get video duration information as a string.

OBJECT GetDurationAsString

Get the duration of current video stream. The duration is returned as a string in the following format: `minutes:seconds.frames`.

See also: GetDuration

Show source

    method GetDurationAsString {} {

        # Get video duration information as a string.
        #
        # Get the duration of current video stream.
        # The duration is returned as a string in the following
        # format: `minutes:seconds.frames`.
        #
        # See also: GetDuration

        set durDict [my GetDuration]
        return [format "%02d:%02d.%02d"  [dict get $durDict minutes]  [dict get $durDict seconds]  [dict get $durDict frames]  ]
    }

#### GetFramerate [::mawt::Video]Video, Top

OBJECT GetFramerate

Show source

    method GetFramerate {} {

        return [mawtlib::MawtVideoGetFramerate $mVideoId]
    }

#### GetHeight [::mawt::Video]Video, Top

Get the height of a video stream.

OBJECT GetHeight

Returns the height of a video stream in pixels.

See also: Open, GetWidth

Show source

    method GetHeight {} {

        # Get the height of a video stream.
        #
        # Returns the height of a video stream in pixels.
        #
        # See also: Open GetWidth

        return [mawtlib::MawtVideoGetHeight $mVideoId]
    }

#### GetImage [::mawt::Video]Video, Top

Get an image from a video stream.

OBJECT GetImage img flip num

`img` | A Vector of appropriate size to store the image data.
`flip` | Boolean value to specify image flipping.
`num` | Image number as integer value starting at zero.

Get image `$num` from current video stream. The image will be stored in variable `$img`. `$img` must point to a buffer of appropriate size. If `$flip` is set to true, the image is returned in bottom-up scanline order as needed by OpenGL. If `$flip` is set to false, the image is returned in top-down scanline order as needed by the img::raw extension.

Throws an error, if the image could not be retrieved from the video stream.

See also: Open, GetNextImage, GetWidth, GetHeight

Show source

    method GetImage {img flip num} {

        # Get an image from a video stream.
        #
        # img  - A Vector of appropriate size to store the image data.
        # flip - Boolean value to specify image flipping.
        # num  - Image number as integer value starting at zero.
        #
        # Get image $num from current video stream.
        # The image will be stored in variable $img.
        # $img must point to a buffer of appropriate size.
        # If $flip is set to true, the image is returned in
        # bottom-up scanline order as needed by OpenGL.
        # If $flip is set to false, the image is returned in
        # top-down scanline order as needed by the img::raw extension.
        #
        # Throws an error, if the image could not be retrieved
        # from the video stream.
        #
        # See also: Open GetNextImage GetWidth GetHeight

        if { ! [mawtlib::MawtVideoGetImage $mVideoId $img [expr {bool($flip)}] $num] } {
            throw [list Video GetImage] [mawtlib::MawtGetErrorMessage]
        }
    }

#### GetNextImage [::mawt::Video]Video, Top

Get next image from a video stream.

OBJECT GetNextImage img flip

`img` | A Vector of appropriate size to store the image data.
`flip` | Boolean value to specify image flipping.

Get the next image from current video stream. The image will be stored in variable `$img`. `$img` must point to a buffer of appropriate size. If `$flip` is set to true, the image is returned in bottom-up scanline order as needed by OpenGL. If `$flip` is set to false, the image is returned in top-down scanline order as needed by the img::raw extension.

Throws an error, if the image could not be retrieved from the video stream.

See also: Open, Close, GetImage, GetWidth, GetHeight

Show source

    method GetNextImage {img flip} {

        # Get next image from a video stream.
        #
        # img  - A Vector of appropriate size to store the image data.
        # flip - Boolean value to specify image flipping.
        #
        # Get the next image from current video stream.
        # The image will be stored in variable $img.
        # $img must point to a buffer of appropriate size.
        # If $flip is set to true, the image is returned in
        # bottom-up scanline order as needed by OpenGL.
        # If $flip is set to false, the image is returned in
        # top-down scanline order as needed by the img::raw extension.
        #
        # Throws an error, if the image could not be retrieved
        # from the video stream.
        #
        # See also: Open Close GetImage GetWidth GetHeight

        if { ! [mawtlib::MawtVideoGetNextImage $mVideoId $img [expr {bool($flip)}]] } {
            # TODO: Check why this throws an error at the last frame.
            # throw [list Video GetNextImage] [mawtlib::MawtGetErrorMessage]
        }
    }

#### GetNumFrames [::mawt::Video]Video, Top

OBJECT GetNumFrames

Show source

    method GetNumFrames {} {

        return [mawtlib::MawtVideoGetNumFrames $mVideoId]
    }

#### GetWidth [::mawt::Video]Video, Top

Get the width of a video stream.

OBJECT GetWidth

Returns the width of a video stream in pixels.

See also: Open, GetHeight

Show source

    method GetWidth {} {

        # Get the width of a video stream.
        #
        # Returns the width of a video stream in pixels.
        #
        # See also: Open GetHeight

        return [mawtlib::MawtVideoGetWidth $mVideoId]
    }

#### IsOpen [::mawt::Video]Video, Top

OBJECT IsOpen

Show source

    method IsOpen {} {

        if { $mVideoId ne "NULL" } {
            return true
        } else {
            return false
        }
    }

#### Lock [::mawt::Video]Video, Top

Lock a video stream.

OBJECT Lock

See also: Open, Unlock

Show source

    method Lock {} {

        # Lock a video stream.
        #
        # See also: Open Unlock

        mawtlib::MawtVideoLock $mVideoId
    }

#### Open [::mawt::Video]Video, Top

Open a video file.

OBJECT Open fileName

`fileName` | Open the video stream stored in specified file.

If a video stream is already open, it is closed before opening the new video stream.

Throws an error, if the file could not be openend.

See also: Close, Start, Stop

Show source

    method Open {fileName} {

        # Open a video file.
        #
        # fileName - Open the video stream stored in specified file.
        #
        # If a video stream is already open, it is closed before opening
        # the new video stream.
        #
        # Throws an error, if the file could not be openend.
        #
        # See also: Close Start Stop

        if { [my IsOpen] } {
            my Close
        }
        set mVideoId [mawtlib::MawtVideoOpen $fileName]
        if { ! [my IsOpen] } {
            throw [list Video Open] [mawtlib::MawtGetErrorMessage]
        }
        set mVideoFile $fileName
    }

#### Start [::mawt::Video]Video, Top

Start acquisition of a video stream.

OBJECT Start ?width? ?height?

`width` | integer Optional, default `-1`.
`height` | integer Optional, default `-1`.

Start acquisition of current video stream. If `$width` and `$height` are specified and greater than zero, stretch the video to that size. Otherwise the video is played in its original size.

Returns the number of bytes needed for a video frame. If the video could not be started, an error is thrown.

See also: Open, Stop

Show source

    method Start {{width -1} {height -1}} {

        # Start acquisition of a video stream.
        #
        # width   - integer
        # height  - integer
        #
        # Start acquisition of current video stream.
        # If $width and $height are specified and greater than
        # zero, stretch the video to that size.
        # Otherwise the video is played in its original size.
        #
        # Returns the number of bytes needed for a video frame.
        # If the video could not be started, an error is thrown.
        #
        # See also: Open Stop

        set mNumBytes [mawtlib::MawtVideoStart $mVideoId $width $height]
        if { $mNumBytes < 0 } {
            throw [list Video Start] [mawtlib::MawtGetErrorMessage]
        }
        return $mNumBytes
    }

#### Stop [::mawt::Video]Video, Top

Stop acquisition of a video stream.

OBJECT Stop

See also: Start, Open, Close

Show source

    method Stop {} {

        # Stop acquisition of a video stream.
        #
        # See also: Start Open Close

        mawtlib::MawtVideoStop $mVideoId
    }

#### Unlock [::mawt::Video]Video, Top

Unlock a video stream.

OBJECT Unlock

See also: Open, Lock

Show source

    method Unlock {} {

        # Unlock a video stream.
        #
        # See also: Open Lock

        mawtlib::MawtVideoUnlock $mVideoId
    }

#### WriteNextImage [::mawt::Video]Video, Top

Write next image to a video stream.

OBJECT WriteNextImage img width height flip

`img` | A Vector containing the image data.
`width` | Width of the image.
`height` | Height of the image.
`flip` | Boolean value to specify image flipping.

Write the next image to the current video stream.

The image data must be available in variable `$img`. `$img` must point to a buffer of size width by height. If `$flip` is set to true, the image is returned in bottom-up scanline order as needed by OpenGL. If `$flip` is set to false, the image is returned in top-down scanline order as needed by the img::raw extension.

Throws an error, if the image could not be written to the video stream.

See also: WriteNextPhotoImage, Create, Close, GetImage, GetWidth, GetHeight

Show source

    method WriteNextImage {img width height flip} {

        # Write next image to a video stream.
        #
        # img    - A Vector containing the image data.
        # width  - Width of the image.
        # height - Height of the image.
        # flip   - Boolean value to specify image flipping.
        #
        # Write the next image to the current video stream.
        #
        # The image data must be available in variable $img.
        # $img must point to a buffer of size width by height.
        # If $flip is set to true, the image is returned in
        # bottom-up scanline order as needed by OpenGL.
        # If $flip is set to false, the image is returned in
        # top-down scanline order as needed by the img::raw extension.
        #
        # Throws an error, if the image could not be written
        # to the video stream.
        #
        # See also: WriteNextPhotoImage Create Close GetImage GetWidth GetHeight

        if { ! [mawtlib::MawtVideoWriteNextImage $mVideoId $img $width $height [expr {bool($flip)}]] } {
            # TODO: Check why this throws an error at the last frame.
            # throw [list Video WriteNextImage] [mawtlib::MawtGetErrorMessage]
        }
    }

#### WriteNextPhotoImage [::mawt::Video]Video, Top

Write next photo image to a video stream.

OBJECT WriteNextPhotoImage phImg flip

`phImg` | A Tk photo image.
`flip` | Boolean value to specify image flipping.

The image data must be available in photo image `$phImg`.

If `$flip` is set to true, the image is returned in bottom-up scanline order as needed by OpenGL. If `$flip` is set to false, the image is returned in top-down scanline order as needed by the img::raw extension.

Throws an error, if the image could not be written to the video stream.

See also: WriteNextImage, Create, Close, GetImage, GetWidth, GetHeight

Show source

    method WriteNextPhotoImage {phImg flip} {

        # Write next photo image to a video stream.
        #
        # phImg - A Tk photo image.
        # flip  - Boolean value to specify image flipping.
        #
        # The image data must be available in photo image $phImg.
        #
        # If $flip is set to true, the image is returned in
        # bottom-up scanline order as needed by OpenGL.
        # If $flip is set to false, the image is returned in
        # top-down scanline order as needed by the img::raw extension.
        #
        # Throws an error, if the image could not be written
        # to the video stream.
        #
        # See also: WriteNextImage Create Close GetImage GetWidth GetHeight

        set w [image width  $phImg]
        set h [image height $phImg]
        set vectorObj [mawt Vector new [expr {$w * $h * 3}]]
        $vectorObj FromPhoto $phImg 3 1 0
        if { ! [mawtlib::MawtVideoWriteNextImage $mVideoId [$vectorObj Get] $w $h [expr {bool($flip)}]] } {
            # TODO: Check why this throws an error at the last frame.
            # throw [list Video WriteNextImage] [mawtlib::MawtGetErrorMessage]
        }
        $vectorObj destroy
    }

# MAWT - Movie Automation With Tcl

# mawt

## Commands

#### GetErrorMessage Get the last error message issued by MAWT.

#### GetFfmpegVersion Get FFMPEG library version string.

#### GetVersion Get MAWT library version string.

#### SetDebugMode Enable or disable the debug mode of the MAWT library.

#### VideoExport Export video frames into a series of image files.

#### VideoImport Generate a video by importing a series of image files.

## Classes

### Vector

#### constructor

#### destructor

#### FromByteArray Create a Vector from a binary string.

#### FromPhoto

#### Get

#### ToByteArray Copy a Vector into a binary string.

#### ToPhoto

### Video

#### constructor

#### destructor

#### Close Close a video stream.

#### Create Create a new empty video file.

#### GetDuration Get video duration information as a dict.

#### GetDurationAsString Get video duration information as a string.

#### GetFramerate

#### GetHeight Get the height of a video stream.

#### GetImage Get an image from a video stream.

#### GetNextImage Get next image from a video stream.

#### GetNumFrames

#### GetWidth Get the width of a video stream.

#### IsOpen

#### Lock Lock a video stream.

#### Open Open a video file.

#### Start Start acquisition of a video stream.

#### Stop Stop acquisition of a video stream.

#### Unlock Unlock a video stream.

#### WriteNextImage Write next image to a video stream.

#### WriteNextPhotoImage Write next photo image to a video stream.

Document generated by Ruff!