In [2]:
import helpers as h
h.create_small_videos()


['behindthefence', 'cherynobl', 'download-new-examples.ipynb', 'goproad', 'grandteton', 'internetsurfer', 'invisible', 'mentos', 'nationalparks', 'pacificnorthwest', 'reef', 'seals', 'sharks', 'surreal', 'tokyo', 'viking', 'worldwonder']
[]
['behindthefence', 'cherynobl', 'download-new-examples.ipynb', 'goproad', 'grandteton', 'internetsurfer', 'invisible', 'mentos', 'nationalparks', 'pacificnorthwest', 'reef', 'seals', 'sharks', 'surreal', 'tokyo', 'viking', 'worldwonder']
processing video behindthefence
processing video cherynobl
processing video download-new-examples.ipynb
processing video goproad
processing video grandteton
processing video internetsurfer
processing video invisible
processing video mentos
processing video nationalparks
processing video pacificnorthwest
processing video reef
processing video seals
processing video sharks
processing video surreal
processing video tokyo
processing video viking
---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
<ipython-input-2-4c778badfdf3> in <module>()
      1 import helpers as h
----> 2 h.create_small_videos()

/Users/apavel/Sites/360-video-project/vrview/examples/orientations/helpers.py in create_small_videos(bases)
    203         fn_out = "new-videos/" + video + "-small.mp4"
    204 
--> 205         subprocess.call(["ffmpeg", "-i", fn_in, "-vf", "scale=500:-2", fn_out])
    206 
    207 # attempting optical flow on one 360 video

