How to list all files in ". ts" format of folders and subfolders to be converted to ". avi"?

Asked

Viewed 392 times

1

I found a shell-script and modified it to meet my need and stayed like this:

#!/bin/bash
[ "$1" ] && cd "$1"

ls -1 *.TS
[ "$?" -ne 0 ] && echo 'Sem arquivos TS nesse diretório' && exit 0
for ARQUIVO in $(ls -1 *.TS)
do
ARQ_DESTINO="${ARQUIVO%%.TS}.avi"
echo "Convertendo $ARQUIVO para $ARQ_DESTINO"

ffmpeg -i "$ARQUIVO" -vcodec libxvid -b 2000k \
-acodec libmp3lame -ac 2 -ar 44100 -ab 128k "$ARQ_DESTINO"
done

Only I don’t know how to make this script enter the subdirectories and take each file .ts and convert to .avi, in this case up there it only does in the directory in which the script is.

How can I do with this script to do this process?

1 answer

4


Perhaps it would be more appropriate to use the find for this task:

find . -name "*.TS" | while read -r ARQUIVO; do
  ARQ_DESTINO="${ARQUIVO%%.TS}.avi"
  echo "Convertendo $ARQUIVO para $ARQ_DESTINO"
  #....   
done

The point . indicates the current directory, the search starts from it.

  • Stayed like this: #!/bin/bash&#xA;[ "$1" ] && cd "$1"&#xA;find . -name "*.TS" | while read -r ARQUIVO; &#xA;do&#xA; ARQ_DESTINO="${ARQUIVO%%.TS}.avi"&#xA; echo "Convertendo $ARQUIVO para $ARQ_DESTINO"&#xA; ffmpeg -i "$ARQUIVO" -vcodec libxvid -b 2000k \&#xA; -acodec libmp3lame -ac 2 -ar 44100 -ab 128k "$ARQ_DESTINO"&#xA;done. Mais did not work on execution. I think my code has some error only can. Returns this error: Enter command: <target>|all <time>|-1 <command>[ <argument>]&#xA;Parse error, at least 3 arguments were expected, only 1 given in string

  • 1

    @JB_ On the line of ffmpeg add at the end < /dev/null, for example: ffmpeg ... -ab 128k "$ARQ_DESTINO" < /dev/null

  • Very good, worked. Fixed the problem. < /dev/null was the final solution. Thanks.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.