Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ferreirafabio/770eb6bfdb01c0f616eb1ef0e1255d13 to your computer and use it in GitHub Desktop.
Save ferreirafabio/770eb6bfdb01c0f616eb1ef0e1255d13 to your computer and use it in GitHub Desktop.
Augment video files with ffmpeg by changing their gamma, brightness and/or saturation values
% contributors: Jonas Rothfuss and Fabio Ferreira
import itertools
import os
import subprocess
import glob
AVI_SOURCE_DIR = '/data/rothfuss/data/ArmarExperiences/videos/memory'
TARGET_DIR = '/data/rothfuss/data/ArmarExperiences/videos/memory_augmented'
GAMMA_VALS = [0.7, 1.0]
BRIGHTNESS_VALS = [-0.1, 0.0, 0.2]
SATURATION = [0.6, 1.0]
avi_files = io.file_paths_from_directory(AVI_SOURCE_DIR, '*.avi')
def augment_video(video_path, target_dir, gamma, brightness, saturation, i):
video_id = os.path.basename(video_path).split('.')[0]
new_video_path = os.path.join(target_dir, video_id + '_%i.avi'%i)
ffmpeg_str = "/common/homes/students/rothfuss/Documents/ffmpeg/bin/ffmpeg -i %s -vf eq=gamma=%.1f:brightness=%.1f:saturation=%.1f -c:a copy %s"%(video_path, gamma, brightness, saturation, new_video_path)
print(ffmpeg_str)
subprocess.Popen(ffmpeg_str, shell=True)
def file_paths_from_directory(dir_str, file_type):
return glob.glob(os.path.join(dir_str, file_type))
for file in avi_files:
for i, (gamma, brightness, saturation) in enumerate(itertools.product(GAMMA_VALS, BRIGHTNESS_VALS, SATURATION)):
try:
augment_video(file, TARGET_DIR, gamma, brightness, saturation, i)
print("%i: "%i + "Sucessfully augmented " + file)
except Exception as e:
print("%i: "%i + "Could not augment " + file + " --- " + str(e))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment