8

I'm converting all of my video files to WebM, to greatly reduce the amount of hard disk space being used. To do this I use the program "ffmpeg" which requires an input and output file specified. Since the converting process takes a long time, I wish to run it day and night for every video file in my video folder, so I don't have to manually do it myself.

By Googling myself I found ways to do this but the output would be 1 big file. Can anybody explain me how I convert "video1.avi" to "video1.webm", and "video2.avi" to "video2.webm", etc etc automatically?

3 Answers3

16

You can use a bash loop - the basic structure would be something like

for file in *.avi; do ffmpeg -i "$file" "${file%.avi}".webm; done

You can add whatever other ffmpeg command line options you require as appropriate.

steeldriver
  • 136,215
  • 21
  • 243
  • 336
1

Below a python script to do the job:

#!/usr/bin/env python3

import os
import subprocess

sourcedir = "/path/to/sourcedirectory"

for file in os.listdir(sourcedir):
    name = file[:file.rfind(".")]
    subprocess.call(["fmpeg", "-i", sourcedir+"/"+name+".avi", sourcedir+"/"+name+".webm"])

By using subproces.call() the script will only continue on the next conversion when the last one has finished.

To use:

Copy the script into an empty text file, set the source directory of your files, save it as convert.py and run it by the command

python3 /path/to/convert.py
Jacob Vlijm
  • 83,767
0

You can also use my free application. It is called dmMediaConverter and it is a simple frontend for ffmpeg. For your need you must use bulk option then drop all files that you need converted and choose the appropriate options. The naming for output files is done automatically. Yoiu must download it from the link below since the one in Ubuntu Software Center is to old. I hope that you like it. http://dmsimpleapps.blogspot.ro/2014/04/dmmediaconverter.html

mdalacu
  • 670