Skip to content

Instantly share code, notes, and snippets.

Revisions

  1. ferreirafabio renamed this gist Sep 11, 2018. 1 changed file with 0 additions and 0 deletions.
  2. ferreirafabio renamed this gist Sep 11, 2018. 1 changed file with 0 additions and 0 deletions.
  3. ferreirafabio revised this gist Sep 11, 2018. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions augment_gamma_brightness_saturation_ffmpeg
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    % contributors: Jonas Rothfuss and Fabio Ferreira

    import itertools
    import os
    import subprocess
  4. ferreirafabio created this gist Sep 11, 2018.
    34 changes: 34 additions & 0 deletions augment_gamma_brightness_saturation_ffmpeg
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    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))