Changeset 2023


Ignore:
Timestamp:
Jan 9, 2011, 9:30:53 PM (14 years ago)
Author:
dkearney
Message:

updates for video widgets
two new video dials
video chooser widget for selecting movies
video preview widget is a no frills movie player.
updated c code to more correctly report the last frame of the movie.
new video speed widget which allows for fractional values between 0x and 1.0x
updated piv/pve example application
fixed "release" function in tcl bindings for RpVideo?

Location:
trunk
Files:
18 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/examples/video/dial/dialdemo.tcl

    r1979 r2023  
    4545after 200 {
    4646    update idletasks
    47     .f.d3 mark add loopstart 5
    48     .f.d3 mark add loopend 10
     47#    .f.d3 mark add loopstart 5
     48#    .f.d3 mark add loopend 10
    4949    .f.d3 mark add particle0 17
    5050    .f.d3 mark add particle1 10
  • trunk/examples/video/piv/intro.html

    r1928 r2023  
    11<html>
    22    <body>
    3         <h1>PIV tool</h1>
    4         <p>add info about how piv tool works</p>
     3        <center>
     4            <h1>ParticleVE</h1>
     5            <h2>a particle tracking velocimetry tool</h2>
     6        </center>
     7        <p>
     8            Track particles in videos to calculate an estimate of
     9            their velocity.
     10        </p>
     11
     12        <h3>What is Particle Velocity Estimation</h3>
     13        <p>
     14        <!-- text from wikipedia -->
     15Particle tracking velocimetry (PTV) is a velocimetry method, i.e a technique to measure velocity of particles. The name suggests that the particles are tracked, and not only recorded as an image as it is suggested in another form, particle image velocimetry. There are two very different experimental methods:
     16
     17    * the two dimensional (2D) modification of Particle Image Velocimetry (PIV), in which the flow field is measured in the two-dimensional slice of the flow, illuminated by a laser sheet (a thin plane) and low density of seeded particles allow for the tracking each of them individually for several frames.
     18    * the Three-Dimensional Particle tracking velocimetry (3D-PTV) is a distinctive experimental technique, based on multiple camera-system, three-dimensional volume illumination and tracking of flow tracers (i.e. particles) in three-dimensional space by using photogrammetric principles.
     19        </p>
     20        <h3>Get Started:</h3>
     21        <ol>
     22            <li>Choose a video to track particles in.</li>
     23            <li>Preview the video, searching for interesting frames.</li>
     24            <li>Mark particle locations and analyze the frames.</li>
     25        </ol>
     26        <center>
     27            <img src="images/pve_demo_small.png"/>
     28        </center>
     29
     30        <h3>Practical Applications:</h3>
     31        <p></p>
     32
     33        <h3>Learn More:</h3>
     34        <ol>
     35            <li><a href="http://wikipedia.org/wiki/Particle_tracking_velocimetry">Particle Tracking Velocimetry (PTV)</a></li>
     36            <li><a href="http://wikipedia.org/wiki/Particle_image_velocimetry">Particle Image Velocimetry (PIV)</a></li>
     37        </ol>
    538    </body>
    639</html>
  • trunk/examples/video/piv/piv.tcl

    r1979 r2023  
    77package require RapptureGUI
    88package require BLT
     9package require Img
    910
    1011
     
    3637wm title . "particle velocity estimate"
    3738wm withdraw .
     39set width 960
     40set height 625
     41
     42set installdir [file dirname [ \
     43                Rappture::utils::expandPath [ \
     44                file normalize [info script]]]]
     45
    3846
    3947
     
    5361set f [$nb insert end about]
    5462
    55 # loader for videos
    5663
    57 set loader [frame $f.loader]
    5864
    59 label $loader.icon -image [Rappture::icon folder]
    60 pack $loader.icon -side left
    61 label $loader.name -borderwidth 1 -relief solid -background white -anchor w
    62 pack $loader.name -side left -expand yes -fill x -padx 2
    63 button $loader.go -text "Upload..."
    64 pack $loader.go -side right
     65# html intro page
    6566
    66 # create an html intro page
    67 
    68 set intro [frame $f.intro -borderwidth 1 -width 300 -height 300]
     67set intro [frame $f.intro]
    6968
    7069Rappture::Scroller $intro.scroller -xscrollmode auto -yscrollmode auto
     
    7978$intro.scroller.html load $html
    8079
    81 set demo [frame $f.demo]
    8280
     81# verticle divider
     82set div [frame $f.div -width 1 -background black]
     83
     84
     85set previewVar ""
     86
     87# movie chooser
     88
     89set chooser [frame $f.chooser_f]
     90
     91set fid [open [file join $installdir images step1.png] r]
     92fconfigure $fid -translation binary -encoding binary
     93set data [read $fid]
     94close $fid
     95set imh [image create photo]
     96$imh put $data
     97label $chooser.step1 -image $imh
     98
     99set vc [Rappture::VideoChooser $chooser.vc -variable ::previewVar]
     100$vc load [glob "/home/derrick/projects/piv/video/*.mp4"]
     101# $vc load [glob "/apps/piv/video/*.mp4"]
     102
     103pack $chooser.step1 -side top -anchor w -pady 8
     104pack $vc -side bottom -anchor center
     105
     106
     107
     108# movie previewer
     109
     110set preview [frame $f.preview_f]
     111
     112set fid [open [file join $installdir images step2.png] r]
     113fconfigure $fid -translation binary -encoding binary
     114set data [read $fid]
     115close $fid
     116set imh [image create photo]
     117$imh put $data
     118label $preview.step2 -image $imh
     119
     120set vp [Rappture::VideoPreview $preview.preview -variable ::previewVar]
     121
     122pack $preview.step2 -side top -anchor w -pady 8
     123pack $vp -side bottom -anchor center
     124
     125
     126
     127# analyze button gets us to the analyze page
     128
     129set analyze [frame $f.analyze_f]
     130
     131set fid [open [file join $installdir images step3.png] r]
     132fconfigure $fid -translation binary -encoding binary
     133set data [read $fid]
     134close $fid
     135set imh [image create photo]
     136$imh put $data
     137label $analyze.step3 -image $imh
     138
     139button $analyze.go \
     140    -text "Analyze" \
     141    -command {
     142        $vp video stop
     143        $vs load file $previewVar
     144        $vs video seek [$vp query framenum]
     145        $nb current next>
     146        # FIXME: video loaded into memory twice
     147    }
     148pack $analyze.step3 -side left -anchor w
     149pack $analyze.go -anchor center
     150
     151
     152set reqwidth [expr round($width/2.0)]
    83153blt::table $f \
    84     0,0 $intro -rowspan 3 -fill both \
    85     0,1 $demo -fill x \
    86     1,1 $loader -fill x
     154    0,0 $intro -rowspan 3 -fill both -reqwidth $reqwidth\
     155    0,1 $div -rowspan 3 -fill y -pady 8 -padx 8\
     156    0,2 $chooser -fill x -padx {0 8}\
     157    1,2 $preview -fill x \
     158    2,2 $analyze -fill x
    87159
    88 blt::table configure $f c* -resize both
     160blt::table configure $f c0 -resize none
     161blt::table configure $f c1 -resize none
     162blt::table configure $f c2 -resize none
    89163# blt::table configure $f r0 -pady 1
    90164
     
    94168
    95169set f [$nb insert end video]
    96 set movieViewer [Rappture::VideoScreen $f.viewer]
    97 $loader.go configure -command {$nb current next>; $movieViewer loadcb}
     170set vs [Rappture::VideoScreen $f.viewer -fileopen {$nb current about}]
     171pack $vs -expand yes -fill both
    98172
    99 pack $movieViewer -expand yes -fill both
    100173
    101174# ------------------------------------------------------------------
     
    103176# ------------------------------------------------------------------
    104177
     178
    105179$nb current about
    106 wm geometry . 900x600
     180wm geometry . ${width}x${height}
    107181wm deiconify .
    108 update idletasks
    109182
    110 # for testing we automatically load a video
    111 array set videoFiles [list \
    112     1 "/home/derrick/projects/piv/video/TOPHAT_06-03-10_16-05-55.mp4" \
    113     2 "/home/derrick/projects/piv/video/TOPHAT_06-03-10_16-09-56.mp4" \
    114     3 "/home/derrick/projects/piv/video/TOPHAT_06-03-10_16-13-56.mp4" \
    115     4 "/home/derrick/junk/coa360download56Kbps240x160.mpg" \
    116 ]
    117 $nb current video
    118 update idletasks
    119 $movieViewer load file $videoFiles(1)
     183#update idletasks
     184#image delete $imh
  • trunk/gui/scripts/Makefile.in

    r1979 r2023  
    114114                $(srcdir)/utils.tcl \
    115115                $(srcdir)/valueresult.tcl \
     116                $(srcdir)/videochooser.tcl \
     117                $(srcdir)/videochooserinfo.tcl \
    116118                $(srcdir)/videodial.tcl \
     119                $(srcdir)/videodial1.tcl \
     120                $(srcdir)/videodial2.tcl \
    117121                $(srcdir)/videodistance.tcl \
    118122                $(srcdir)/videoscreen.tcl \
     123                $(srcdir)/videospeed.tcl \
    119124                $(srcdir)/videoparticle.tcl \
     125                $(srcdir)/videopreview.tcl \
    120126                $(srcdir)/visviewer.tcl \
    121127                $(srcdir)/vtkviewer.tcl \
  • trunk/gui/scripts/videodial.tcl

    r1979 r2023  
    682682        foreach {x0 y0 x1 y1} [$c bbox $item] break
    683683        if {! [info exists y1]} continue
    684          puts stderr "$item : [expr $y1-$y0]: $y0 $y1"
     684        puts stderr "$item : [expr $y1-$y0]: $y0 $y1"
    685685        lappend q $y0 $y1
    686686    }
  • trunk/gui/scripts/videoscreen.tcl

    r1979 r2023  
    1717
    1818option add *Video.width 300 widgetDefault
    19 option add *Video*cursor crosshair widgetDefault
    2019option add *Video.height 300 widgetDefault
    2120option add *Video.foreground black widgetDefault
    2221option add *Video.controlBackground gray widgetDefault
    23 option add *Video.controlDarkBackground #999999 widgetDefault
    24 option add *Video.plotBackground black widgetDefault
    25 option add *Video.plotForeground white widgetDefault
    26 option add *Video.plotOutline gray widgetDefault
    2722option add *Video.font \
    2823    -*-helvetica-medium-r-normal-*-12-* widgetDefault
     
    3126    inherit itk::Widget
    3227
    33     itk_option define -plotforeground plotForeground Foreground ""
    34     itk_option define -plotbackground plotBackground Background ""
    35     itk_option define -plotoutline plotOutline PlotOutline ""
    3628    itk_option define -width width Width -1
    3729    itk_option define -height height Height -1
     30    itk_option define -fileopen fileopen Fileopen ""
    3831
    3932    constructor { args } {
     
    109102
    110103    array set _settings [subst {
    111         $this-currenttime       0
    112104        $this-framenum          0
    113105        $this-loop              0
     
    122114
    123115
    124 
    125116    # Create flow controls...
    126117
     
    132123        rename -background -controlbackground controlBackground Background
    133124    }
    134 
    135     # pack $itk_component(main) -side top -expand yes -fill both
    136125    bind $itk_component(main) <Configure> [itcl::code $this fixSize]
     126
     127    # hold the video frames in an image on the canvas
     128    set _imh [image create photo]
     129    $itk_component(main) create image 0 0 -anchor nw -image $_imh
    137130
    138131    # setup movie controls
     
    154147    set imagesDir [file join $RapptureGUI::library scripts images]
    155148
     149    # ==== fileopen ====
     150    itk_component add fileopen {
     151        button $itk_component(moviecontrols).fileopen \
     152            -borderwidth 1 -padx 1 -pady 1 \
     153            -image [Rappture::icon upload] \
     154            -command [itcl::code $this loadcb]
     155            #-command [Rappture::filexfer::upload {piv tool} {id label desc} [itcl::code $this Upload]]
     156            #-command [itcl::code $this video seek 0]
     157    } {
     158        usual
     159        ignore -borderwidth
     160        rename -highlightbackground -controlbackground controlBackground \
     161            Background
     162    }
     163    Rappture::Tooltip::for $itk_component(fileopen) \
     164        "Open file"
    156165
    157166    # ==== measuring tool ====
     
    254263        "Play continuously between marked sections"
    255264
    256     # Video Dial
    257265    itk_component add dial {
    258         Rappture::Videodial $itk_component(moviecontrols).dial \
     266        frame $itk_interior.dial
     267    } {
     268        usual
     269        rename -background -controlbackground controlBackground Background
     270    }
     271
     272    # Video Dial Major
     273    itk_component add dialmajor {
     274        Rappture::Videodial1 $itk_component(dial).dialmajor \
    259275            -length 10 -valuewidth 0 -valuepadding 0 -padding 6 \
    260276            -linecolor "" -activelinecolor "" \
    261277            -min 0 -max 1 \
    262             -minortick 1 -majortick 5 \
    263             -variable [itcl::scope _settings($this-currenttime)] \
     278            -variable [itcl::scope _settings($this-framenum)] \
    264279            -dialoutlinecolor black \
    265280            -knobimage [Rappture::icon knob2] -knobposition center@middle
     
    269284        rename -background -controlbackground controlBackground Background
    270285    }
    271     $itk_component(dial) current 0
    272     bind $itk_component(dial) <<Value>> [itcl::code $this video update]
     286    $itk_component(dialmajor) current 0
     287    bind $itk_component(dialmajor) <<Value>> [itcl::code $this video update]
     288
     289    # Video Dial Minor
     290    itk_component add dialminor {
     291        Rappture::Videodial2 $itk_component(dial).dialminor \
     292            -padding 0 \
     293            -min 0 -max 1 \
     294            -minortick 1 -majortick 5 \
     295            -variable [itcl::scope _settings($this-framenum)] \
     296            -dialoutlinecolor black
     297    } {
     298        usual
     299        rename -background -controlbackground controlBackground Background
     300    }
     301    $itk_component(dialminor) current 0
     302    bind $itk_component(dialminor) <<Value>> [itcl::code $this video update]
    273303
    274304    itk_component add framenumlabel {
     
    282312
    283313    # Current Frame Number
    284     #set ffont "arial 9"
    285     #set fwidth [calcLabelWidth $ffont]
    286314    itk_component add framenum {
    287315        label $itk_component(frnumfr).framenum \
     
    293321        rename -background -controlbackground controlBackground Background
    294322    }
    295     #$itk_component(framenum) value 1
    296     #bind $itk_component(framenum) <<Value>> \
    297     #    [itcl::code $this video seek -framenum]
    298323    Rappture::Tooltip::for $itk_component(framenum) \
    299324        "Current frame number"
     
    315340    # Speed
    316341    itk_component add speed {
    317         Rappture::Flowspeed $itk_component(moviecontrols).speed \
    318             -min 1 -max 10 -width 3 -font "arial 9"
     342        Rappture::Videospeed $itk_component(moviecontrols).speed \
     343            -min 0 -max 1 -width 4 -font "arial 9" -factor 2
    319344    } {
    320345        usual
     
    325350        "Change speed of movie"
    326351
    327     $itk_component(speed) value 1
     352    $itk_component(speed) value 0.25
    328353    bind $itk_component(speed) <<Value>> [itcl::code $this video speed]
    329354
    330355
     356    blt::table $itk_component(dial) \
     357        0,0 $itk_component(dialmajor) -fill x \
     358        1,0 $itk_component(dialminor) -fill x
     359
     360
    331361    blt::table $itk_component(moviecontrols) \
    332         0,0 $itk_component(measure) -padx {2 0}  \
    333         0,1 $itk_component(particle) -padx {4 0} \
     362        0,0 $itk_component(fileopen) -padx {2 0}  \
     363        0,1 $itk_component(measure) -padx {4 0}  \
     364        0,2 $itk_component(particle) -padx {4 0} \
    334365        0,5 $itk_component(dial) -fill x -padx {2 4} -rowspan 3 \
    335366        1,0 $itk_component(rewind) -padx {2 0} \
     
    361392itcl::body Rappture::VideoScreen::destructor {} {
    362393    array unset _settings $this-*
     394    if {[info exists _imh]} {
     395        image delete $_imh
     396    }
    363397}
    364398
     
    394428    }
    395429
     430    if {([info exists _movie]) && ("" != ${_movie})} {
     431        ${_movie} release
     432    }
     433
    396434    set _movie [Rappture::Video $type $data]
    397435    file delete $fname
    398436    set _framerate [${_movie} get framerate]
    399     set _mspf [expr round(((1.0/${_framerate})*1000)/pow(2,$_settings($this-speed)-1))]
    400     set _delay [expr {${_mspf} - ${_ofrd}}]
    401     puts stderr "framerate = ${_framerate}"
    402     puts stderr "mspf = ${_mspf}"
    403     puts stderr "ofrd = ${_ofrd}"
    404     puts stderr "delay = ${_delay}"
    405 
    406     ${_movie} seek 0
     437    video speed
     438
     439    video seek 0
     440
     441    # update the dial and framenum widgets
     442    set _settings($this-framenum) 0
     443
    407444
    408445    # setup the image display
    409446
    410     set _imh [image create photo]
    411447    foreach {w h} [query dimensions] break
    412448    if {${_width} == -1} {
     
    416452        set _height $h
    417453    }
    418     $itk_component(main) create image 0 0 -anchor nw -image $_imh
    419454
    420455    set _lastFrame [$_movie get position end]
    421456
    422457    # update the dial with video information
    423     $itk_component(dial) configure -min 0 -max ${_lastFrame}
     458    $itk_component(dialmajor) configure -min 0 -max ${_lastFrame}
     459    $itk_component(dialminor) configure -min 0 -max ${_lastFrame}
    424460
    425461    fixSize
     
    466502    }
    467503
    468     set _width [winfo width $itk_component(main)]
    469     set _height [winfo height $itk_component(main)]
     504#    set _width [winfo width $itk_component(main)]
     505#    set _height [winfo height $itk_component(main)]
     506#
     507#    # get an image with the new size
     508#    ${_imh} put [${_movie} get image ${_width} ${_height}]
     509#
     510#    # fix the dimesions of the canvas
     511#    #$itk_component(main) configure -width ${_width} -height ${_height}
     512#
     513#    $itk_component(main) configure -scrollregion [$itk_component(main) bbox all]
     514
     515######################
    470516
    471517    # get an image with the new size
    472518    ${_imh} put [${_movie} get image ${_width} ${_height}]
    473 
    474     # fix the dimesions of the canvas
    475     #$itk_component(main) configure -width ${_width} -height ${_height}
    476 
    477     $itk_component(main) configure -scrollregion [$itk_component(main) bbox all]
     519    puts stderr "${_width} ${_height}"
     520
     521    # fix the dimesions of the video canvas
     522    $itk_component(main) configure -width ${_width} -height ${_height}
    478523}
    479524
     
    486531        "play" {
    487532            if {$_settings($this-play) == 1} {
    488                 # disable seek while playing
    489                 # bind $itk_component(dial) <<Value>> ""
    490533                eventually play
    491534            } else {
     
    494537                set _pendings(play) 0
    495538                set _settings($this-play) 0
    496                 # enable seek while paused
    497                 # bind $itk_component(dial) <<Value>> [itcl::code $this updateFrame]
    498539            }
    499540        }
     
    507548        "speed" {
    508549            set speed [$itk_component(speed) value]
    509             set _mspf [expr round(((1.0/${_framerate})*1000)/pow(2,$speed-1))]
     550            set _mspf [expr round(((1.0/${_framerate})*1000)/$speed)]
    510551            set _delay [expr {${_mspf} - ${_ofrd}}]
    511552            puts stderr "_mspf = ${_mspf} | $speed | ${_ofrd} | ${_delay}"
    512553        }
    513554        "update" {
    514             #video stop
    515             # eventually seek [expr round($_settings($this-currenttime))]
    516             Seek [expr round($_settings($this-currenttime))]
    517             # Seek $_settings($this-framenum)
    518             #after idle [itcl::code $this video play]
     555            # eventually seek [expr round($_settings($this-framenum))]
     556            Seek [expr round($_settings($this-framenum))]
    519557        }
    520558        default {
     
    555593itcl::body Rappture::VideoScreen::Play {} {
    556594
     595    set cur ${_nextframe}
     596
    557597    # time how long it takes to retrieve the next frame
    558598    set _ofrd [time {
    559         $_movie seek $_nextframe
     599        # use seek instead of next fxn incase the ${_nextframe} is
     600        # not the current frame+1. this happens when we skip frames
     601        # because the underlying c lib is too slow at reading.
     602        $_movie seek $cur
    560603        $_imh put [$_movie get image ${_width} ${_height}]
    561604    } 1]
     
    574617
    575618    # update the dial and framenum widgets
    576     set _settings($this-currenttime) $cur
    577619    set _settings($this-framenum) $cur
    578620
    579     if {[expr $cur%100] == 0} {
    580 #        puts stderr "ofrd = ${_ofrd}"
    581 #        puts stderr "delay = ${_delay}"
    582 #        puts stderr "after: [after info]"
    583 #        puts stderr "id = ${_id}"
    584     }
    585621
    586622    # no play cmds pending
     
    590626    # then loop back to loopstart when cur hits loopend
    591627    if {$_settings($this-loop)} {
    592         if {$cur == [$itk_component(dial) mark position loopend]} {
    593             Seek [$itk_component(dial) mark position loopstart]
     628        if {$cur == [$itk_component(dialminor) mark position loopend]} {
     629            Seek [$itk_component(dialminor) mark position loopstart]
    594630        }
    595631    }
     
    598634    if {$cur < ${_lastFrame}} {
    599635        set _id [after ${_delay} [itcl::code $this eventually play]]
    600     }
    601 
    602 #    event generate $itk_component(hull) <<Frame>>
     636    } else {
     637        video stop
     638    }
     639
     640    event generate $itk_component(hull) <<Frame>>
    603641}
    604642
     
    624662
    625663    # update the dial and framenum widgets
     664    set _settings($this-framenum) [$_movie get position cur]
    626665    event generate $itk_component(main) <<Frame>>
    627     set cur [$_movie get position cur]
    628     set _settings($this-currenttime) $cur
    629     set _settings($this-framenum) $cur
    630666
    631667}
     
    836872            ${_obj} Coords $x $y $x $y
    837873            ${_obj} Show object
    838             $itk_component(dial) mark add arrow current
     874            $itk_component(dialminor) mark add arrow current
    839875        }
    840876        "drag" {
     
    898934            ${_obj} Coords $x $y
    899935            ${_obj} Show object
    900             $itk_component(dial) mark add $name current
     936            $itk_component(dialminor) mark add $name current
    901937            # bind $itk_component(hull) <<Frame>> [itcl::code $itk_component(main).$name UpdateFrame]
    902938
     
    9931029# ----------------------------------------------------------------------
    9941030itcl::body Rappture::VideoScreen::writeText {x y text color tags width} {
    995     # write text up-left
    996     $itk_component(main) create text [expr $x-1] [expr $y-1] \
     1031    $itk_component(main) create text [expr $x-1] [expr $y] \
    9971032        -tags $tags \
    9981033        -justify center \
     
    10011036        -width $width
    10021037
    1003     # write text down-right
    1004     $itk_component(main) create text [expr $x+1] [expr $y+1] \
     1038    $itk_component(main) create text [expr $x+1] [expr $y] \
    10051039        -tags $tags \
    10061040        -justify center \
     
    10081042        -fill black \
    10091043        -width $width
     1044
     1045    $itk_component(main) create text [expr $x] [expr $y-1] \
     1046        -tags $tags \
     1047        -justify center \
     1048        -text $text \
     1049        -fill black \
     1050        -width $width
     1051
     1052    $itk_component(main) create text [expr $x] [expr $y+1] \
     1053        -tags $tags \
     1054        -justify center \
     1055        -text $text \
     1056        -fill black \
     1057        -width $width
     1058
     1059#    # write text up-left
     1060#    $itk_component(main) create text [expr $x-1] [expr $y-1] \
     1061#        -tags $tags \
     1062#        -justify center \
     1063#        -text $text \
     1064#        -fill black \
     1065#        -width $width
     1066#
     1067#    # write text down-right
     1068#    $itk_component(main) create text [expr $x+1] [expr $y+1] \
     1069#        -tags $tags \
     1070#        -justify center \
     1071#        -text $text \
     1072#        -fill black \
     1073#        -width $width
    10101074
    10111075    # write text at x,y
     
    10311095
    10321096    if {($frames != 0) && (${_px2dist} != 0)} {
    1033         set t [expr 1.0*$px/$frames/${_px2dist}*${_framerate}]
     1097        set t [expr 1.0*$px/$frames*${_px2dist}*${_framerate}]
    10341098    } else {
    10351099        set t 0.0
     
    10441108itcl::body Rappture::VideoScreen::toggleloop {} {
    10451109    if {$_settings($this-loop) == 0} {
    1046         $itk_component(dial) mark remove loopstart
    1047         $itk_component(dial) mark remove loopend
     1110        $itk_component(dialminor) mark remove loopstart
     1111        $itk_component(dialminor) mark remove loopend
    10481112    } else {
    10491113        set cur [$_movie get position cur]
     
    10601124        }
    10611125
    1062         $itk_component(dial) mark add loopstart $startframe
    1063         $itk_component(dial) mark add loopend $endframe
     1126        $itk_component(dialminor) mark add loopstart $startframe
     1127        $itk_component(dialminor) mark add loopend $endframe
    10641128    }
    10651129
     
    10741138        error "bad value: \"$itk_option(-width)\": width should be an integer"
    10751139    }
    1076     set ${_width} $itk_option(-width)
     1140    set _width $itk_option(-width)
    10771141    after idle [itcl::code $this fixSize]
    10781142}
     
    10861150        error "bad value: \"$itk_option(-height)\": height should be an integer"
    10871151    }
    1088     set ${_height} $itk_option(-height)
     1152    set _height $itk_option(-height)
    10891153    after idle [itcl::code $this fixSize]
    10901154}
     1155
     1156# ----------------------------------------------------------------------
     1157# OPTION: -fileopen
     1158# ----------------------------------------------------------------------
     1159itcl::configbody Rappture::VideoScreen::fileopen {
     1160    $itk_component(fileopen) configure -command $itk_option(-fileopen)
     1161}
  • trunk/lang/tcl/src/RpVideoTclInterface.cc

    r1925 r2023  
    3030
    3131static Rp_OpSpec rpVideoOps[] = {
    32     {"get",  1, (void *)GetOp, 3, 5, "[image ?width height?]|[position cur|end]|[framerate]",},
     32    {"get",   1, (void *)GetOp, 3, 5, "[image ?width height?]|[position cur|end]|[framerate]",},
    3333    {"next",  1, (void *)NextOp, 2, 2, "",},
     34    {"release", 1, (void *)ReleaseOp, 2, 2, "",},
    3435    {"seek",  1, (void *)SeekOp, 3, 3, "+n|-n|n",},
    3536    {"size",  1, (void *)SizeOp, 2, 2, "",},
    36     {"release", 1, (void *)ReleaseOp, 2, 2, "",},
    3737};
    3838
     
    243243         Tcl_Obj *const *objv)
    244244{
    245 
    246 //    void *img = NULL;
    247 //    int width = 960;
    248 //    int height = 540;
    249 //    int bufSize = 0;
    250 
    251245    int pos = 0;
    252246    VideoGoNext((VideoObj *)clientData);
    253247    VideoGetPositionCur((VideoObj *)clientData,&pos);
    254248    Tcl_SetObjResult(interp, Tcl_NewIntObj(pos));
    255 //    VideoGetImage((VideoObj *)clientData, width, height, &img, &bufSize);
    256 
    257 //    Tcl_SetByteArrayObj(Tcl_GetObjResult(interp),
    258 //                        (const unsigned char*)img, bufSize);
    259249
    260250    return TCL_OK;
     
    277267         Tcl_Obj *const *objv)
    278268{
    279 
    280 //    void *img = NULL;
    281 //    int width = 960;
    282 //    int height = 540;
    283 //    int bufSize = 0;
    284269    const char *val_s = NULL;
    285270    int val = 0;
     
    311296        int c = 0;
    312297        c = VideoGoToN((VideoObj *)clientData, val);
    313         // printf("c = %d\tval = %d\n",c,val);
    314     }
    315 
    316 //    VideoGetImage((VideoObj *)clientData, width, height, &img, &bufSize);
    317 
    318 //    if (img == NULL) {
    319 //        printf("img is null\n");
    320 //    }
    321 
    322 //    Tcl_SetByteArrayObj(Tcl_GetObjResult(interp),
    323 //                        (const unsigned char*)img, bufSize);
     298    }
    324299
    325300    VideoGetPositionCur((VideoObj *)clientData,&pos);
  • trunk/src/objects/RpVideo.c

    r1983 r2023  
    8383    char mode[64];
    8484    char fmt[64];
     85    int lastframe;
    8586
    8687    /* tmp buffer to give images back to user */
     
    154155    *vid->mode = '\0';
    155156    *vid->fmt = '\0';
     157    vid->lastframe = 0;
    156158
    157159    vid->img = NULL;
     
    171173    int fnlen = 0;
    172174    int err = 0;
     175    int lastframe = 0;
    173176
    174177    if (fileName == NULL) {
     
    206209            return err;
    207210        }
     211
     212        VideoFindLastFrame(vidPtr,&lastframe);
     213        vidPtr->lastframe = lastframe;
    208214    } else if (*mode == 'w') {
    209215        /* we're now in "input" mode */
     
    216222    return 0;
    217223}
     224
     225/*
     226 * ------------------------------------------------------------------------
     227 *  VideoFindLastFrame()
     228 *
     229 *  Find the last readable frame.
     230 * ------------------------------------------------------------------------
     231 */
     232int
     233VideoFindLastFrame(vidPtr,lastframe)
     234    VideoObj *vidPtr;
     235    int *lastframe;
     236{
     237    int f = 0;
     238    int nframe = 0;
     239    int cur = 0;
     240    AVStream *vstreamPtr;
     241
     242    if (vidPtr == NULL) {
     243        return -1;
     244    }
     245
     246    if (lastframe == NULL) {
     247        return -1;
     248    }
     249
     250    if (VideoModeRead(vidPtr) != 0) {
     251        return -1;
     252    }
     253
     254    // calculate an estimate of the last frame
     255    vstreamPtr = vidPtr->pFormatCtx->streams[vidPtr->videoStream];
     256    nframe = VideoTime2Frame(vstreamPtr,
     257        vstreamPtr->start_time + vstreamPtr->duration);
     258
     259    // get the real last readable frame
     260    // is 50 frames far enough to go back
     261    // to be outside of the last key frame?
     262    f = vidPtr->frameNumber;
     263    cur = VideoGoToN(vidPtr,nframe-50);
     264    while (cur != nframe) {
     265        cur = nframe;
     266        nframe = VideoGoNext(vidPtr);
     267    }
     268    *lastframe = nframe;
     269    VideoGoToN(vidPtr,f);
     270
     271    return 0;
     272}
     273
    218274
    219275/*
     
    822878    VideoObj *vidPtr;
    823879{
    824     return VideoGoPlusMinusN(vidPtr,1);
     880    int nabs;
     881
     882    if (vidPtr == NULL) {
     883        return -1;
     884    }
     885
     886    nabs = vidPtr->frameNumber + 1;
     887    return VideoGoToN(vidPtr, nabs);
    825888}
    826889
     
    910973        /* get at least one frame, unless we're done or at the beginning*/
    911974        if (!gotframe && !vidPtr->atEnd) {
    912             VideoNextFrame(vidPtr);
     975            if (vidPtr->frameNumber > nabs) {
     976                // we are probably at a key frame, just past
     977                // the requested frame and need to seek backwards.
     978                VideoGoToN(vidPtr,n);
     979            } else {
     980                VideoNextFrame(vidPtr);
     981            }
    913982        }
    914983    }
     
    10401109                free(vidPtr->img);
    10411110                VideoAllocImgBuffer(vidPtr,iw,ih);
    1042             } else {
    1043                 // image buffer is the correct size
    1044                 // do nothing
    10451111            }
    10461112        }
     
    11551221    int *pos;
    11561222{
    1157     int nframe = -1;
    11581223    AVStream *vstreamPtr;
    11591224
     
    11701235    }
    11711236
    1172     if (vidPtr->pFormatCtx) {
    1173         vstreamPtr = vidPtr->pFormatCtx->streams[vidPtr->videoStream];
    1174         nframe = VideoTime2Frame(vstreamPtr,
    1175             vstreamPtr->start_time + vstreamPtr->duration);
    1176     }
    1177 
    1178     *pos = nframe;
     1237    *pos = vidPtr->lastframe;
    11791238    return 0;
    11801239}
Note: See TracChangeset for help on using the changeset viewer.