1

What command will convert multiple video files to multiple GIFs?

I use the following command to convert 1 video to GIF:

ffmpeg -i input.flv -vf scale=320:-1 output.gif

I assume I'll need a bash script or some command with loop.

This thread is vaguely related to my question.

3

You can use the following command

for f in ./*.flv; do
    ffmpeg -i "$f" -vf scale=320:-1 "${f%.*}.gif"
done

This iterates over all files ending with .flv in the current directory, processing them and changing the extension to .gif.

Note that the file names must not contain spaces for this to work.

Alternatively, on a GNU system, you can use

find . -maxdepth 1 -name "*.flv" -print0 |
  sed 's/\.flv\x00/\x00/g' |
  xargs -r0 -I FILENAME ffmpeg -i FILENAME.flv -vf scale=320:-1 FILENAME.gif

This will find all files ending with .flv (including hidden ones) in the current directory and print that list to the standard output as a \0-delimited string. That string is then filtered through sed to remove the extensions and then passed to xargs which executes the command ffmpeg -i FILENAME.flv -vf scale=320:-1 FILENAME.gif, replacing FILENAME by the actual file name from the list.

If you want to convert all files in the current directory and all sub-directories (and their sub-directories and so on), just remove the -maxdepth 1 part from the command.

  • Unless your files contain newline characters, sed will only see one record which means storing the whole file list in memory and starting the processing only after find has finished crawling the directory. With a recent GNU sed, you could use sed -z 's/\.flv$//' instead. – Stéphane Chazelas Dec 16 '14 at 15:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.