[分享] 自己寫的音檔轉檔小玩具

看板Linux作者 (SunOS 5.11)時間13年前 (2011/07/21 21:18), 編輯推噓1(101)
留言2則, 2人參與, 最新討論串1/1
最近剛學會用一點ffmpeg,就順手寫了一支視窗程式來方便執行它。 這個年頭自己寫視窗程式比網路上花力氣找GUI還來的簡單啊...... 如果大家有興趣玩玩看的話,希望可以順便把你還有哪些需求, 或是執行遇到哪些問題回報給我,我再繼續修改並擴充它,謝謝。 目前還在研究ffmpeg如果做影片轉檔,所以影片檔的設定參數還沒加上。 (本程式碼歡迎自由散佈、修改等,使用沒有限制) 程式說明,最上面的選項是找到ffmpeg的位置後按確定, 它會執行ffmpeg -formats的動作檢查支援哪些格式, 之後輸出格式的部份就有選項可選了。選擇完輸入輸出目錄, 按下轉檔鍵就會將整個目錄的音檔轉過去。 目前已知狀況: 1.遇到異常檔名(含怪字元),程式會執行終止,還在研究怎麼過濾中。 2.輸入資料夾中含有非ffmpeg能處理的檔案,也會讓程式執行到那裡時終止。 從終端機中執行這隻程式,比較能看出ffmpeg運作到哪邊時, 發生異常。有時候Tk彈出的錯誤訊息視窗,多半是Tcl/Tk部份的程式問題, 而不容易看到ffmpeg的錯誤訊息。因為ffmpeg是外部呼叫的程式。 除了分享自己寫的小程式外,也歡迎大家來玩Tcl/Tk。 ================================================================ #!/usr/bin/wish8.5 ###########################前置宣告######################## set ftype1 { {{全部} {*}} } proc scancodec { ffcmd } { set clist [split [exec -ignorestderr $ffcmd -formats] "\n"] set ll [llength $clist] for {set i 0} {$i<$ll} {incr i} { set line [lindex $clist $i]set line1 [lindex $line 0] if {$line1=="E" || $line1=="DE"} { lappend oclist $line } } set ocl [llength $oclist] for {set i 0} {$i<$ocl} {incr i} { lappend ::ocf [lindex [lindex $oclist $i] 1] } .area2.op3 configure -values $::ocf -state normal } proc conv {ffcmd ab ar sel inpdir outdir} { set ::probmx 0 set ::count 0 set par "-ar" if {$ar==""} { set par "" } set fls [split [exec ls $inpdir] "\n"] set ll [llength $fls] set ::probmx $ll .area4.prob configure -maximum $::probmx for {set i 0} {$i<$ll} {incr i} { set infile [lindex $fls $i] ######檢查檔名異常###### set llf [string length $infile] set c ""set infile1 "" for {set j 0} {$j<$llf} {incr j} { set c [string index $infile $j] if {$c==" " || $c=="\[" || $c=="\]" } { set c "_"#append infile1 "_" } append infile1 $c } if {[string match $infile $infile1]==0} { file rename $inpdir/$infile $inpdir/$infile1 set infile $infile1 } ######################## set outfile [lindex [split $infile "."] 0] eval "exec -ignorestderr $ffcmd -ab $ab $par $ar \ -i $inpdir/$infile -f $sel $outdir/$outfile.$sel" incr ::count update after 1000 } } set ab 192k set ::ocf "" set ::probmx 0 set ::count 0 ###########################主程式########################## if { [file exists /tmp/ffcmd]==1 } { set f [open /tmp/ffcmd r] set ffcmd [lindex [split [read $f] "\n"] 0] close $f } label .findff -text "轉檔指令位置:(注意:目前只支援ffmpeg)" label .ffpar -text "ffmpeg參數設定:(留空白則使用預設)" frame .area1 -relief flat frame .area2 -relief flat frame .area3 -relief flat frame .area4 -relief flat button .conv -text "開始轉檔" -command { conv $ffcmd $ab $ar $sel $inpdir $outdir } button .exit -text "離開" -command { exit } pack .findff .area1 .ffpar .area2 .area3 .area4 .conv .exit \ -side top -fill x entry .area1.ffpath -textvariable ffcmd button .area1.bw -text "瀏覽" -command { set ffcmd [tk_getOpenFile -title "轉檔程式的位置" -filetypes $ftype1] } button .area1.ok1 -text "確定" -command { scancodec $ffcmdset f [open /tmp/ffcmd w+] puts $f $ffcmdclose $f } pack .area1.ffpath .area1.bw .area1.ok1 -side left label .area2.opl1 -text "音頻碼率" entry .area2.op1 -textvariable ab label .area2.opl2 -text "音頻採樣率" entry .area2.op2 -textvariable ar label .area2.opl3 -text "輸出格式" ttk::combobox .area2.op3 -values $::ocf -textvariable sel -state disabled grid .area2.opl1 -column 1 -row 1 grid .area2.op1 -column 2 -row 1 grid .area2.opl2 -column 1 -row 2 grid .area2.op2 -column 2 -row 2 grid .area2.opl3 -column 1 -row 3 grid .area2.op3 -column 2 -row 3 label .area3.inpl -text "來源音檔目錄" entry .area3.inp -textvariable inpdir button .area3.inpbw -text "瀏覽" -command { set inpdir [tk_chooseDirectory -title "來源目錄" -initialdir [pwd] ] } label .area3.outl -text "輸出音檔目錄" entry .area3.out -textvariable outdir button .area3.outbw -text "瀏覽" -command { set outdir [tk_chooseDirectory -title "輸出目錄" -initialdir [pwd] ] if {[file exists $outdir]==0} { file mkdir $outdir} } grid .area3.inpl -column 1 -row 1 grid .area3.inp -column 2 -row 1 grid .area3.inpbw -column 3 -row 1 grid .area3.outl -column 1 -row 2 grid .area3.out -column 2 -row 2 grid .area3.outbw -column 3 -row 2 label .area4.prol -text "處理進度:" ttk::progressbar .area4.prob -orient horizontal \ -maximum $::probmx -variable ::count pack .area4.prol .area4.prob -side top -fill x -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 123.193.201.199

07/21 21:42, , 1F
可以考慮把程式放到github
07/21 21:42, 1F

07/21 23:24, , 2F
還在研究怎麼使用github中......
07/21 23:24, 2F
文章代碼(AID): #1EA2SVjc (Linux)