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:

::mawtTop

Commandsmawt, Top

GetErrorMessage [::mawt]mawt, Top

Get the last error message issued by MAWT.

GetErrorMessage

See also: GetFfmpegVersion, GetVersion, SetDebugMode

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

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

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
onOffBoolean value to enable or disable the debug mode.

See also: GetFfmpegVersion, GetVersion, GetErrorMessage

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?
movieFileMovie file name.
imgFilePatternPattern for image output files. Must contain a printf like integer format specifier.
argsOptions described below.
-end <int>End frame. Default: Last video frame.
-start <int>Start frame. Default: First video frame.

See also: VideoImport

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?
imgFilePatternPattern for image output files. Must contain a printf like integer format specifier.
movieFileMovie file name.
argsOptions 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

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

constructorConstructor for the class.
destructorDestructor for the class.
FromByteArrayCreate a Vector from a binary string.
FromPhotoNot documented.
GetNot documented.
ToByteArrayCopy a Vector into a binary string.
ToPhotoNot documented.

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

Vector create numBytes
numBytesNot documented.
method constructor {numBytes} {

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

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

OBJECT destroy
method destructor {} {

    mawtlib::delete_UByte $mVec
}

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

Create a Vector from a binary string.

OBJECT FromByteArray str
strBinary string.

Create a new Vector from given binary string $str.

See also: ToByteArray

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
phImgNot documented.
numChansNot documented.
scaleNot documented.
offsetNot documented.
method FromPhoto {phImg numChans scale offset} {

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

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

OBJECT Get
method Get {} {

    return $mVec
}

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

Copy a Vector into a binary string.

OBJECT ToByteArray numBytes ?srcOff? ?destOff?
numBytesint
srcOffint Optional, default 0.
destOffint 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

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?
phImgNot documented.
widthNot documented.
heightNot documented.
numChansNot documented. Optional, default 3.
linesAreBottomUpNot documented. Optional, default 0.
method ToPhoto {phImg width height {numChans 3} {linesAreBottomUp 0}} {

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

Video [::mawt]mawt, Top

constructorConstructor for the class.
destructorDestructor for the class.
CloseClose a video stream.
CreateCreate a new empty video file.
GetDurationGet video duration information as a dict.
GetDurationAsStringGet video duration information as a string.
GetFramerateNot documented.
GetHeightGet the height of a video stream.
GetImageGet an image from a video stream.
GetNextImageGet next image from a video stream.
GetNumFramesNot documented.
GetWidthGet the width of a video stream.
IsOpenNot documented.
LockLock a video stream.
OpenOpen a video file.
StartStart acquisition of a video stream.
StopStop acquisition of a video stream.
UnlockUnlock a video stream.
WriteNextImageWrite next image to a video stream.
WriteNextPhotoImageWrite next photo image to a video stream.

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

Video create fileName mode ?args?
fileNameNot documented.
modeNot documented.
argsOptional arguments.
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
method destructor {} {

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

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

Close a video stream.

OBJECT Close

See also: Open

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
fileNameCreate the video stream in specified file.
widthWidth of the video stream.
heightHeight of the video stream.
fpsFramerate of the video streams (frames per second).
bitrateNot documented.
birateBit rate of the video ostream in MBits/s.

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

See also: Close, WriteNextImage, WriteNextPhotoImage

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

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

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
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

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
imgA Vector of appropriate size to store the image data.
flipBoolean value to specify image flipping.
numImage 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

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
imgA Vector of appropriate size to store the image data.
flipBoolean 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

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
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

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
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

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
fileNameOpen 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

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?
widthinteger Optional, default -1.
heightinteger 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

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

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

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
imgA Vector containing the image data.
widthWidth of the image.
heightHeight of the image.
flipBoolean 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

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
phImgA Tk photo image.
flipBoolean 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

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
}
Document generated by Ruff!