Bon,
Je viens de terminer une première version du Meizu Video Encoder
Il comprend un choix d'options et l'affichage de la progression des opérations via Kdialog.
#!/usr/bin/regina
trace off
PARSE ARG filenames
/* parseur des noms de fichier */
fileSize.=0
totalSize=0
cr=x2c('0A')
tb=x2c('09')
/* parsage des noms de fichiers */
/* + calcul de leur taille, */
/* du total et des des tailles de chaque fichier */
/* proportionnellement au total */
filename.=''
i=1
do while totalSize=0
if filenames='' then do
ADDRESS SYSTEM 'kdialog --icon ~/Meizu_icon.png --miniicon ~/Meizu_icon.png --title "Meizu Video Encoder" --getopenfilename :label0 --multiple "video/mpeg video/msvideo video/quicktime video/vnd.rn-realvideo video/x-avi video/x-fli video/x-flic video/x-ms-asf video/x-ms-wmv video/x-msvideo"' WITH OUTPUT STEM fileList.
if rc\=0 then exit
filenames=fileList.1
end
posSlash=index(filenames,'/')
do while posSlash=1
secondPosSlash=index(filenames,' /',2)
if secondPosSlash>0 then do
filename.i=substr(filenames,posSlash,secondPosSlash-1)
filenames=substr(filenames,secondPosSlash+1)
end
else do
filename.i=strip(filenames)
filenames=''
end
posSlash=index(filenames,'/')
ADDRESS SYSTEM 'du "'filename.i'"' WITH OUTPUT STEM currentFileSize.
if rc=0 then do
currentFileSize.1=delword(currentFileSize.1,2)
fileSize.i=currentFileSize.1
totalSize=totalSize+currentFileSize.1
end
else do
filename.i=''
end
i=i+1
end
imax=i-1
end
proportionnalSize.=0
p=1
do while p<=imax
proportionnalSize.p=format(fileSize.p*100/totalSize,3,0)
p=p+1
end
elapseTime=totalSize/400000
/* choix des options d'encodage */
ADDRESS SYSTEM 'kdialog --icon ~/Meizu_icon.png --miniicon ~/Meizu_icon.png --title "Meizu Video Encoder" --separate-output --checklist "Choisissez les options d''encodage simplifiées" 1 "Correction du décalage Audio/Vidéo" off 2 "Gain de volume" off 3 "Son Haute Qualité" off 4 "Egalisation" off 5 "Transfert en séquence" off 6 "Encodage direct sur la cible" off' WITH OUTPUT STEM listOptions.
if rc\=0 then exit
af=''
volume=''
delayOption=''
volnormOption=''
equalizerOption=''
audioQualityOption='192'
gain=0
equalize=0
transfer=0
direct=0
l=1
pref='[MZ'
do listOptions.0
if listOptions.l='1' then do
pref=pref'-'
delayOption='-ignore-start -delay -0.3 '
end
if listOptions.l='2' then do
af='-af '
gain=1
end
if listOptions.l='3' then do
pref=pref'+'
audioQualityOption='256'
end
if listOptions.l='4' then do
af='-af '
equalize=1
end
if listOptions.l='5' then transfer=1
if listOptions.l='6' then do
transfer=0
direct=1
end
l=l+1
end
/* choix des options de règlage du volume */
if (gain) then do
ADDRESS SYSTEM 'kdialog --icon ~/Meizu_icon.png --miniicon ~/Meizu_icon.png --title "Meizu Video Encoder" --combobox "Volume +dB" "1" "2" "3" "4" "5" "6" "8" "10" "12" "15" "20" "30"' WITH OUTPUT STEM volLev.
if rc=0 then do
pref=pref'^'volLev.1
volume='volume='volLev.1' '
af='-af '
end
end
/* choix des options d'égalisation */
if (equalize) then do
if volume='' then virg=' '
else virg=','
ADDRESS SYSTEM 'kdialog --icon ~/Meizu_icon.png --miniicon ~/Meizu_icon.png --title "Meizu Video Encoder" --combobox "Egalisation pour :" "Ecouteurs Meizu" "Koss PortaPro" "Ecouteurs neutres"' WITH OUTPUT STEM speakersType.
if rc\=0 then do
equalizerOption=''
end
if speakersType.1='Koss PortaPro' then do
pref=pref'~K'
equalizerOption='equalizer=0:-1:0:0:0:0:0:-1:1:0'virg
end
if speakersType.1='Ecouteurs Meizu' then do
pref=pref'~M'
equalizerOption='equalizer=4:3:2:2:1:0:0:-4:0:1'virg
end
if speakersType.1='Ecouteurs neutres' then equalizerOption=''
if volume='' & equalizerOption='' then af=''
end
pref=pref']'
/* choix de la directory cible en cas de transfert en séquence */
if (transfer | direct) then do
ADDRESS SYSTEM 'kdialog --icon ~/Meizu_icon.png --miniicon ~/Meizu_icon.png --title "Meizu Video Encoder" --getexistingdirectory :label1' WITH OUTPUT STEM dir.
if rc\=0 then do
exit
end
end
/* initialisation de la barre de progression pour chaque fichier */
ADDRESS SYSTEM 'kdialog --icon ~/Meizu_icon.png --miniicon ~/Meizu_icon.png --title "Meizu Video Encoder" --progressbar "Début de l''encodage" '100 WITH OUTPUT STEM dialogCode.
ADDRESS SYSTEM 'dcop "'dialogCode.1'" showCancelButton true' WITH OUTPUT STEM dcopLog.
/* boucle d'encodage des fichiers */
previousTailLine=''
progressSize=0
i=1
do while i<=imax & filename.i\=''
/* détermination du nom du fichier de sortie */
lastPosSlash=lastpos('/',filename.i)
if direct then destDir=dir.1'/'
else destDir=substr(filename.i,1,lastPosSlash)
if lastPosSlash\=0 then outputFilename=destDir''pref''substr(filename.i,lastPosSlash+1)
else outputFilename=pref''filename.i
posMpg=index(outputFilename,'.mpg')
if posMpg=length(outputFilename)-3 then outputFilename=substr(outputFilename,1,posMpg-1)'.avi'
else outputFilename=outputFilename'.avi'
say outputFilename
/* mise en place de l'affichage des informations d'encodage */
fileLabel=substr('Encodage de'tb''tb'-'tb''filename.i' ',1,100,' ')
destLabel=substr('Encodage en'tb''tb'-'tb''outputFilename' ',1,100,' ')
if transfer then destLabel=destLabel''cr''substr('Transfert demandé vers'tb'-'tb''dir.1' ',1,100,' ')
progressLabel=cr''cr'Progression de l''encodage total'
currentLabel=fileLabel''cr''destLabel''cr''cr'Taille estimée'tb''tb'-'tb' 'cr
currentLabel=currentLabel'Pourcentage encodé'tb'-'tb' 'cr
currentLabel=currentLabel'Temps restant'tb''tb'-'tb' 'cr
currentLabel=currentLabel'Image par seconde'tb'-'tb' 'progressLabel
'dcop "'dialogCode.1'" setLabel "'currentLabel'"'
ADDRESS SYSTEM 'dcop "'dialogCode.1'" setProgress 'progressSize WITH OUTPUT STEM dcopLog.
ADDRESS SYSTEM 'dcop "'dialogCode.1'" wasCancelled ' WITH OUTPUT STEM wasCanceled.
if wasCanceled.1='true' then do
ADDRESS SYSTEM 'dcop "'dialogCode.1'" close ' WITH OUTPUT STEM dcopLog.
exit
end
/* encodage */
'mencoder -msglevel all=-1:avsync=5 "'filename.i'" -idx -noodml 'delayOption'-ofps 20 -vf scale=320:-2,expand=:240:::1,crop=320:240,rotate=1 'af''equalizerOption''volume'-ovc lavc -ffourcc XVID -lavcopts vcodec=mpeg4:vbitrate=384:vmax_b_frames=0:vhq -sws 9 -srate 44100 -oac mp3lame -lameopts cbr:br='audioQualityOption':mode=0 -o "'outputFilename'" >~/progressFile &'
if rc\=0 then do
ADDRESS SYSTEM 'dcop "'dialogCode.1'" close ' WITH OUTPUT STEM dcopLog.
exit
end
/* barre de progression pour chaque fichier */
fileProgress=0
do while fileProgress<100
ADDRESS SYSTEM 'tail -n 5 ~/progressFile' WITH OUTPUT STEM tailLine.
lastLine=tailLine.0
posPos=index(tailLine.lastLine,'Pos')
posPar=index(tailLine.lastLine,'(')
posTrem=index(tailLine.lastline,'Trem: ')
posMin=index(tailLine.lastline,'min ')
posMb=index(tailLine.lastLine,'mb ')
posFps=index(tailLine.lastLine,'fps ')
posPer=index(tailLine.lastLine,'%')
lengthProgress=posPer-posPar-1
if posPos=1 & posPar\=0 & lengthProgress>0 then do
curFps=strip(substr(tailLine.lastline,posPer+2,posFps-posPer-2))
curMb=strip(substr(tailLine.lastline,posMin+3,posMb-posMin-3))
curTrem=strip(substr(tailLine.lastline,posTrem+5,posMin-posTrem-5))
fileProgress=strip(substr(tailLine.lastLine,posPar+1,lengthProgress))
currentLabel=fileLabel''cr''destLabel''cr''cr'Taille estimée'tb''tb'-'tb''curMb' mb'cr
currentLabel=currentLabel'Pourcentage encodé'tb'-'tb''fileProgress' %'cr
currentLabel=currentLabel'Temps restant'tb''tb'-'tb''curTrem' min'cr
currentLabel=currentLabel'Image par seconde'tb'-'tb''curFps' fps'progressLabel
'dcop "'dialogCode.1'" setLabel "'currentLabel'" '
'dcop "'dialogCode.1'" setProgress 'progressSize+format(proportionnalSize.i*fileProgress/100,3,0)
end
if (fileProgress='99' | fileProgress=0) & previousTailLine=tailLine.lastLine then fileProgress='100'
previousTailLine=tailLine.lastLine
'sleep 'min(2,elapseTime)
ADDRESS SYSTEM 'dcop "'dialogCode.1'" wasCancelled ' WITH OUTPUT STEM wasCanceled.
if wasCanceled.1='true' then do
ADDRESS SYSTEM 'dcop "'dialogCode.1'" close ' WITH OUTPUT STEM dcopLog.
'killall mencoder'
exit
end
end
progressSize=progressSize+proportionnalSize.i
/* barre de progression : fin d'encodage d'un fichier */
/* copie éventuelle à la destination choisie */
if transfer then do
currentLabel=currentLabel''tb''tb''tb''tb'Transfert vers 'dir.1
end
'dcop "'dialogCode.1'" setLabel "'currentLabel'" '
ADDRESS SYSTEM 'dcop "'dialogCode.1'" setProgress 'progressSize WITH OUTPUT STEM dcopLog.
ADDRESS SYSTEM 'dcop "'dialogCode.1'" wasCancelled ' WITH OUTPUT STEM wasCanceled.
if wasCanceled.1='true' then do
ADDRESS SYSTEM 'dcop "'dialogCode.1'" close ' WITH OUTPUT STEM dcopLog.
exit
end
/* copie des fichiers si le transfert est demandé */
if transfer then do
ADDRESS SYSTEM 'cp -f "'outputFilename'" 'dir.1 WITH OUTPUT STEM cpLog.
k=1
do cplog.0
say 'LOG -'cplog.k
k=k+1
end
end
i=i+1
end
/* fin de l'encodage */
ADDRESS SYSTEM 'dcop "'dialogCode.1'" setLabel "Fin de l''encodage" ' WITH OUTPUT STEM dcopLog.
ADDRESS SYSTEM 'dcop "'dialogCode.1'" setProgress 'progressSize WITH OUTPUT STEM dcopLog.
'sleep 0.5'
ADDRESS SYSTEM 'dcop "'dialogCode.1'" close ' WITH OUTPUT STEM dcopLog.
[EDIT] la version postée ci dessus est modifiée pour fonctioner sous Kubuntu 7.10 avec la version courante de mencoder[/EDIT]
[EDIT2] l'option volnorm, ça marche pas des masse bien. J'ai remplacé le principe par un pti dialogue de choix du volume[/EDIT2]
[EDIT3] fonctionne également sur Ubuntu Feisty standard [EDIT3]
En combinant avec mes précédents post sur le sujet, vous pouvez ainsi encoder et transférer sous KDE/Konqueror d'un simple click droit
Bon Meizu 🙂