#!/usr/bin/env wish # Different values for the following variables can be put into set dataInput /shared/sos/render set dataOutputDir /shared/sos/media/mp4 set dataOutputFile output set dataOutputFormat mp4 set dataOutput /shared/sos/media/mp4/output.mp4 set frameRate 30 set bitRate 25000 set size 1600x800 set useQscale 1 set pass 2 # Allow site configuration to override defaults. if { [ file readable ~/.createMovie-guirc ] } { puts stderr "Using initialization file ~/.createMovie-guirc" soure ~/.createMovie-guirc } proc frameRateOption { } { global frameRate if { [string length $frameRate ] > 0 } { return "$frameRate" } else { return "30" } } proc bitRateOption { } { global bitRate if { [string length $bitRate ] > 0 } { return "$bitRate" } else { return "25000" } } proc sizeOption { } { global size if { [string length $size ] > 0 } { return "$size" } else { return "1600x800" } } proc waiton { proc } { puts stderr "waiton: waiting on $proc" global progress while { 1 } { if { [catch "exec ps -p $proc | wc -l" nlines] } { return } elseif { $nlines < 2 } { return } after 1000 set progress [expr $progress % 100 + 1] update } } proc waitForProcs { plist } { while { [llength $plist] > 0 } { set proc [lindex $plist 0] set plist [lrange $plist 1 end] waiton $proc } } proc getDataInput { } { global dataInput set dir [tk_chooseDirectory -initialdir $dataInput -mustexist true \ -title "Choose Input Directory"] if { [string length $dir] > 0 } { set dataInput $dir } # If the directory starts with /sos, use /shared/sos instead so # all hosts have access via nfs. if { [string match "/sos/*" $dir] } { set dataInput /shared${dir} } } proc setDataOutput { } { global dataOutput global dataOutputFile set typeName { {{mp4} {.mp4} } {{mpeg2} {.mpeg} } } set file [tk_getSaveFile -initialfile $dataOutputFile \ -filetypes $typeName -title "Choose Save FileName"] if { [string length $file] > 0 } { set dataOutput $file } if { [string match "/sos/*" $file] } { set dataOutput /shared${file} } } # setting order of input data file proc listFiles {} { global dataInput global fileList cd $dataInput set fileList [lsort [glob *]] } # To make a unify filename for ffmpeg proc makeLink {} { global dataInput global dataOutput global dataOutputDir global fileList set dataOutputDir [string range $dataOutput 0 [expr [string last / $dataOutput] - 1]] set tmpDir "$dataOutputDir/imageTmp" set idx 1000001 if { ![file exists $tmpDir] } { exec mkdir $tmpDir } listFiles foreach file $fileList { if { [catch "exec ln -s $dataInput/$file $tmpDir/image$idx.jpg" msg] } { puts stderr "$msg \n" } puts stdout "$file link $tmpDir/image$idx.jpg \n" set idx [expr $idx+1] } } proc removeLink {} { global dataOutputDir if { [catch "exec rm -rf $dataOutputDir/imageTmp " msg] } { puts stderr "$msg \n" } puts stdout "remove files from $dataOutputDir/imageTmp/ \n" } proc call_ffmpeg { } { global dataOutput global dataOutputDir global dataFormat if { ![string match {*.mp4} $dataOutput] } { if { ![string match {*.mpeg} $dataOutput] } { append dataOutput ".mp4" } } puts stderr "[exec date] --Movie Create Starting" makeLink set ffmpegPath [exec which ffmpeg] lappend ps [exec $ffmpegPath -i $dataOutputDir/imageTmp/image1%6d.jpg -r [frameRateOption] -b [bitRateOption] -s [sizeOption] -qscale 1 -y $dataOutput &] waitForProcs $ps removeLink } proc make_movie { } { global progress global dataOutput .buttons.run configure -state disabled call_ffmpeg tk_messageBox -message "Movie is created successfully \n" set answer [tk_messageBox -message "Movie Preview?" -type yesno -icon question] switch -- $answer { yes { exec ffplay $dataOutput & } no { } } .buttons.run configure -state normal } proc exit_this { } { removeLink exec killall ffmpeg & exec killall ffplay & exit } proc newDialogBox { } { label .filesLabel -text "Create a MP4 Movie" -relief flat grid .filesLabel - -sticky ew -padx 4 -pady 2 button .getDataInput -text "Input Dir:" -command getDataInput entry .dataInput -textvariable dataInput -width 40 grid .getDataInput .dataInput -sticky ew -padx 4 -pady 2 button .setDataOutput -text "Output File:" -command setDataOutput entry .dataOutput -textvariable dataOutput -width 40 grid .setDataOutput .dataOutput -sticky ew -padx 4 -pady 2 frame .space1 -height 20 grid .space1 label .optionsLabel -text "Options" -relief flat grid .optionsLabel - -sticky ew -padx 4 -pady 2 label .frameRateLabel -text "Frames Per Second:" entry .frameRate -textvariable frameRate -width 10 grid .frameRateLabel .frameRate -sticky ew -padx 4 -pady 2 label .bitRateLabel -text "Bitrate:" entry .bitRate -textvariable bitRate -width 10 grid .bitRateLabel .bitRate -sticky ew -padx 4 -pady 2 label .sizeLabel -text "Resolution:" entry .size -textvariable size -width 10 grid .sizeLabel .size -sticky ew -padx 4 -pady 2 label .statusLabel -text "Status" -relief flat grid .statusLabel - -sticky ew -padx 4 -pady 2 label .progressLabel -text "Bogus Progress %" scale .progress -orient horizontal -state disabled -variable progress grid .progressLabel .progress -sticky ew -padx 4 -pady 2 frame .buttons button .buttons.cancel -text "Exit" -command exit_this button .buttons.run -text "Execute" -command make_movie pack .buttons.cancel .buttons.run -side left -padx 10 grid x .buttons -sticky e -padx 4 -pady 2 } newDialogBox