AVI para DVD - Cria seu DVD com menu e legendas

Publicado por fernando (última atualização em 08/01/2015)

[ Hits: 3.738 ]

Homepage: http://sites.google.com/site/suportetecnico87

Download criaDVD




Criado por: Bruno Nocera Zanette

Esse script tem como finalidade automatizar  o processo de conversão de arquivos AVI para DVD, com Menu e Legendas. Para isso utiliza  um arquivo de configuração criado na primeira vez que o programa for executado.  

COMO EXECUTAR:

Para executar o programa basta escrever no terminal:   

# ./criaDVD <video1> <video2> ...

Onde <video1,2,...> é o nome do filme com o caminho. Ex.:

./criaDVD ~/video1.avi ./Outros/video2.avi

OPÇÕES:

-> config : Remove a configuração existente e cria uma nova configuração

DEPENDÊNCIAS:

- avidemux-cli
- avidemux-common
- tovid
- mencoder
- lame
- toolame
- mjpegtools
- imagemagick
- zenity

  



Esconder código-fonte

#!/bin/bash
#!/usr/bin/env bash
PATH=/usr/share/tovid:$PATH

#############################################################################
# Este programa é software livre, você pode redistribuí-lo ou modificá-lo   #
# sob os termos da GNU General Public License, versão 2 ou qualquer versão  #
# mais recente, conforme publicado pela Free Software Foundation.           #
#############################################################################

#################################################
#                 AVI para DVD              #
#       Feito por: Bruno Nocera Zanette           #
#   Email: brunonzanette@gmail.com          #
#                Data: 10/2008                  #
#                        #
#===============================================#
#                       #   
#                 FINALIDADE:              #
# Esse Script tem como finalidade automatizar   #
# o processo de conversão de arquivos AVI para  #
# DVD, com Menu e Legendas. Para isso utiliza   # 
# um arquivo de configuração criado na          #
# primeira vez que o programa for executado.    #
#                       #
#               COMO EXECUTAR:                #
# Para executar o programa basta escrever no    #
# Terminal:                    #   
# ./CriaDVD <video1> <video2> ...               #
# Onde <video1,2,...> é o nome do filme com o   # 
# caminho.                    #   
# Ex.:                        #   
# ./cria_dvd ~/video1.avi ./Outros/video2.avi   #
#                  #
#         OPCOES:         #
# -> config : Remove a configuração existente e #
#             cria uma nova configuração   #
#                  #
#################################################         

#################################################
#                DEPENDENCIAS:          #
# - avidemux-cli                 #
# - avidemux-common             # 
# - tovid               #
# - mencoder               #
# - lame               #
# - toolame               #
# - mjpegtools               #
# - imagemagick               #   
# - zenity               #
#################################################

#################################################
# INICIA O PROGRAMA E TESTA SE A PASTA ~/.dvd   #
# ESTA CRIADA                                   #
#################################################
if ! [ -d ~/.dvd ]
then
   mkdir ~/.dvd
fi

if ! [ -d ~/.dvd/tmp ]
then
   mkdir ~/.dvd/tmp
fi

if [[ $1 == 'config' && -e ~/.dvd/.dvd_config ]]
then
        rm ~/.dvd/.dvd_config
fi


if [[ `df -lk | egrep '\/$' | tr -s " " | cut -d" " -f4` -le 10000000 ]]
then
   zenity --info -title "AVI_DVD" --text "O seu HD não possui espaço em disco suficiente (9Gb) para rodar o script.\nLibere mais espaço e tente denovo."
   exit 1
fi

#################################################
# CONFIGURA O PROGRAMA E SALVA A CONFIGURAÇÂO   #
# EM ~/.dvd/.dvd_config            #
#################################################
if ! [ -e ~/.dvd/.dvd_config ]
then
   clear
   zenity --info --title "AVI_DVD" --text "Bem Vindo ao AVI_DVD\!\nPor Favor responda o questionário a seguir."

   ###############
   #### VIDEO ####
   ###############
   
   opcao=`zenity --width=350 --height=250 --title "AVI_DVD" --text "Qual formato o seu DVD Player aceita?" --list --radiolist --hide-column=2 --column "" --column "" --column "Opções" FALSE 1 NTSC FALSE 2 PAL TRUE 2 Ambos`
      case $opcao in
         1) echo "ntsc" >>  ~/.dvd/.dvd_config; res=480;;
         2) echo "pal" >> ~/.dvd/.dvd_config; res=576;;
         *) echo "ERRO!"; exit 1;;
      esac

   opcao=`zenity --width=350 --height=250 --title "AVI_DVD" --text "Qual codec você deseja usar para o vídeo?" --list --radiolist --hide-column=2 --column "" --column "" --column "Opções" TRUE 1 LAVC FALSE 2 MPEG2Enc`
      case $opcao in
         1) echo "XDVD" >> ~/.dvd/.dvd_config;;
         2) echo "DVD" >> ~/.dvd/.dvd_config;;
         *) echo "ERRO!"; exit 1;;
      esac
   
   #### CONFIGURA O VIDEO DEPENDENDO DO CODEC ####
   #### CODEC ESCOLHIDO (LAVC / MPEG2ENC)     ####   
   if [[ $opcao == 1 ]]
   then
      opcao=`zenity --width=350 --height=250 --title "AVI_DVD" --text "Que tipo de codificação você deseja?" --list --radiolist --hide-column=2 --column "" --column "" --column "Opções" TRUE 1 Default FALSE 2 TMPGEnc FALSE 3 Anime`
         case $opcao in
                                1) echo "160 05 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 1f 00 00 00 03 00 00 00 02 00 00 00 01 00 00 00 01 00 00 00 fe ff ff ff 01 00 00 00 fb ff ff ff cd cc 4c 3d 01 00 00 00 0a d7 23 3c 01 00 00 00 00 00 00 3f 00 00 00 3f 00 00 00 00 28 23 00 00 00 00 00 00 0c 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 40 1f 00 00 00 00 00 00 00 00 00 3f 00 00 00 00 00 00 00 3f 00 00 00 00 01 00 00 00 e0 00 00 00 00 00 00 00 00 00 00 00" >> ~/.dvd/.dvd_config;;
                                2) echo "160 05 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 1f 00 00 00 03 00 00 00 02 00 00 00 01 00 00 00 01 00 00 00 fe ff ff ff 01 00 00 00 fb ff ff ff cd cc 4c 3d 01 00 00 00 0a d7 23 3c 01 00 00 00 00 00 00 3f 00 00 00 3f 00 00 00 00 28 23 00 00 01 00 00 00 0c 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 40 1f 00 00 00 00 00 00 00 00 00 3f 00 00 00 00 00 00 00 3f 00 00 00 00 01 00 00 00 e0 00 00 00 00 00 00 00 00 00 00 00" >> ~/.dvd/.dvd_config;;
            3) echo "160 05 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 1f 00 00 00 03 00 00 00 02 00 00 00 01 00 00 00 01 00 00 00 fe ff ff ff 01 00 00 00 fb ff ff ff cd cc 4c 3d 01 00 00 00 0a d7 23 3c 01 00 00 00 00 00 00 3f 00 00 00 3f 00 00 00 00 28 23 00 00 02 00 00 00 0c 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 40 1f 00 00 00 00 00 00 00 00 00 3f 00 00 00 00 00 00 00 3f 00 00 00 00 01 00 00 00 e0 00 00 00 00 00 00 00 00 00 00 00" >> ~/.dvd/.dvd_config;;
                                *) echo "ERRO!"; exit 1;;
                        esac

      opcao=`zenity --width=350 --height=250 --title "AVI_DVD" --text "Que tipo de encode você deseja usar?" --list --radiolist --hide-column=2 --column "" --column "" --column "Opções" TRUE 1 "Video Size" FALSE 2 "Bitrate"`
                case $opcao in
                        1) echo "2PASS" >> ~/.dvd/.dvd_config;;
                        2) echo "2PASSBITRATE" >> ~/.dvd/.dvd_config;;
                        *) echo "ERRO!"; exit 1;;
                esac
   
   else

      opcao=`zenity --width=350 --height=250 --title "AVI_DVD" --text "Que tipo de codificação você deseja usar?" --list --radiolist --hide-column=2 --column "" --column "" --column "Opções" TRUE 1 "Default" FALSE 2 "TMPGEnc" FALSE 3 "Anime"`
                        case $opcao in
                                1) echo "24 28 23 00 00 0c 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00" >> ~/.dvd/.dvd_config;;
                                2) echo "24 28 23 00 00 0c 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00" >> ~/.dvd/.dvd_config;;
                                3) echo "24 28 23 00 00 0c 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00" >> ~/.dvd/.dvd_config;;
                                *) echo "ERRO!"; exit 1;;
                        esac

      opcao=`zenity --width=350 --height=250 --title "AVI_DVD" --text "Que tipo de encode você deseja usar?" --list --radiolist --hide-column=2 --column "" --column "" --column "Opções" TRUE 1 "Video Size" FALSE 2 "Bitrate" FALSE 3 "Constant Quality"`
                        case $opcao in
                                1) echo "2PASS" >> ~/.dvd/.dvd_config;;
                                2) echo "CBR" >> ~/.dvd/.dvd_config;;
            3) echo "CQ" >> ~/.dvd/.dvd_config;;
                                *) echo "ERRO!"; exit 1;;
                        esac
   fi
   
   opcao=`zenity --width=350 --height=250 --title "AVI_DVD" --text "Que resolução você deseja usar?" --list --radiolist --hide-column=2 --column "" --column "" --column "Opções" TRUE 1 "4:3 (FullScreen)" FALSE 2 "16:9 (WideScreen)"`
      case $opcao in
         1) echo "43" >> ~/.dvd/.dvd_config;;
         2) echo "169" >> ~/.dvd/.dvd_config;;
         *) echo "ERRO!"; exit 1;;
      esac

   ###############
   #### AUDIO ####
   ###############

   opcao=`zenity --width=350 --height=250 --title "AVI_DVD" --text "Qual codec você deseja usar?" --list --radiolist --hide-column=2 --column "" --column "" --column "Opções" FALSE 1 "MP2" FALSE 2 "MP2 - TwoLAME" TRUE 3 "AC3"`
      case $opcao in
         1) echo "mp2" >> ~/.dvd/.dvd_config;;
         2) echo "twolame" >> ~/.dvd/.dvd_config;;
         3) echo "ac3" >> ~/.dvd/.dvd_config;;
         *) echo "ERRO!"; exit 1;;
                esac

   opcao=`zenity --width=350 --height=250 --title "AVI_DVD" --text "Qual bitrate você deseja usar?" --list --radiolist --hide-column=2 --column "" --column "" --column "Opções" FALSE 1 "128" FALSE 2 "192" FALSE 3 "224" TRUE 4 "384"`
      case $opcao in
         1) echo "128" >> ~/.dvd/.dvd_config;;
         2) echo "192" >> ~/.dvd/.dvd_config;;
         3) echo "224" >> ~/.dvd/.dvd_config;;
         4) echo "384" >> ~/.dvd/.dvd_config;;
         *) echo "ERRO!"; exit 1;;
                esac

   #################
   #### LEGENDA ####
   #################

   opcao=`zenity --width=350 --height=250 --title "AVI_DVD" --text "Qual fonte você deseja usar para legenda?" --list --radiolist --hide-column=2 --column "" --column "" --column "Opções" FALSE 1 "Arial" FALSE 2 "Lucida Sans" TRUE 3 "DejaVu" FALSE 4 "Outro"`
      case $opcao in
                        1) echo "/usr/share/fonts/truetype/msttcorefonts/arial.ttf" >> ~/.dvd/.dvd_config;;
                        2) echo "/usr/share/fonts/truetype/ttf-lucida/LucidaSansRegular.ttf" >> ~/.dvd/.dvd_config;;
         3) echo "/usr/share/fonts/truetype/ttf-dejavu/DejaVuSansCondensed-Bold.ttf" >> ~/.dvd/.dvd_config;;
                        4) echo `zenity --file-selection --title "AVI_DVD - Escolha a fonte que você deseja usar: (/usr/share/fonts/)"` >>  ~/.dvd/.dvd_config;;
         *) echo "ERRO!"; exit 1;;
                esac       
 
   opcao=`zenity --width=350 --height=250 --title "AVI_DVD" --text "Qual cor você prefere para a legenda?" --list --radiolist --hide-column=2 --column "" --column "" --column "Opções" FALSE 1 "Branco" TRUE 2 "Amarelo" FALSE 3 "Outro"`
      case $opcao in 
                   1) echo "255,255,255" >> ~/.dvd/.dvd_config;;
                        2) echo "255,255,000" >> ~/.dvd/.dvd_config;;
                        3) echo `zenity --entry --title "AVI_DVD" --text "Digite o número da cor no formato RGB:" --entry-text "RRR:GGG:BBB"` >> ~/.dvd/.dvd_config;;
         *) echo "ERRO!"; exit 1;;
      esac
      
   tam_fonte=`zenity --title "AVI_DVD" --text "Qual tamanho da fonte da legenda?" --scale --value=26`
   echo $tam_fonte >> ~/.dvd/.dvd_config


   #### CALCULA POSICAO MAX E IDEAL DA LEGENDA ####
   posicao_max=$(($res -($tam_fonte*3)))
   if [[ $res == 576 ]]
   then
      posicao_inicial=$(($posicao_max - (92 -($tam_fonte*2))))
   else
      posicao_inicial=$(($posicao_max - (44 - $tam_fonte)))
   fi   
            
   zenity --title "AVI_DVD" --text "Qual posicao da legenda? (Quanto maior, mais embaixo)" --scale --min-value=0 --max-value=$posicao_max --value=$posicao_inicial --print-partial >> ~/.dvd/.dvd_config

   ###############   
   #### MENU: ####
   ###############

   echo `zenity --width=500 --entry --title "AVI_DVD" --text "Qual o titúlo que você deseja que o menu tenha?"` >> ~/.dvd/.dvd_config

   opcao=`zenity --title "AVI_DVD" --text "Qual a cor da fonte do menu?" --list --radiolist --hide-column=2 --column "" --column "" --column "Opções" TRUE 1 "Branco" FALSE 2 "Amarelo" FALSE 3 "Preto" FALSE 4 "Azul" FALSE 5 "Outro"`
      case $opcao in
                        1) echo "255,255,255" >> ~/.dvd/.dvd_config;;
                        2) echo "255,255,000" >> ~/.dvd/.dvd_config;;
         3) echo "000,000,000" >> ~/.dvd/.dvd_config;;
         4) echo "000,000,255" >> ~/.dvd/.dvd_config;;      
         5) echo `zenity --entry --title "AVI_DVD" --text "Digite o número da cor no formato RGB:" --entry-text "RRR:GGG:BBB"` >> ~/.dvd/.dvd_config;;
                        *) echo "ERRO!"; exit 1;;
                esac

   zenity --file-selection --title "AVI_DVD - Escolha a imagem que você deseja usar como plano de fundo:" >> ~/.dvd/.dvd_config   
   
   zenity --info --title "AVI_DVD" --text "Configuração realizada com sucesso\!"
fi
            
#################################################
#   SELECIONA OS VIDEOS QUE SERÃO CONVERTIDOS   #
#################################################
if [[ $# == "0" ]]
then
   args=`zenity --title "AVI_DVD - Selecione os arquivos que você deseja converter" --file-selection --multiple | sed s#\|#" "#g`

   if [[ $args == "" ]]
   then
      exit 1
   fi
      
   zenity --title "AVI_DVD" --question --text "Deseja adicionar mais algum vídeo?"
   while [[ $? == 0 ]]
   do
      args_2=`zenity --title "AVI_DVD - Selecione os arquivos que você deseja converter" --file-selection --multiple | sed s#\|#" "#g`
      args=`echo "$args $args_2"`
      zenity --title "AVI_DVD" --question --text "Deseja adicionar mais algum vídeo?"
   done   
else
   args=$*   
fi   

#################################################
# PEGA AS INFORMACOES: NOME DO FILME E DURACAO  #
#################################################   
num_args=0
for x in $args
do
   num_args=$(($num_args + 1))
          if [[ -e $x && `echo $x | grep -c .avi` -ge 1 ]]
        then
      filme[$num_args]=filme$num_args

      nome[$num_args]=`zenity --title "AVI_DVD" --entry --text "Qual o nome do filme do arquivo \"$x\"?"`
      
      #### SE ENCONTRAR "." COMO PRIMEIRO CARACTERE ####
      #### SUBSTITUI PELO DIRETORIO CORRENTE        ####
      if [[ `echo $x | grep -c '^\.'` -ge 1 ]]
      then
         dir=`pwd`
         filme_caminho[$num_args]=`echo $x | sed s#^\.\/#$dir/#g | sed s#.avi##g`
      #### SE ENCONTRAR "/home/" NO COMEÇO APENAS   ####
      #### SALVA $x EM FILME_CAMINHO                ####
      elif [[ `echo $x | grep -c '^/home'` -ge 1 ]]
      then
         filme_caminho[$num_args]=`echo $x | sed s#.avi##g`
      #### SENAO, APENAS ADICIONA O DIRETORIO       ####
      #### CORRENTE NO COMECO DO CAMINHO         ####   
      else
         dir=`pwd`   
         filme_caminho[$num_args]=`echo $dir/$x | sed s#.avi##g`
      fi

      if ! [ -e ${filme_caminho[$num_args]}.srt ]
      then
         zenity --title "AVI_DVD" --question --text "O arquivo \"$x\" não possui legenda.\nDeseja continuar?"
         if [[ $? == 1 ]]
         then
            exit 1
         fi
      fi
        else
      zenity --title "AVI_DVD" --warning --text "ERRO! O arquivo \"$x\" não existe ou não está no formato \".avi\"."
                  exit 1
        fi
done

#################################################
# LE AS INFORMACOES DO ARQUIVO DE CONFIGURACAO  #
#################################################
i=1
while read x
do
   case $i in
      1) padrao_dvd=$x;;
      2) video_codec=$x;;
      3) video_matriz=$x;;
      4) tipo_encode=$x;;
      5) resolucao=$x;;   
      6) audio_codec=$x;;
      7) audio_bitrate=$x;;
      8) legenda_fonte=$x;;
      9) legenda_cor=$x;;
      10) legenda_tamanho=$x;;
      11) legenda_posicao=$x;;
      12) menu_titulo=$x;;
      13) menu_fonte_cor=$x;;
      14) menu_imagem=$x;;
      *) echo "";;
   esac
   i=$(($i + 1))
done < ~/.dvd/.dvd_config
                  
#################################################
# COLETA AS INFORMAÇÕES RELACIONADAS AO FILME   #
#################################################
duracao_total=0
user=`ps u | cut -d" " -f1 | tail -1`

for ((i=1; i<=$num_args; i=i+1))
do
   avidemux2_cli --nogui --load ${filme_caminho[$i]}.avi --info > ~/.dvd/tmp/${filme[$i]}.info 2> ~/.dvd/tmp/${filme[$i]}.erro

   total_frames[$i]=`grep -m1 dwTotalFrames ~/.dvd/tmp/${filme[$i]}.info | cut -d":" -f3`
   markerb[$i]=$(( ${total_frames[$i]} - 1 ))
   fps[$i]=`grep -m1 fps ~/.dvd/tmp/${filme[$i]}.info | cut -d" " -f6 | sed s#,##g`
   if [[ ${fps[$i]} -lt 9999 ]]
   then
      fps[$i]=$(( ${fps[$i]} * 1000 ))
   elif [[ ${fps[$i]} -gt 99999 ]]
   then
      fps[$i]=$(( ${fps[$i]} / 1000 ))
   fi   

   video_x[$i]=`grep -m2 biWidth ~/.dvd/tmp/${filme[$i]}.info | cut -d":" -f3`
   video_y[$i]=`grep -m1 biHeight ~/.dvd/tmp/${filme[$i]}.info | cut -d":" -f3`

        duracao[$i]=`grep -m1 Duration ~/.dvd/tmp/${filme[$i]}.info | cut -d":" -f2 | cut -d"," -f1 | sed s#' '##g`
   duracao_total=$(( $duracao_total + ${duracao[$i]} ))
   
   ###############################################
   #           DETECTA OS ERROS NO VIDEO         #
   #  (SE ENCONTRAR O TEXTO UMA OU MAIS VEZES)   #
   ###############################################
   if [[ `grep -c "Packed Bitstream detected" ~/.dvd/tmp/${filme[$i]}.erro` -ge 1 ]]
   then
      force_unpack[$i]="app.forceUnpack();"
   else
      force_unpack[$i]=""
   fi

        if [[ `grep -c "Index is not up to date" ~/.dvd/tmp/${filme[$i]}.erro` -ge 1 ]]
        then
          avidemux --nogui --load ${filme_caminho[$i]}.avi --autoindex --rebuild-index --save ~/.dvd/tmp/${filme[$i]}_OK.avi --quit > ~/.dvd/tmp/${filme[$i]}_index.log 2> ~/.dvd/tmp/${filme[$i]}_index.erro
          cp ${filme_caminho[$i]}.srt ~/.dvd/tmp/${filme[$i]}_OK.srt
           filme_caminho[$i]=`echo "/home/$user/.dvd/tmp/${filme[$i]}_OK"`
        fi

   if [[ `grep -c "Build Time Map" ~/.dvd/tmp/${filme[$i]}.erro` -ge 1 ]]
        then
                build_time_map[$i]="app.audio.scanVBR();"
        else
                build_time_map[$i]=""
        fi
done

#################################################
# TESTA SE A DURACAO TOTAL É MUITO GRANDE       #
# SE FOR, PERGUNTA SE CONTINUA OU NAO           #       
#################################################
if [[ $duracao_total -ge 12000 ]]
then
   zenity --title "AVI_DVD" --question --text "A duracao total dos filmes é muito grande.\nDeseja continuar?"
   if [[ $? == 1 ]]
   then
                  exit 1
   fi
fi
                  
#################################################
# CALCULA OS VALORES NECESSARIOS PARA           #
# A CONVERSAO, DEPENDENDO DO TIPO               #
#################################################
caminho_projeto=`echo /home/$user/.dvd/tmp/`

for ((i=1; i<=$num_args; i=i+1))
do
   #### CONVERTE PAL->NTSC / NTSC->PAL ####
   #### PADRAO    /   FPS              ####
   #### NTSC      /   29970-23976      ####
   #### PAL       /   25000       ####            
   if [[ $padrao_dvd == "ntsc" ]]
   then
      if [[ ${fps[$i]} == 25000 ]]
      then
         resample_fps[$i]="app.video.addFilter(\"resamplefps\",\"newfps=29970\",\"use_linear=0\");"
      else
         resample_fps[$i]=""
      fi
   else
      if [[ ${fps[$i]} != 25000 ]]
                then
                        fps_resample[$i]="app.video.addFilter(\"resamplefps\",\"newfps=25000\",\"use_linear=0\");"
                else
                        fps_resample[$i]=""
                fi
   fi

   if [[ `grep "Audio codec" ~/.dvd/tmp/${filme[$i]}.info | cut -d":" -f2 | tr -d " "` == 'AC3'
                && `grep "Frequency" ~/.dvd/tmp/${filme[$i]}.info | cut -d":" -f2 | cut -d" " -f2` == 48000 ]]
        then
                temp=`grep BitRate ~/.dvd/tmp/${filme[$i]}.info | cut -d"/" -f2 | cut -d" " -f2`
                audio_tamanho[$i]=$(((($temp * 71) * ${duracao[$i]}) / 600000))
                audio_comando[$i]="app.audio.codec(\"copy\",128,0,\"\");"
      audio_resample[$i]=""
        else
      if [[ $audio_codec == "twolame" ]]
      then
         audio_comando[$i]=`echo "app.audio.codec(\"$audio_codec\",$audio_bitrate,4,\"01 00 00 00\");"`
                        audio_resample[$i]="app.audio.resample=48000;"
                        audio_tamanho[$i]=$(((($audio_bitrate * 71) * ${duracao[$i]}) / 600000))
      else
                   audio_comando[$i]=`echo "app.audio.codec(\"$audio_codec\",$audio_bitrate,0,\"\");"`
         audio_resample[$i]="app.audio.resample=48000;"
                   audio_tamanho[$i]=$(((($audio_bitrate * 71) * ${duracao[$i]}) / 600000))
      fi
        fi

   if [[ $tipo_encode == '2PASS' ]]
        then   
      ### VALOR = TAMANHO_TOTAL ###   
                  valor_conversao[$i]=$(((4300 * ${duracao[$i]}) / $duracao_total ))
        elif [[ $tipo_encode == '2PASSBITRATE' || $tipo_encode == 'CBR' ]]
          then
      ### VALOR = BITRATE ###
      tamanho_total[$i]=$(((4300 * ${duracao[$i]}) / $duracao_total ))
               video_tamanho[$i]=$((((${tamanho_total[$i]} - ${audio_tamanho[$i]}) * 98 ) / 100))
      valor_conversao[$i]=$((( ${video_tamanho[$i]} * 8384) / ${duracao[$i]}))
      if [[ ${valor_conversao[$i]} -ge 9000 ]]
      then
         valor_conversao[$i]=9000
      fi
        else
             #### VALOR = CONSTANT_QUALITY ####
      valor_conversao[$i]=4
   fi

   #### CONFIGURA A RESOLUCAO DO VIDEO CONFORME ####
   #### O PADRAO DE DVD E RESOLUCAO DA TV       ####
   
   #### PADRAO    /  RESOLUCAO ####
   #### NTSC      /  720x480   ####
   #### PAL       /  720x576   ####

   if [[ $resolucao == 43 ]]
   then
      if [[ $padrao_dvd == "ntsc" ]]
           then
                   res_y_final=480
           else
                   res_y_final=576
           fi   

      #### RESOLUCAO FINAL NÃO PODE SER IMPAR ####
      resolucao_x[$i]=720
           resolucao_y[$i]=$(((720 * ${video_y[$i]}) / ${video_x[$i]}))

      if [[ ${resolucao_y[$i]} -gt $res_y_final ]]
                then
                        resolucao_y[$i]=$res_y_final
                fi      
      
      if [[ $(( ${resolucao_y[$i]} % 2 )) == 1 ]]
      then
         resolucao_y[$i]=$(( ${resolucao_y[$i]} + 1 ))
      fi

      #### VALOR BLACK NÃO PODE SER IMPAR ####
      black_top[$i]=$((($res_y_final - ${resolucao_y[$i]}) / 2))
      if [[ $(( ${black_top[$i]} % 2 )) == 1 ]]
      then   
         resolucao_y[$i]=$(( ${resolucao_y[$i]} + 2 ))
         black_top[$i]=$(( ${black_top[$i]} - 1 ))
      fi

      black_bottom[$i]=${black_top[$i]}
      black_left[$i]=0
      black_right[$i]=0
   else
      if [[ $padrao_dvd == "NTSC" ]]
                then
         res_x_prop=833
                        res_y_final=480
                else
         res_x_prop=1024
                        res_y_final=576
                fi

      #### RESOLUCAO FINAL NÃO PODE SER IMPAR ####
                resolucao_x[$i]=720
                resolucao_y[$i]=$((($res_x_prop * ${video_y[$i]}) / ${video_x[$i]}))

      if [[ ${resolucao_y[$i]} -gt $res_y_final ]]
      then
         resolucao_y[$i]=$res_y_final
      fi
      
      if [[ $(( ${resolucao_y[$i]} % 2 )) == 1 ]]
                then
                        resolucao_y[$i]=$(( ${resolucao_y[$i]} + 1 ))
      fi

                #### VALOR BLACK NÃO PODE SER IMPAR ####
                black_top[$i]=$((($res_y_final - ${resolucao_y[$i]}) / 2))
                if [[ $(( ${black_top[$i]} % 2 )) == 1 ]]
                then
                        resolucao_y[$i]=$(( ${resolucao_y[$i]} + 2 ))
                        black_top[$i]=$(( ${black_top[$i]} - 1 ))
                fi

                black_bottom[$i]=${black_top[$i]}
                black_left[$i]=0
                black_right[$i]=0
   fi
