00001 00002
00003 00004 00005 00006
00007 namespace eval display {
00008
00009 namespace eval video {
00010
00011 variable convertBin "convert"00012 variable mencoderBin "mencoder"00013 variable mplayerBin "mplayer"00014
00015 variable imagePrefix "display."00016 variable imageDir "images"00017 variable imageFormat "eps"00018 variable imageIndex 000019 variable imageNbDigits "4"00020 variable imageTmp "/tmp/display"00021
00022 variable videoOutput "display.avi"00023 variable videoCodec "mpeg4"00024 variable videoFps "15"00025 variable videoBitrate "2000"00026
00027 variable displayWindow00028
00029 proc init {displayWindow_} {
00030 00031 00032 00033 00034
00035 variable displayWindow
00036
00037 set displayWindow $displayWindow_
00038
00039 set w ".jafarDisplayVideo"
00040 toplevel $w
00041 wm title $w "Video"
00042 wm resizable $w 0 0
00043
00044 00045
00046 set fd "$w.dump"
00047 labelframe $fd -text "dump"
00048
00049 set fdf "$fd.filename"
00050 frame $fdf
00051
00052 label $fdf.imageDirLabel -text "dir:"
00053 entry $fdf.imageDir -textvariable ::display::video::imageDir
00054 label $fdf.imagePrefixLabel -text "prefix:"
00055 entry $fdf.imagePrefix -textvariable ::display::video::imagePrefix
00056 label $fdf.imageFormatLabel -text "format:"
00057 tk_optionMenu $fdf.imageFormat ::display::video::imageFormat "eps" "png"
00058 label $fdf.imageIndexLabel -text "index:"
00059 entry $fdf.imageIndex -width $::display::video::imageNbDigits -textvariable ::display::video::imageIndex
00060
00061 grid $fdf.imageDirLabel $fdf.imageDir
00062 grid $fdf.imagePrefixLabel $fdf.imagePrefix
00063 grid $fdf.imageIndexLabel $fdf.imageIndex
00064 grid $fdf.imageFormatLabel $fdf.imageFormat
00065
00066 grid configure $fdf.imageDirLabel $fdf.imagePrefixLabel $fdf.imageIndexLabel $fdf.imageFormatLabel -sticky "e"
00067 grid configure $fdf.imageIndex $fdf.imageFormat -sticky "w"
00068
00069 grid $fdf -padx 2 -pady 2 -sticky "w"
00070
00071 button $fd.dump -text "Dump" -command {::display::video::dump}
00072
00073 grid $fd.dump -padx 2 -pady 2 -sticky "e"
00074
00075 00076
00077 set fe "$w.encode"
00078 labelframe $fe -text "encode"
00079
00080 set fef "$fe.filename"
00081 frame $fef
00082
00083 label $fef.videoOutputLabel -text "output:"
00084 entry $fef.videoOutput -textvariable ::display::video::videoOutput
00085 label $fef.videoCodecLabel -text "format:"
00086 tk_optionMenu $fef.videoCodec $::display::video::videoCodec "mpeg4"
00087 label $fef.videoFpsLabel -text "fps:"
00088 entry $fef.videoFps -width 5 -textvariable ::display::video::videoFps
00089 label $fef.videoBitrateLabel -text "bitrate:"
00090 entry $fef.videoBitrate -width 5 -textvariable ::display::video::videoBitrate
00091
00092 grid $fef.videoOutputLabel $fef.videoOutput
00093 grid $fef.videoCodecLabel $fef.videoCodec
00094 grid $fef.videoFpsLabel $fef.videoFps
00095 grid $fef.videoBitrateLabel $fef.videoBitrate
00096
00097 grid configure $fef.videoOutputLabel $fef.videoCodecLabel $fef.videoFpsLabel $fef.videoBitrateLabel -sticky "e"
00098 grid configure $fef.videoOutput $fef.videoCodec $fef.videoFps $fef.videoBitrate -sticky "w"
00099
00100 grid $fef -padx 2 -pady 2 -sticky "e"
00101
00102 button $fe.encode -text "Encode" -command {::display::video::encode}
00103 button $fe.play -text "Play" -command {::display::video::play}
00104
00105 grid $fe.encode $fe.play -padx 2 -pady 2 -sticky "e"
00106
00107 00108
00109 set fc "$w.control"
00110 frame $fc
00111
00112 button $fc.close -text "Close" -command "destroy $w"
00113
00114 grid $fc.close -padx 2 -pady 2
00115
00116 grid $fd -sticky "we"
00117 grid $fe -sticky "we"
00118 grid $fc -sticky "e"
00119
00120 grid configure $fd $fe $fc -padx 2 -pady 2
00121 }00122
00123 proc dump {} {
00124 variable imageIndex
00125 variable imageFormat
00126 variable imageNbDigits
00127 variable imageTmp
00128 variable convertBin
00129 variable displayWindow
00130
00131 set index [format "%0${imageNbDigits}d" $imageIndex]
00132 switch $imageFormat {
00133 "eps" {display::dumpEps $displayWindow [getImageFilename $index]}
00134 "png" {
00135 display::dumpEps $displayWindow ${imageTmp}.eps
00136 exec $convertBin ${imageTmp}.eps [getImageFilename $index]
00137 exec rm -f ${imageTmp}.eps
00138 }
00139 }
00140 incr imageIndex
00141 }00142
00143 proc encode {} {
00144 variable mencoderBin
00145 variable videoOutput
00146 variable videoCodec
00147 variable videoFps
00148 variable videoBitrate
00149
00150 switch $videoCodec {
00151 "mpeg4" {
00152 set cmd "$mencoderBin mf://[getImageFilename] -mf fps=${videoFps} -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=${videoBitrate} -oac copy -o $videoOutput -ffourcc XVID"
00153 puts "\n$cmd \n"
00154
00155 if {[catch "exec $cmd >@stdout 2>@stderr" result]} {
00156 puts "$result"
00157 }
00158 }
00159 }
00160 }00161
00162 proc play {} {
00163 variable mplayerBin
00164 variable videoOutput
00165
00166 set cmd "$mplayerBin $videoOutput"
00167 puts "\n$cmd \n"
00168
00169 if {[catch "exec $cmd >@stdout 2>@stderr" result]} {
00170 puts "$result"
00171 }
00172 }00173
00174 proc getImageFilename {{index "*"}} {
00175 variable imageDir
00176 variable imagePrefix
00177 variable imageFormat
00178
00179 return [file join $imageDir "${imagePrefix}${index}.${imageFormat}"]
00180 }00181
00182 }00183 }00184
00185 package provide display 1.0