My note:

  1. Install Anaconda
  2. Setup the carnd-term1 environment as instructions in Starter Kit.
  3. Run the test.ipynb in the carnd-term1 kernel
  4. Troubleshoot with ffmpeg

Run all the cells below to make sure everything is working and ready to go. All cells should run without error.

Test Matplotlib and Plotting


In [1]:
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy as np
%matplotlib inline

In [2]:
img = mpimg.imread('test.jpg')
plt.imshow(img)


Out[2]:
<matplotlib.image.AxesImage at 0x119fb2198>

Test OpenCV


In [3]:
import cv2

In [4]:
# convert the image to grayscale
gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
plt.imshow(gray, cmap='Greys_r')


Out[4]:
<matplotlib.image.AxesImage at 0x11dccca90>

Test TensorFlow


In [5]:
import tensorflow as tf

In [6]:
with tf.Session() as sess:
    a = tf.constant(1)
    b = tf.constant(2)
    c = a + b
    # Should be 3
    print("1 + 2 = {}".format(sess.run(c)))


1 + 2 = 3

Test Moviepy


In [9]:
# Import everything needed to edit/save/watch video clips
from moviepy.editor import VideoFileClip
from IPython.display import HTML

Troubleshooting ffmpeg NOTE: If you don't have ffmpeg installed on your computer you'll have to install it for moviepy to work. If this is the case you'll be prompted by an error in the notebook. You can easily install ffmpeg by running the following in a code cell in the notebook.

import imageio

imageio.plugins.ffmpeg.download()


In [8]:
import imageio
imageio.plugins.ffmpeg.download()


Imageio: 'ffmpeg.osx' was not found on your computer; downloading it now.
Try 1. Download from https://github.com/imageio/imageio-binaries/raw/master/ffmpeg/ffmpeg.osx (28.8 MB)
Downloading: 8192/30241064 bytes (0.0221184/30241064 bytes (0.7663552/30241064 bytes (2.21155072/30241064 bytes (3.8%1679360/30241064 bytes (5.6%1908736/30241064 bytes (6.3%2498560/30241064 bytes (8.3%3014656/30241064 bytes (10.03416064/30241064 bytes (11.33956736/30241064 bytes (13.14546560/30241064 bytes (15.04988928/30241064 bytes (16.55365760/30241064 bytes (17.75955584/30241064 bytes (19.76299648/30241064 bytes (20.86905856/30241064 bytes (22.87430144/30241064 bytes (24.67921664/30241064 bytes (26.28445952/30241064 bytes (27.99003008/30241064 bytes (29.89584640/30241064 bytes (31.79740288/30241064 bytes (32.210297344/30241064 bytes (34.1%10690560/30241064 bytes (35.4%11264000/30241064 bytes (37.2%11919360/30241064 bytes (39.4%12279808/30241064 bytes (40.6%12836864/30241064 bytes (42.4%13295616/30241064 bytes (44.0%13852672/30241064 bytes (45.8%14426112/30241064 bytes (47.7%14917632/30241064 bytes (49.3%15441920/30241064 bytes (51.1%16023552/30241064 bytes (53.0%16556032/30241064 bytes (54.7%17162240/30241064 bytes (56.8%17833984/30241064 bytes (59.0%18374656/30241064 bytes (60.8%19030016/30241064 bytes (62.9%19636224/30241064 bytes (64.9%20226048/30241064 bytes (66.9%20815872/30241064 bytes (68.8%21159936/30241064 bytes (70.0%21782528/30241064 bytes (72.0%22257664/30241064 bytes (73.6%22798336/30241064 bytes (75.4%23339008/30241064 bytes (77.2%23896064/30241064 bytes (79.0%24436736/30241064 bytes (80.8%24821760/30241064 bytes (82.1%25346048/30241064 bytes (83.8%25935872/30241064 bytes (85.8%26533888/30241064 bytes (87.7%27058176/30241064 bytes (89.5%27484160/30241064 bytes (90.9%28057600/30241064 bytes (92.8%28467200/30241064 bytes (94.1%28909568/30241064 bytes (95.6%29384704/30241064 bytes (97.2%29622272/30241064 bytes (98.0%30089216/30241064 bytes (99.5%30241064/30241064 bytes (100.0%)
  Done
File saved as /Users/phuongpham/Library/Application Support/imageio/ffmpeg/ffmpeg.osx.

Create a new video with moviepy by processing each frame to YUV color space.


In [10]:
new_clip_output = 'test_output.mp4'
test_clip = VideoFileClip("test.mp4")
new_clip = test_clip.fl_image(lambda x: cv2.cvtColor(x, cv2.COLOR_RGB2YUV)) #NOTE: this function expects color images!!
%time new_clip.write_videofile(new_clip_output, audio=False)


[MoviePy] >>>> Building video test_output.mp4
[MoviePy] Writing video test_output.mp4
100%|██████████| 251/251 [00:08<00:00, 31.11it/s]
[MoviePy] Done.
[MoviePy] >>>> Video ready: test_output.mp4 

CPU times: user 2.42 s, sys: 989 ms, total: 3.41 s
Wall time: 9.39 s

In [11]:
HTML("""
<video width="640" height="300" controls>
  <source src="{0}" type="video/mp4">
</video>
""".format(new_clip_output))


Out[11]:

In [ ]: