0
Aproveite e veja este incrível site com diversos BOOKs gratuitos ou para venda disponíveis!
Grato ao Thomas pela excelente indicação!
Não existe nada melhor do que ferramentas que nos auxiliam naquelas horas que mais precisamos. Confesso que usar o terminal para fazer coisas simples pode ser um pouco cansativo (apesar de eu não achar que TODO trabalho feito no terminal é cansativo e mais difícil, tudo é relativo). Mas temos que evidenciar que trabalho com grupo de arquivos pode ser muito simples com a ajuda de scripts prontos. Aqui segue uma grande dica que depois que descobri reduziu horas desperdiçadas com a automação que os scripts dão. O Nautilus (não sei ao certo a partir de qual versão, mas funciona no GNOME 2.28.1) passou a incorporar uma funcionalidade extra. Dentro da pasta ~/.gnome2/nautilus-scripts você pode colocar scripts que podem ser acessados em qualquer lugar clicando com o botão direito do mouse. Os scripts devem ser feitos com os parametros de entrada sendo o nome dos arquivos. Então chega de papo e vamos ao que interessa. Eu criei um script que funciona em conjunto com o ffmpeg para converter qualquer vídeo para o formato FLV usado em players flash para internet e também em sites como blip.tv e youtube (é bem interessante se você quer personalizar sua conversão e reduzir tempo para seu vídeo ficar pronto nesses sites). Primeiro você deve instalar o ffmpeg (procure no seu gerenciador de pacotes) e o zenity (caixas de diálogo) Depois vc deve criar um arquivo na pasta de scripts do nautilus com o nome que preferir. Em seguida crie o código do seu script, no caso estou passando o código do meu script: #!/bin/bash# # Author : Walker Gusmão Leite <walker@praiseweb.com.br> # # Copyright (C) 2005,2010 Walker Gusmão Leite <walker@praiseweb.com.br> # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. MAXCPT=50000; if [ $# -eq 0 ]; then here=`pwd`”/.” files=`zenity –file-selection –multiple –separator=”|” –filename=”$here”`”|” #if $? != 0, user click on cancel button, so exit if [ "$?" != 0 ] ; then exit fi cpt=0 # I put all filename in $selection here because I didn’t managed to put filenames with whitespace in $* while [ ${#files} -gt 0 ]; do f=”`echo $files |cut -f1 -d’|'`” isvideo=`file -bi “$f” |grep -c image` if [ $isvideo -eq 1 ]; then selection[$nb_images]=$f let “nb_images++” fi files=`echo $files |cut -f2- -d”|”` let “cpt++” # only to avoid infinite loop (do not occured normaly, but nobody never know.. perhaps!) if [ $cpt -gt $MAXCPT ]; then shift fi done fi videosize=`zenity –title “Selecione o tamanho do vídeo” –text “Selecione o tamanho do vídeo” –list –radiolist –separator=” ” –column=”" –column=”Tamanho” FALSE “160×120″ FALSE “320×240″ TRUE “640×480″ FALSE “800×600″ FALSE “1024×768″ FALSE “1280×720″ –height=220` video_width=${videosize%x*} video_height=${videosize#*x} videobitrate=`zenity –title “Selecione a qualidade do vídeo (bitrate)” –text “Selecione a qualidade do vídeo (bitrate)” –scale –value=”800″ –min-value=”80″ –max-value=”4000″ –step=”10″ –height=220` videobitrate=$(($videobitrate*1024)) videorate=`zenity –title “Selecione o framerate do vídeo (FPS)” –text “Selecione o framerate do vídeo (FPS)” –scale –value=”20″ –min-value=”2″ –max-value=”60″ –step=”1″ –height=220` videofilters=`zenity –title “Selecione os filtros” –text “Selecione os filtros” –list –checklist –separator=” ” –column=”" –column=”Filtros:” FALSE “Desentrelaçar” –height=220` for i in $videofilters; do if [ $i = "Desentrelaçar" ]; then filter=” -deinterlace”; fi; done videocut=`zenity –title “Selecione áreas de corte” –text “Selecione áreas de corte” –list –checklist –separator=” ” –column=”" –column=”Corte:” FALSE “Superior” FALSE “Direita” FALSE “Esquerda” FALSE “Inferior” –height=220` max_cut_w=$(($video_width-1)) max_cut_h=$(($video_height-1)) for i in $videocut; do if [ $i = "Superior" ]; then corte[0]=`zenity –title “Selecione o corte superior em pixels” –text “Selecione o corte superior em pixels” –scale –value=”1″ –min-value=”1″ –max-value=”$max_cut_h” –step=”1″ –height=220`; fi; if [ $i = "Direita" ]; then corte[1]=`zenity –title “Selecione o corte da direita em pixels” –text “Selecione o corte da direita em pixels” –scale –value=”1″ –min-value=”1″ –max-value=”$max_cut_w” –step=”1″ –height=220`; fi; if [ $i = "Esquerda" ]; then corte[2]=`zenity –title “Selecione o corte da esquerda em pixels” –text “Selecione o corte da esquerda em pixels” –scale –value=”1″ –min-value=”1″ –max-value=”$max_cut_w” –step=”1″ –height=220`; fi; if [ $i = "Inferior" ]; then corte[3]=`zenity –title “Selecione o corte inferior em pixels” –text “Selecione o corte inferior em pixels” –scale –value=”1″ –min-value=”1″ –max-value=”$max_cut_h” –step=”1″ –height=220`; fi; done aux=1 video_init=`zenity –title “Selecione o início do vídeo” –text “Selecione o início do vídeo em segundos” –entry –entry-text=”0″ ` while [ $aux -eq 1 ]; do if [ $video_init -eq $video_init 2> /dev/null ]; then aux=0; else video_init=`zenity –title “Selecione o início do vídeo” –text “Entrada não reconhecida, por favor selecione o início do vídeo em segundos” –entry –entry-text=”0″ `; fi; done aux=1 video_end=`zenity –title “Selecione o fim do vídeo” –text “Selecione o fim do vídeo em segundos, deixe 0 para converter o vídeo inteiro” –entry –entry-text=”0″ ` while [ $aux -eq 1 ]; do if [ $video_init -eq $video_init 2> /dev/null ]; then aux=0; else video_end=`zenity –title “Selecione o fim do vídeo” –text “Entrada não reconhecida, por favor selecione o fim do vídeo em segundos, deixe 0 para converter o vídeo inteiro” –entry –entry-text=”0″ ` fi; done if [ $video_end -eq 0 ]; then video_end=”"; else video_end=`echo ” -t $video_end” `; fi #COMANDO while [ $# -gt 0 ]; do loc1=`file -bi “$1″ | grep -c video` loc2=`file -bi “$1″ | grep -c application` isvideo=$(($loc1+$loc2)) if [ $isvideo -gt 0 ]; then selection[$nb_videos]=$1 let “nb_videos++” else isdir=`file -b “$1″ |grep -c directory` if [ $isdir -eq 1 ]; then for f in `ls -1 “$1″`; do loc1=`file -bi “$1/$f” |grep -c video` loc2=`file -bi “$1/$f” |grep -c application` isvideo=$(($loc1+$loc2)) if [ $isvideo -gt 0 ]; then selection[$nb_videos]=”$1/$f” let “nb_videos++” fi done fi fi shift done n=$nb_videos let “n=n-1″ (for i in `seq 0 $n`;do video=${selection[$i]} vid_filename=`basename “$video”` vid_dirname=`dirname “$video”` #create directory if not exist and at least one image to process if [ ! -d "$vid_dirname/convertidos" ]; then mkdir -p “$vid_dirname/convertidos” fi let “compteur += 1″ echo “Processando vídeo $compteur / $nb_videos $vid_filename …” ffmpeg -i “$video” -y -ar 44100 -ab 128 -croptop ${corte[0]:-”0″} -cropright ${corte[1]:-”0″} -cropbottom ${corte[3]:-”0″} -cropleft ${corte[2]:-”0″} -s $videosize -r $videorate -b $videobitrate $filter -f flv -ss ${video_init:-”0″} $video_end “$vid_dirname/convertidos/$vid_filename.flv” 2>&1 | zenity –width 500 –title “Processando vídeo $compteur / $nb_videos $vid_filename …” –text “Processando vídeo $compteur / $nb_videos $vid_filename … ” –progress –pulsate –auto-close let “progress = compteur*100/nb_videos” echo $progress done ) | zenity –progress –auto-close –title=”Convertendo vídeos” –text=”Convertendo vídeos …” –percentage=0 (gnome-open “`dirname \”${selection[0]}\”`/convertidos”) & exit Depois dê permissão de execução ao arquivo do script. Pronto! Agora é só acessar o script selecionando seus arquivos e clicando com o botão direito do mouse no arquivo, acessando o menu scripts. Aproveitando a deixa passo o código de outro script para redimensionar imagens em massa: #!/bin/bash # # Author : Mathieu Vilaplana <mathieu@creationgif.com> # Author : Matthieu MARC <matthieu.marc@wanadoo.fr> # # Copyright (C) 2005,2006 Charles Bouveyron <charles.bouveyron@free.fr> # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # pour l’internationalisation des messages # to generate the i18n file from .po file : # $ msgfmt -o .locale/fr/LC_MESSAGES/nis.mo .locale/fr/LC_MESSAGES/fr.po export TEXTDOMAIN=”nis” export TEXTDOMAINDIR=`dirname $0`”/.locale/” MAXCPT=50000; nb_images=0; selection=”"; txt_error=”`gettext ‘error’`” #test if a file has been selected if [ $# -eq 0 ]; then # zenity –error –title=$txt_error –text=”`gettext ‘You must select at least 1 file to process’`” here=`pwd`”/.” files=`zenity –file-selection –multiple –separator=”|” –filename=”$here”`”|” #if $? != 0, user click on cancel button, so exit if [ "$?" != 0 ] ; then exit fi cpt=0 # I put all filename in $selection here because I didn’t managed to put filenames with whitespace in $* while [ ${#files} -gt 0 ]; do f=”`echo $files |cut -f1 -d’|'`” isimage=`file -bi “$f” |grep -c image` if [ $isimage -eq 1 ]; then selection[$nb_images]=$f let “nb_images++” fi files=`echo $files |cut -f2- -d”|”` let “cpt++” # only to avoid infinite loop (do not occured normaly, but nobody never know.. perhaps!) if [ $cpt -gt $MAXCPT ]; then shift fi done fi #=================================== # SELECT SIZE DIALOG txt_text=”`gettext ‘Choose which size to scale to’`” txt_title=$txt_text txt_size=”`gettext ’size’`” imgsize=`zenity –title “$txt_title” –text “$txt_text” –list –radiolist –separator=” ” –column=”" –column=”$txt_size” FALSE “160×120″ FALSE “320×240″ FALSE “640×480″ TRUE “800×600″ FALSE “1024×768″ FALSE “1280×720″ –height=220` #if $? != 0, user click on cancel button, so exit if [ "$?" != 0 ] ; then exit fi #user must select a target size imgsize=`echo $imgsize | sed ’s/ max//g’` if [ ! "$imgsize" ]; then zenity –error –title=$txt_error –text=”`gettext ’select a target size’`” # just restart myself (more user friendly I think) ($0 “$*”)& exit fi #transform 640×480 en 640×640 for convert to respect proportions himgsize=$imgsize val1=`echo “$imgsize” | awk -F’x’ ‘{ print $1 }’` imgsize=”${val1}x${val1}” # END SELECT SIZE DIALOG #========================= #Select only images while [ $# -gt 0 ]; do isimage=`file -bi “$1″ | grep -c image` if [ $isimage -eq 1 ]; then selection[$nb_images]=$1 let “nb_images++” else isdir=`file -b “$1″ |grep -c directory` if [ $isdir -eq 1 ]; then for f in `ls -1 “$1″`; do isimage=`file -bi “$1/$f” |grep -c image` if [ $isimage -eq 1 ]; then selection[$nb_images]=”$1/$f” let “nb_images++” fi done fi fi shift done n=$nb_images let “n=n-1″ (for i in `seq 0 $n`;do picture=${selection[$i]} img_filename=`basename “$picture”` img_dirname=`dirname “$picture”` #create directory if not exist and at least one image to process if [ ! -d "$img_dirname/$himgsize" ]; then mkdir -p “$img_dirname/$himgsize” fi let “compteur += 1″ echo “`gettext ‘# Processing image’` $compteur / $nb_images $img_filename …” convert -quality 80 -resize $imgsize “$picture” “$img_dirname/$himgsize/$img_filename” #convert -quality 80 -resize $imgsize “$picture” $himgsize/”$picture” let “progress = compteur*100/nb_images” echo $progress done ) | zenity –progress –auto-close –title=”`gettext ‘Scaling images’`” –text=”`gettext ‘Processing images …’`” –percentage=0 (gnome-open “`dirname \”${selection[0]}\”`/$himgsize”) & exit
Aproveite e veja este incrível site com diversos BOOKs gratuitos ou para venda disponíveis!
Grato ao Thomas pela excelente indicação!