Created
May 30, 2018 21:23
-
-
Save bearpelican/f42714226bef41c88152ca1cc60b70f9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"from moviepy.editor import VideoFileClip\n", | |
"from moviepy.editor import ImageSequenceClip\n", | |
"import os\n", | |
"\n", | |
"import sys, skvideo.io" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 33, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# Define pathname to save the output video\n", | |
"mpy_output = 'mpy_new_test_video.mp4'\n", | |
"image_folder = 'Test/CameraRGB/'\n", | |
"\n", | |
"images = sorted([(image_folder+img) for img in os.listdir(image_folder) if img.endswith(\".png\")])" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 39, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"30\n", | |
"30\n", | |
"[MoviePy] >>>> Building video mpy_new_test_video.mp4\n", | |
"[MoviePy] Writing video mpy_new_test_video.mp4\n" | |
] | |
}, | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"100%|██████████| 31/31 [00:00<00:00, 57.56it/s]\n" | |
] | |
}, | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"[MoviePy] Done.\n", | |
"[MoviePy] >>>> Video ready: mpy_new_test_video.mp4 \n", | |
"\n" | |
] | |
} | |
], | |
"source": [ | |
"print (len(images))\n", | |
"\n", | |
"clip = ImageSequenceClip(images, fps=10)\n", | |
"\n", | |
"print (len(clip.sequence))\n", | |
"\n", | |
"clip.write_videofile(mpy_output, audio=False)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"sk_output = 'sk_new_test_video.mp4'" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 42, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"(30, 600, 800, 3)" | |
] | |
}, | |
"execution_count": 42, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"import numpy as np\n", | |
"import cv2\n", | |
"\n", | |
"np_images = np.array([cv2.cvtColor(cv2.imread(i), cv2.COLOR_BGR2RGB) for i in images]); np_images.shape" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 32, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"skvideo.io.vwrite(sk_output, np_images)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"### Results" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 43, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"(30, 600, 800, 3)" | |
] | |
}, | |
"execution_count": 43, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"sk_res = skvideo.io.vread(sk_output); sk_res.shape" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 44, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"(31, 600, 800, 3)" | |
] | |
}, | |
"execution_count": 44, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"mpy_res = skvideo.io.vread(mpy_output); mpy_res.shape" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.6.4" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment