Вопрос

I am trying to make a bash script that searches all subfolders on given path for .mov files and converts them with ffmpeg and outputs them in an destination folder, keeping the clip name.

I'm very new to scripting and I'm having a hard time finding out how to solve this.

So far I've tried using ls and find to output the filepaths, but have no idea how to pipe this to ffmpeg in the right way.

Any clues?

Edit:

got some sucess with this:

#!/bin/bash

echo "drop source folder: "
read source

echo "drop destination folder: "
read des

find "$source" -name '*.mov' -exec sh -c 'ffmpeg -i "$0" -vcodec prores -profile:v 0 -an "$des/${0%%.mov}.mov"' {} \;
exit;

but, the it seems to output to the source folder asking for a overwrite. How can i setup the parameters correctly so it outputs to the "destination folder" and keeps the filenames?

Это было полезно?

Решение

You could start with this:

#!/bin/bash

shopt -s extglob || {
    echo "Unable to enable exglob."
    exit 1
}

TARGETEXT='.avi'
TARGETPREFIX='/path/to/somewhere/' ## Make sure it ends with /.

while IFS= read -r FILE; do
    BASE=${FILE##*/}
    NOEXT=${BASE%.*}
    TARGETFILEPATH=${TARGETPREFIX}${NOEXT}${TARGETEXT}
    echo ffmpeg -i "$FILE" "$TARGETFILEPATH"  ## Remove echo if it's already correct.
done < <(exec find -type f -name '*.mov')  ## You could also use -iname '*.sh' instead.

Of course you could use a custom directory to search for the files:

find /path/to/directory -type f -name '*.mov'

Другие советы

something like this should do the job:

for f in *.mov; do ffmpeg -i "$f" -vcodec copy -acodec copy "/desination/${f%.mov}.mp4"; done

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top