/usr/local/Cellar/python/2.7.8_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.pyc in call(*popenargs, **kwargs)
    520     retcode = call(["ls", "-l"])
    521     """
--> 522     return Popen(*popenargs, **kwargs).wait()
    523 
    524 

/usr/local/Cellar/python/2.7.8_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.pyc in wait(self)
   1374             while self.returncode is None:
   1375                 try:
-> 1376                     pid, sts = _eintr_retry_call(os.waitpid, self.pid, 0)
   1377                 except OSError as e:
   1378                     if e.errno != errno.ECHILD:

/usr/local/Cellar/python/2.7.8_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.pyc in _eintr_retry_call(func, *args)
    474     while True:
    475         try:
--> 476             return func(*args)
    477         except (OSError, IOError) as e:
    478             if e.errno == errno.EINTR:

KeyboardInterrupt: 

In [1]:
%matplotlib inline
import cv2
from matplotlib import pyplot as plt
import time

import os, json, sys
sys.path.append("../../../../../resources/pyimgsaliency/")
import pyimgsaliency as psal

import scipy.misc, os
import subprocess
from PIL import Image

VIDEO_FRAMES_ROOT = "video-frames-medium/"
ANALYSIS_ROOT = "analysis/image-saliency/"
VIDEO_ROOT = "new-videos/"

time_ref = {
    "snowboarding": [151.868109 + 29, 241],
    "hpo-preview": [0, 60.5],
    "surfing": [45, 105],
    "dining-at-the-met": [30, 96],
    "knives": [0,35],
    "trees": [82,150],
    "invasion": [120, 180],
    "ice-art": [4,70],
    "volcano": [93,160]
}
already_done = [f.split(".json")[0] for f in os.listdir("analysis/image-saliency/") if f[0] != "."]
bases = [f for f in os.listdir("video-frames/") if "." not in f and f not in already_done][1:]
print bases

def get_immediate_subdirectories(a_dir):
    return [name for name in os.listdir(a_dir)
            if os.path.isdir(os.path.join(a_dir, name))]

def any_base_in_fn(f): 
        for base in bases: 
            if base in f: 
                return True
        return False

all_videos = [v for v in os.listdir(VIDEO_ROOT) if "small" in v and v[0] !='.' if "arctic" not in v and "congo" not in v]
all_videos = [v for v in all_videos if any_base_in_fn(v)]
print all_videos

for video in all_videos:
    base = video.lower().split(".mp4")[0]
    print "Processing video:", base
    video_path = VIDEO_ROOT + video
    video_frames_path = VIDEO_FRAMES_ROOT + base + "/"
    
    # delete any existing video frames
    sub_directory_paths = [VIDEO_FRAMES_ROOT + p + "/" for p in get_immediate_subdirectories(VIDEO_FRAMES_ROOT)]
    for d in sub_directory_paths: 
        for frame in os.listdir(d):
            os.remove(d + frame)
            
    # make a new directory
    if not os.path.exists(video_frames_path):
        os.mkdir(video_frames_path)
    
    start_time = time.time()
    
    # split the video into smaller video frames
    subprocess.call(["ffmpeg", "-i", video_path, "-vf", "fps=2", video_frames_path + "%05d.png"])
    
    analysis_path = ANALYSIS_ROOT + base + "/"
    
    # make a new directory
    if not os.path.exists(analysis_path):
        os.mkdir(analysis_path)
    
    # ok now we actually want to just take 2 frames per second
    fns = [video_frames_path + fn for fn in os.listdir(video_frames_path) if ".png" in fn]
#     new_fns = []
#     for i in range(len(fns)): 
#         fn = fns[i]
#         if i % 15 == 0: 
#             new_fns.append(fn)
#     fns = new_fns
    
    for frame_fn in fns: 
        out_fn = analysis_path + frame_fn.split("/")[-1]
        try: 
            sal_map = psal.get_saliency_mbd(frame_fn).astype('uint8')
            im = Image.fromarray(sal_map)
            im.save(out_fn)
        except: 
            print frame_fn
        
    print "Time to process:", time.time() - start_time


['dining-at-the-met', 'goproad', 'grandteton', 'hong-kong-nytimes', 'mentos', 'tokyo']
['goproad-small.mp4', 'grandteton-small.mp4', 'mentos-small.mp4', 'tokyo-small.mp4']
Processing video: goproad-small
video-frames-medium/goproad-small/00001.png
video-frames-medium/goproad-small/00002.png
video-frames-medium/goproad-small/00003.png
video-frames-medium/goproad-small/00004.png
video-frames-medium/goproad-small/00005.png
video-frames-medium/goproad-small/00229.png
video-frames-medium/goproad-small/00230.png
video-frames-medium/goproad-small/00231.png
video-frames-medium/goproad-small/00232.png
video-frames-medium/goproad-small/00233.png
video-frames-medium/goproad-small/00234.png
video-frames-medium/goproad-small/00235.png
video-frames-medium/goproad-small/00236.png
video-frames-medium/goproad-small/00237.png
video-frames-medium/goproad-small/00238.png
video-frames-medium/goproad-small/00239.png
video-frames-medium/goproad-small/00240.png
video-frames-medium/goproad-small/00241.png
video-frames-medium/goproad-small/00242.png
video-frames-medium/goproad-small/00243.png
Time to process: 240.429791927
Processing video: grandteton-small
video-frames-medium/grandteton-small/00001.png
video-frames-medium/grandteton-small/00002.png
video-frames-medium/grandteton-small/00003.png
video-frames-medium/grandteton-small/00004.png
video-frames-medium/grandteton-small/00005.png
video-frames-medium/grandteton-small/00006.png
video-frames-medium/grandteton-small/00119.png
video-frames-medium/grandteton-small/00120.png
video-frames-medium/grandteton-small/00121.png
video-frames-medium/grandteton-small/00122.png
video-frames-medium/grandteton-small/00123.png
video-frames-medium/grandteton-small/00124.png
video-frames-medium/grandteton-small/00125.png
video-frames-medium/grandteton-small/00126.png
Time to process: 126.954035997
Processing video: mentos-small
video-frames-medium/mentos-small/00001.png
video-frames-medium/mentos-small/00002.png
video-frames-medium/mentos-small/00003.png
video-frames-medium/mentos-small/00004.png
video-frames-medium/mentos-small/00005.png
video-frames-medium/mentos-small/00006.png
video-frames-medium/mentos-small/00007.png
video-frames-medium/mentos-small/00008.png
video-frames-medium/mentos-small/00009.png
video-frames-medium/mentos-small/00010.png
video-frames-medium/mentos-small/00253.png
video-frames-medium/mentos-small/00254.png
video-frames-medium/mentos-small/00255.png
video-frames-medium/mentos-small/00256.png
video-frames-medium/mentos-small/00257.png
video-frames-medium/mentos-small/00258.png
video-frames-medium/mentos-small/00259.png
video-frames-medium/mentos-small/00260.png
video-frames-medium/mentos-small/00261.png
video-frames-medium/mentos-small/00262.png
video-frames-medium/mentos-small/00263.png
video-frames-medium/mentos-small/00264.png
video-frames-medium/mentos-small/00300.png
video-frames-medium/mentos-small/00301.png
Time to process: 301.748976946
Processing video: tokyo-small
video-frames-medium/tokyo-small/00001.png
video-frames-medium/tokyo-small/00002.png
video-frames-medium/tokyo-small/00003.png
video-frames-medium/tokyo-small/00004.png
video-frames-medium/tokyo-small/00005.png
video-frames-medium/tokyo-small/00205.png
video-frames-medium/tokyo-small/00206.png
video-frames-medium/tokyo-small/00207.png
video-frames-medium/tokyo-small/00208.png
video-frames-medium/tokyo-small/00209.png
video-frames-medium/tokyo-small/00210.png
video-frames-medium/tokyo-small/00211.png
video-frames-medium/tokyo-small/00212.png
Time to process: 213.861281872
../../../../../resources/pyimgsaliency/pyimgsaliency/saliency_mbd.py:214: RuntimeWarning: invalid value encountered in maximum
  u_max = np.maximum(np.maximum(np.maximum(u_left,u_right),u_top),u_bottom)
rbd

In [2]:
3 + 4


Out[2]:
7

In [ ]: