home *** CD-ROM | disk | FTP | other *** search
/ MPEG Toolkit / MPEG Toolkit.iso / os2 / mpegenc / misc / encode.tcl < prev    next >
Encoding:
Text File  |  1997-01-01  |  11.7 KB  |  519 lines

  1. #!encode_sh -f
  2.  
  3. proc nothing {} {}
  4.  
  5. proc tail {aList} \
  6. {
  7.     set length [llength $aList]
  8.     set index [expr $length-1]
  9.     set entry [lindex $aList $index]
  10.  
  11.     return $entry
  12. }
  13.  
  14.  
  15. proc GetPSearch {} \
  16. {
  17.     global psearchVar
  18.  
  19.     if { $psearchVar == "pExhaustButton" } then \
  20.     { SetPSearch EXHAUSTIVE } \
  21.     else \
  22.     {
  23.     if { $psearchVar == "pSubSampleButton" } then \
  24.          { SetPSearch SUBSAMPLE } \
  25.     else \
  26.          { SetPSearch LOGARITHMIC }
  27.     }
  28. }
  29.  
  30.  
  31. proc GetBSearch {} \
  32. {
  33.     global bsearchVar
  34.  
  35.     if { $bsearchVar == "bExhaustButton" } then \
  36.     { SetBSearch EXHAUSTIVE } \
  37.     else \
  38.     {
  39.     if { $bsearchVar == "bSimpleButton" } then \
  40.          { SetBSearch SIMPLE } \
  41.     else \
  42.          { SetBSearch CROSS2 }
  43.     }
  44. }
  45.  
  46.  
  47.     ###########
  48.     # Q-SCALE #
  49.     ###########
  50.  
  51. proc GetQScale {} \
  52. {
  53.     set valueI [.qScaleI get]
  54.     set valueP [.qScaleP get]
  55.     set valueB [.qScaleB get]
  56.  
  57.     SetQScale $valueI $valueP $valueB
  58. }
  59.  
  60.  
  61. proc QScale {} \
  62. {
  63.     scale .qScaleI -orient horizontal -label "I Q-scale" -from 1 -to 31
  64.     place .qScaleI -x 10 -y 640 -width 140
  65.  
  66.     scale .qScaleP -orient horizontal -label "P Q-scale" -from 1 -to 31
  67.     place .qScaleP -x 180 -y 640 -width 140
  68.  
  69.     scale .qScaleB -orient horizontal -label "B Q-scale" -from 1 -to 31
  70.     place .qScaleB -x 350 -y 640 -width 140
  71.  
  72.     .qScaleI set 8
  73.     .qScaleP set 16
  74.     .qScaleB set 25
  75. }
  76.  
  77.     ########################
  78.     # MOTION VECTOR SEARCH #
  79.     ########################
  80.  
  81.  
  82. proc MotionVectorSearch {} \
  83. {
  84.     global errorVar
  85.     global pixelVar
  86.     global psearchVar
  87.     global bsearchVar
  88.     global format
  89.  
  90.     radiobutton .buttonFull -text "Full Pixel" -variable pixelVar
  91.     radiobutton .buttonHalf -text "Half Pixel" -variable pixelVar
  92.  
  93.     place .buttonFull -x 90 -y 470
  94.     place .buttonHalf -x 90 -y 495
  95.  
  96.     .buttonFull select
  97.  
  98.     scale .searchScale -orient horizontal -label "Search Range" -from 2 -to 32
  99.     place .searchScale -x 255 -y 470 -width 130
  100.     .searchScale set 8
  101.  
  102.     label .psearchLabel -text "P-frame Search:"
  103.     place .psearchLabel -x 10 -y 535
  104.  
  105.     radiobutton .pExhaustButton -text "EXHAUSTIVE" -variable psearchVar
  106.     radiobutton .pSubSampleButton -text "SUBSAMPLE" -variable psearchVar
  107.     radiobutton .pLogarithmicButton -text "LOGARITHMIC" -variable psearchVar
  108.  
  109.     place .pExhaustButton -x 10 -y 560
  110.     place .pSubSampleButton -x 10 -y 585
  111.     place .pLogarithmicButton -x 10 -y 610
  112.  
  113.     .pExhaustButton select
  114.  
  115.     label .bsearchLabel -text "B-frame Search:"
  116.     place .bsearchLabel -x 255 -y 535
  117.  
  118.     radiobutton .bSimpleButton -text "SIMPLE" -variable bsearchVar
  119.     radiobutton .bCrossButton -text "CROSS2" -variable bsearchVar
  120.     radiobutton .bExhaustButton -text "EXHAUSTIVE" -variable bsearchVar
  121.  
  122.     place .bSimpleButton -x 255 -y 560
  123.     place .bCrossButton -x 255 -y 585
  124.     place .bExhaustButton -x 255 -y 610
  125.  
  126.     .bSimpleButton select
  127. }
  128.  
  129.  
  130. proc GetSearchRange {} \
  131. {
  132.     set value [.searchScale get]
  133.  
  134.     SetSearchRange $value
  135. }
  136.  
  137. proc GetPixelType {} \
  138. {
  139.     global pixelVar
  140.  
  141.     if { $pixelVar == "buttonFull" } then \
  142.     { SetPixelSearch FULL } \
  143.     else \
  144.         { SetPixelSearch HALF }
  145. }
  146.  
  147.  
  148.     ###########
  149.     # PATTERN #
  150.     ###########
  151.  
  152. proc GetPattern {} \
  153. {
  154.     set patChar1 [tail [.pattern1 configure -text]]
  155.     set patChar2 [tail [.pattern2 configure -text]]
  156.     set patChar3 [tail [.pattern3 configure -text]]
  157.     set patChar4 [tail [.pattern4 configure -text]]
  158.     set patChar5 [tail [.pattern5 configure -text]]
  159.     set patChar6 [tail [.pattern6 configure -text]]
  160.  
  161.     set patString $patChar1$patChar2$patChar3$patChar4$patChar5$patChar6
  162.  
  163.     SetPatternString $patString
  164. }
  165.  
  166. proc ChangePattern {patternButton} \
  167. {
  168.     set temp [tail [$patternButton configure -text]]
  169.     case $temp in I {set newTemp P} P {set newTemp B} B {set newTemp I}
  170.     $patternButton configure -text $newTemp
  171. }
  172.  
  173. proc PatternInterface {} \
  174. {
  175.     label .patternLabel -text "Pattern"
  176.  
  177. # no command for first -- must be an I-frame!!!
  178.     button .pattern1 -text "I" -relief raised
  179.     button .pattern2 -text "P" -relief raised -command { ChangePattern .pattern2 }
  180.     button .pattern3 -text "P" -relief raised -command { ChangePattern .pattern3 }
  181.     button .pattern4 -text "P" -relief raised -command { ChangePattern .pattern4 }
  182.     button .pattern5 -text "P" -relief raised -command { ChangePattern .pattern5 }
  183.     button .pattern6 -text "P" -relief raised -command { ChangePattern .pattern6 }
  184.  
  185.     place .patternLabel -x 10 -y 10
  186.     place .pattern1 -x 110 -y 10
  187.     place .pattern2 -x 130 -y 10
  188.     place .pattern3 -x 150 -y 10
  189.     place .pattern4 -x 170 -y 10
  190.     place .pattern5 -x 190 -y 10
  191.     place .pattern6 -x 210 -y 10
  192. }
  193.  
  194.  
  195.     #################
  196.     # FILE BROWSING #
  197.     #################
  198.  
  199. proc GetBrowseGlob {} \
  200. {
  201.     set temp [.fileBrowseEntry get]
  202.     SetBrowseGlob $temp
  203. }
  204.  
  205.  
  206. proc ClearBrowseFile {} \
  207. {
  208.     .fileBrowseList delete 0 end
  209. }
  210.  
  211.  
  212. proc ShowCurrentDirectory {dirName} \
  213. {
  214.     set show "Directory:  $dirName"
  215.     .pathLabel configure -text $show
  216. }
  217.  
  218. proc BrowseDirectory {dirName} \
  219. {
  220.     if { [string last "/" $dirName] == -1 } then \
  221.     {
  222.     AddInputFile $dirName
  223.     } else \
  224.     {
  225.     ChangeDirectory $dirName
  226.     ClearBrowseFile
  227.     GetBrowseGlob
  228.     ListDirectory
  229.     }
  230. }
  231.  
  232. proc AddBrowseFile {fileName} \
  233. {
  234.     .fileBrowseList insert end $fileName
  235. }
  236.  
  237.  
  238. proc AddSelections {} \
  239. {
  240.     set selections [.fileBrowseList curselection]
  241.  
  242.     foreach index $selections {AddInputFile [.fileBrowseList get $index]}
  243. }
  244.  
  245. proc AddAllSelections {} \
  246. {
  247.     set size [.fileBrowseList size]
  248.  
  249.     for {set index 0} {$index < $size} {set index [expr $index+1]} \
  250.         {AddInputFile [.fileBrowseList get $index]}
  251. }
  252.  
  253. proc FileBrowseInterface {} \
  254. {
  255.     label .pathLabel -text "."
  256.  
  257.     scrollbar .fileBrowseScroll -command ".fileBrowseList yview"
  258.     listbox .fileBrowseList -yscroll ".fileBrowseScroll set"
  259.  
  260.     label .globLabel -text "Glob:"
  261.     entry .fileBrowseEntry -width 150
  262.  
  263.     place .pathLabel -x 10 -y 40
  264.  
  265.     place .globLabel -x 10 -y 70 -width 50
  266.     place .fileBrowseEntry -x 65 -y 70 -width 95
  267.  
  268.     place .fileBrowseList -x 10 -y 100 -height 200 -width 220
  269.     place .fileBrowseScroll -x 230 -y 100 -height 200
  270.  
  271.     bind .fileBrowseList <Double-Button-1> {foreach i [selection get] {BrowseDirectory $i}}
  272.     bind .fileBrowseEntry <space> { nothing }
  273.     bind .fileBrowseEntry <Return> { BrowseDirectory "./" }
  274.     bind .fileBrowseEntry <Tab> { nothing }
  275.  
  276.     .fileBrowseEntry insert 0 "*.ppm"
  277.  
  278.     button .addButton -text "Add" -relief raised -command { AddSelections }
  279.     place .addButton -x 30 -y 310 -width 50
  280.  
  281.     button .addAllButton -text "Add All" -relief raised -command { AddAllSelections }
  282.     place .addAllButton -x 90 -y 310 -width 100
  283.  
  284.     ListDirectory
  285.  
  286.     scale .gopScale -orient horizontal -label "GOP size" -from 1 -to 99
  287.     place .gopScale -x 10 -y 340 -width 200
  288.     .gopScale set 30
  289.  
  290.  
  291.     scale .spfScale -orient horizontal -label "Slices per Frame" -from 1 -to 240
  292.     place .spfScale -x 10 -y 405 -width 200
  293.     .spfScale set 1
  294. }
  295.  
  296.     ###############
  297.     # INPUT FILES #
  298.     ###############
  299.  
  300. proc GetInputFiles {} \
  301. {
  302.     set numInput [.fileInputList size]
  303.  
  304.     if { $numInput == 0 } then \
  305.     { puts stdout "No Input Files Specified"; return }
  306.  
  307.     for {set index 0} {$index < $numInput} {set index [expr $index+1]} \
  308.     {
  309.     set inputFile [.fileInputList get $index]
  310.     NextInputFile $inputFile
  311.     }
  312. }
  313.  
  314.  
  315. proc AddInputFile {fileName} \
  316. {
  317.     if { [string last "/" $fileName] == -1 } then \
  318.         {.fileInputList insert end $fileName}
  319. }
  320.  
  321. proc DeleteInputFile {} \
  322. {
  323.     set selections [.fileInputList curselection]
  324.  
  325.     foreach index $selections {.fileInputList delete $index $index}
  326. }
  327.  
  328. proc RemoveSelections {} \
  329. {
  330.     set selections [.fileInputList curselection]
  331.  
  332.     set firstSel [lindex $selections 0]
  333.     set length [llength $selections]
  334.     set lastIndex [expr $length-1]
  335.     set lastSel [lindex $selections $lastIndex]
  336.  
  337.     .fileInputList delete $firstSel $lastSel
  338. }
  339.  
  340. proc RemoveAllSelections {} \
  341. {
  342.     .fileInputList delete 0 end
  343. }
  344.  
  345. proc FileInterface {} \
  346. {
  347.     label .outputFileLabel -text "Output:"
  348.     entry .outputFileEntry
  349.     place .outputFileLabel -x 255 -y 70 -width 50
  350.     place .outputFileEntry -x 310 -y 70 -width 150
  351.  
  352.     .outputFileEntry insert 0 "output.mpg"
  353.     bind .outputFileEntry <space> { nothing }
  354.     bind .outputFileEntry <Return> { nothing }
  355.     bind .outputFileEntry <Tab> { nothing }
  356.  
  357.     label .inputFileLabel -text "Input Files:"
  358.  
  359.     scrollbar .fileInputScroll -command ".fileInputList yview"
  360.     listbox .fileInputList -yscroll ".fileInputScroll set"
  361.  
  362.     place .inputFileLabel -x 255 -y 100
  363.  
  364.     place .fileInputList -x 255 -y 130 -width 220 -height 170
  365.     place .fileInputScroll -x 475 -y 130 -height 170
  366.  
  367. #   bind .fileInputList <Double-Button-1> {foreach i [selection get] {DeleteInputFile $i}}
  368.     bind .fileInputList <Double-Button-1> {DeleteInputFile}
  369.  
  370.     button .removeButton -text "Remove" -relief raised -command { RemoveSelections }
  371.     place .removeButton -x 255 -y 310 -width 80
  372.  
  373.     button .removeAllButton -text "Remove All" -relief raised -command { RemoveAllSelections }
  374.     place .removeAllButton -x 340 -y 310 -width 110
  375.  
  376.     label .convertLabel -text "Convert:"
  377.     entry .convertEntry
  378.     place .convertLabel -x 255 -y 340 -width 85
  379.     place .convertEntry -x 350 -y 340 -width 100
  380.  
  381.     .convertEntry insert 0 "*"
  382.     bind .convertEntry <space> { nothing }
  383.     bind .convertEntry <Return> { nothing }
  384.     bind .convertEntry <Tab> { nothing }
  385.  
  386.     label .formatLabel -text "Input Format:"
  387.     place .formatLabel -x 255 -y 370
  388.  
  389.     radiobutton .yuvButton -text "YUV" -variable formatVar
  390.     radiobutton .ppmButton -text "PPM" -variable formatVar
  391.     radiobutton .pnmButton -text "PNM" -variable formatVar
  392.  
  393.     place .yuvButton -x 255 -y 400
  394.     place .ppmButton -x 330 -y 400
  395.     place .pnmButton -x 405 -y 400
  396.  
  397.     .ppmButton select
  398.  
  399.     label .widthLabel -text "Width:"
  400.     entry .widthEntry
  401.     place .widthLabel -x 255 -y 435 -width 55
  402.     place .widthEntry -x 315 -y 435 -width 45
  403.  
  404.     .widthEntry insert 0 "352"
  405.     bind .widthEntry <space> { nothing }
  406.     bind .widthEntry <Return> { nothing }
  407.     bind .widthEntry <Tab> { nothing }
  408.  
  409.     label .heightLabel -text "Height:"
  410.     entry .heightEntry
  411.     place .heightLabel -x 370 -y 435 -width 60
  412.     place .heightEntry -x 435 -y 435 -width 45
  413.  
  414.     .heightEntry insert 0 "240"
  415.     bind .heightEntry <space> { nothing }
  416.     bind .heightEntry <Return> { nothing }
  417.     bind .heightEntry <Tab> { nothing }
  418. }
  419.  
  420.  
  421.     ###############
  422.     # OUTPUT FILE #
  423.     ###############
  424.  
  425. proc GetFormat {} \
  426. {
  427.     global formatVar
  428.  
  429.     if { $formatVar == "yuvButton" } then \
  430.     { SetFormat YUV } \
  431.     else \
  432.     {
  433.     if { $formatVar == "ppmButton" } then \
  434.          { SetFormat PPM } \
  435.     else \
  436.          { SetFormat PNM }
  437.     }
  438. }
  439.  
  440.  
  441. proc GetGOPSize {} \
  442. {
  443.     set value [.gopScale get]
  444.  
  445.     SetGOPSize $value
  446. }
  447.  
  448.  
  449. proc GetSPF {} \
  450. {
  451.     set value [.spfScale get]
  452.  
  453.     SetSPF $value
  454. }
  455.  
  456.  
  457. proc GetDimensions {} \
  458. {
  459.     set width [.widthEntry get]
  460.     set height [.heightEntry get]
  461.  
  462.     SetDimensions $width $height
  463. }
  464.  
  465.  
  466. proc GetConversion {} \
  467. {
  468.     set temp [.convertEntry get]
  469.     SetConversion $temp
  470. }
  471.  
  472.  
  473. proc GetOutputFileName {} \
  474. {
  475.     set temp [.outputFileEntry get]
  476.     SetOutputFileName $temp
  477. }
  478.  
  479.  
  480. proc PrepareToEncode {} \
  481. {
  482.     GetOutputFileName
  483.     GetPattern
  484.     GetInputFiles
  485.     GetPixelType
  486.     GetSearchRange
  487.     GetPSearch
  488.     GetBSearch
  489.     GetQScale
  490.     GetConversion
  491.     GetFormat
  492.     GetGOPSize
  493.     GetSPF
  494.     GetDimensions
  495. }
  496.  
  497.  
  498. proc ControlInterface {} \
  499. {
  500.     button .encodeButton -text "Encode" -relief raised -command { PrepareToEncode; encode }
  501.     place .encodeButton -x 40 -y 710 -width 80
  502.  
  503.     button .playButton -text "Play" -relief raised -command { GetOutputFileName; PlayOutput }
  504.     place .playButton -x 210 -y 710 -width 80
  505.  
  506.     button .quitButton -text "Quit" -relief raised -command "destroy ."
  507.     place .quitButton -x 380 -y 710 -width 80
  508. }
  509.  
  510.  
  511. wm geometry . 500x750
  512.  
  513. PatternInterface
  514. FileBrowseInterface
  515. FileInterface
  516. MotionVectorSearch
  517. QScale
  518. ControlInterface
  519.