done

#################################################
# CONVERTE O FORMATO DA COR DA LEGENDA           #     
#           (RGB -> YUV)                   #
#################################################
rgb_r=`echo $legenda_cor | cut -d"," -f1`
rgb_g=`echo $legenda_cor | cut -d"," -f2`
rgb_b=`echo $legenda_cor | cut -d"," -f3`

yuv_y=$((((299 * $rgb_r) + (587 * $rgb_g) + (114 * $rgb_b)) / 1000))
yuv_u=$((((500 * $rgb_r) - (419 * $rgb_g) - (81 * $rgb_b)) / 1000))
yuv_v=$((((-169 * $rgb_r) - (331 * $rgb_g) + (500 * $rgb_b)) / 1000))

#################################################
# CRIA O ARQUIVO FILME[]_DECODER.JS COM AS      #
# INFORMACOES OBTIDAS E FAZ A CONVERSAO           #
#################################################
for ((i=1; i<=$num_args; i=i+1))
do
echo -e "//AD  <- Needed to identify//
//--automatically built--
//--Project: $caminho_projeto${filme[$i]}_decoder.js

var app = new Avidemux();

//** Video **
// 01 videos source 
${force_unpack[$i]}
app.load(\"${filme_caminho[$i]}.avi\");
//01 segments
app.clearSegments();
app.addSegment(0,0,${total_frames[$i]});
app.markerA=0;
app.markerB=${markerb[$i]};

//** Postproc **
app.video.setPostProc(3,3,0);

app.video.setFps1000(${fps[$i]});

//** Filters **
app.video.addFilter(\"mpresize\",\"w=${resolucao_x[$i]}\",\"h=${resolucao_y[$i]}\",\"algo=0\");
app.video.addFilter(\"addblack\",\"left=${black_left[$i]}\",\"right=${black_right[$i]}\",\"top=${black_top[$i]}\",\"bottom=${black_bottom[$i]}\");
app.video.addFilter(\"subtitle\",\"_fontsize=$legenda_tamanho\",\"_subname=${filme_caminho[$i]}.srt\",\"_fontname=$legenda_fonte\",\"_charset=ISO-8859-1\",\"_baseLine=$legenda_posicao\",\"_Y_percent=$yuv_y\",\"_U_percent=$yuv_u\",\"_V_percent=$yuv_v\",\"_selfAdjustable=0\",\"_delay=0\",\"_useBackgroundColor=0\",\"_bg_Y_percent=0\",\"_bg_U_percent=0\",\"_bg_V_percent=0\",\"_blend=1\");
${fps_resample[$i]}

//** Video Codec conf **
app.video.codec(\"$video_codec\",\"$tipo_encode=${valor_conversao[$i]}\",\"$video_matriz \");

//** Audio **
app.audio.reset();
${audio_comando[$i]}
app.audio.normalizeMode=0;
app.audio.normalizeValue=0;
app.audio.delay=0;
app.audio.mixer(\"NONE\");
${build_time_map[$i]}
${audio_resample[$i]}
app.setContainer(\"PS\");
setSuccess(1);
//app.Exit();

//End of script
" > ~/.dvd/tmp/${filme[$i]}_decoder.js   

avidemux2_cli --nogui --run ~/.dvd/tmp/${filme[$i]}_decoder.js --output-format PS --save ~/.dvd/tmp/${filme[$i]}.mpeg --quit >~/.dvd/tmp/${filme[$i]}_conversao.log 2>~/.dvd/tmp/processo &

pid_avidemux=`ps aux | grep -m1 avidemux2_cli | grep ${filme[$i]}_decoder.js | tr -s " " | cut -d" " -f2`

tail -f --pid=$pid_avidemux ~/.dvd/tmp/processo | awk -vRS="\r" '$1 ~ /Done/ {
   gsub("Done:","");
   gsub("%",""); 
   print $1"\n#Completo: "$1"%\\nTempo Restante: "$5;  
   fflush();
   }' | zenity --title "AVI_DVD" --progress --auto-close

if ! [ $? == 0 ]
then
   kill -9 $pid_avidemux
   rm -r ~/.dvd/tmp/*
   zenity --title "AVI_DVD" --warning --text "Ocorreu um erro durante a conversão."
   exit 1
fi
done

#################################################
# OBTEM AS INFORMACOES NECESSARIAS PARA A       #
# CRIACAO DO MENU                               #
#################################################
user=`ps u | cut -d" " -f1 | tail -1`
titulo_filme="\"${nome[1]}\""
nome_mpeg="\"/home/$user/.dvd/tmp/${filme[1]}.mpeg\""

for ((i=2; i<=$num_args; i=i+1))
do
       titulo_filme="$titulo_filme \"${nome[$i]}\""
       nome_mpeg="$nome_mpeg \"/home/$user/.dvd/tmp/${filme[$i]}.mpeg\""
done

#################################################
# CRIA O ARQUIVO MENU.CONFIG COM AS             #
# INFORMACOES OBTIDAS                           #
#################################################
echo -e "
makemenu -noask -quiet -overwrite -$padrao_dvd -dvd -align northwest -menu-title \"$menu_titulo\" -menu-title-fontsize 32 -background \"$menu_imagem\" -font \"Helvetica\" -fontsize 24 -textcolor \"rgb($menu_fonte_cor)\" -fontdeco '-stroke rgb(0,0,0) -strokewidth 1' -button-font \"Helvetica\" -button \">\" -highlightcolor \"rgb(255,255,0)\" -selectcolor \"rgb(255,0,0)\" -button-outline \"rgb(140,140,140)\" $titulo_filme -out \"/home/$user/.dvd/tmp/DVD_MENU\"
makexml -quiet -overwrite -dvd -menu \"/home/$user/.dvd/tmp/DVD_MENU.mpg\" $nome_mpeg -out \"/home/$user/.dvd/tmp/DVD_FILME\"
makedvd -quiet -author /home/$user/.dvd/tmp/DVD_FILME.xml
" > ~/.dvd/tmp/menu.config
                  
#################################################
#       CRIA O MENU E A ESTRUTURA DO DVD        #
#################################################
chmod 777 ~/.dvd/tmp/menu.config
~/.dvd/tmp/menu.config 2> ~/.dvd/tmp/menu.erro | tee > ~/.dvd/tmp/menu.log >(zenity --progress --pulsate --title "AVI_DVD" --text "Criando o menu..." --auto-close)
                                 
#################################################
# FINALIZA E REMOVE OS ARQUIVOS TEMPORARIOS     #
#################################################
dir_dvd="DVD_FILME"
if [ -e ~/"$dir_dvd" ]
then
        i=1
        dir_dvd="DVD_FILME_$i"
        while [ -e ~/"$dir_dvd" ]
        do
                i=$(($i + 1))
                dir_dvd="DVD_FILME_$i"
        done
        mkdir ~/$dir_dvd
else
        mkdir ~/$dir_dvd
fi

mv ~/.dvd/tmp/DVD_FILME/* ~/$dir_dvd
rm -r ~/.dvd/tmp/*

zenity --title "AVI_DVD" --info --text "DVD criado com sucesso\!\nAgora utilize seu programa de gravação preferido para gravar a pasta \"~/$dir_dvd\" em DVD."

exit 0

Scripts recomendados

varrer.sh

Cracking protocolo WPS aprimorado

Zshortcut - criar atalhos no menu de programas

Grave arquivos em pendrive sem sistema de arquivos

wma2mp3


  

Comentários

Nenhum comentário foi encontrado.


Contribuir com comentário




Patrocínio

Site hospedado pelo provedor RedeHost.
Linux banner

Destaques

Artigos

Dicas

Tópicos

Top 10 do mês

Scripts