Mouette

TkFFmpeg.tcl

Dec 17th, 2011
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 3.77 KB | None | 0 0
  1. #!/usr/bin/wish8.5
  2. ###########################前置宣告########################
  3. set ftype1 {
  4. {{全部}         {*}}
  5. }
  6.  
  7. proc scancodec { ffcmd } {
  8. set clist [split [exec -ignorestderr $ffcmd -formats] "\n"]
  9. set ll [llength $clist]
  10. for {set i 0} {$i<$ll} {incr i} {
  11. set line [lindex $clist $i]
  12. set line1 [lindex $line 0]
  13. if {$line1=="E" || $line1=="DE"} {lappend oclist $line}
  14. }
  15. set ocl [llength $oclist]
  16. for {set i 0} {$i<$ocl} {incr i} {
  17. lappend ::ocf [lindex [lindex $oclist $i] 1]
  18. }
  19. .area2.op3 configure -values $::ocf -state normal
  20. }
  21.  
  22. proc conv {ffcmd ab ar sel inpdir outdir} {
  23. set ::probmx 0
  24. set ::count 0
  25. set par "-ar"
  26. if {$ar==""} { set par "" }
  27. set fls [split [exec ls $inpdir] "\n"]
  28. set ll [llength $fls]
  29. set ::probmx $ll
  30. .area4.prob configure -maximum $::probmx
  31. for {set i 0} {$i<$ll} {incr i} {
  32. set infile [lindex $fls $i]
  33. ######檢查檔名異常######
  34. set llf [string length $infile]
  35. set c ""
  36. set infile1 ""
  37. for {set j 0} {$j<$llf} {incr j} {
  38. set c [string index $infile $j]
  39. if {$c==" " || $c=="\[" || $c=="\]" } {
  40. set c "_"
  41. #append infile1 "_"
  42. }
  43. append infile1 $c
  44.  
  45. }
  46. if {[string match $infile $infile1]==0} {
  47. file rename $inpdir/$infile $inpdir/$infile1
  48. set infile $infile1
  49. }
  50. ########################
  51.  
  52. set outfile [lindex [split $infile "."] 0]
  53. eval "exec -ignorestderr $ffcmd -ab $ab $par $ar \
  54. -i $inpdir/$infile -f $sel $outdir/$outfile.$sel"
  55. incr ::count
  56. update
  57. after 1000
  58. }
  59. }
  60.  
  61. set ab 192k
  62. set ::ocf ""
  63. set ::probmx 0
  64. set ::count 0
  65.  
  66. ###########################主程式##########################
  67. if { [file exists /tmp/ffcmd]==1 } {
  68. set f [open /tmp/ffcmd r]
  69. set ffcmd [lindex [split [read $f] "\n"] 0]
  70. close $f
  71. }
  72. label .findff -text "轉檔指令位置:(注意:目前只支援ffmpeg)"
  73. label .ffpar -text "ffmpeg參數設定:(留空白則使用預設)"
  74. frame .area1 -relief flat
  75. frame .area2 -relief flat
  76. frame .area3 -relief flat
  77. frame .area4 -relief flat
  78. button .conv -text "開始轉檔" -command {
  79. conv $ffcmd $ab $ar $sel $inpdir $outdir
  80. }
  81. button .exit -text "離開" -command { exit }
  82. pack .findff .area1 .ffpar .area2 .area3 .area4 .conv .exit -side top -fill x
  83.  
  84. entry .area1.ffpath -textvariable ffcmd
  85. button .area1.bw -text "瀏覽" -command {
  86. set ffcmd [tk_getOpenFile -title "轉檔程式的位置" -filetypes $ftype1]
  87. }
  88. button .area1.ok1 -text "確定" -command {
  89. scancodec $ffcmd
  90. set f [open /tmp/ffcmd w+]
  91. puts $f $ffcmd
  92. close $f
  93. }
  94. pack .area1.ffpath .area1.bw .area1.ok1 -side left
  95.  
  96. label .area2.opl1 -text "音頻碼率"
  97. entry .area2.op1 -textvariable ab
  98. label .area2.opl2 -text "音頻採樣率"
  99. entry .area2.op2 -textvariable ar
  100. label .area2.opl3 -text "輸出格式"
  101. ttk::combobox .area2.op3 -values $::ocf -textvariable sel -state disabled
  102. grid .area2.opl1 -column 1 -row 1
  103. grid .area2.op1 -column 2 -row 1
  104. grid .area2.opl2 -column 1 -row 2
  105. grid .area2.op2 -column 2 -row 2
  106. grid .area2.opl3 -column 1 -row 3
  107. grid .area2.op3 -column 2 -row 3
  108.  
  109. label .area3.inpl -text "來源音檔目錄"
  110. entry .area3.inp -textvariable inpdir
  111. button .area3.inpbw -text "瀏覽" -command {
  112. set inpdir [tk_chooseDirectory -title "來源目錄" -initialdir [pwd] ]
  113. }
  114. label .area3.outl -text "輸出音檔目錄"
  115. entry .area3.out -textvariable outdir
  116. button .area3.outbw -text "瀏覽" -command {
  117. set outdir [tk_chooseDirectory -title "輸出目錄" -initialdir [pwd] ]
  118. if {[file exists $outdir]==0} { file mkdir $outdir}
  119. }
  120. grid .area3.inpl -column 1 -row 1
  121. grid .area3.inp -column 2 -row 1
  122. grid .area3.inpbw -column 3 -row 1
  123. grid .area3.outl -column 1 -row 2
  124. grid .area3.out -column 2 -row 2
  125. grid .area3.outbw -column 3 -row 2
  126.  
  127. label .area4.prol -text "處理進度:"
  128. ttk::progressbar .area4.prob -orient horizontal \
  129.  -maximum $::probmx -variable ::count
  130. pack .area4.prol .area4.prob -side top -fill x
Advertisement
Add Comment
Please, Sign In to add comment