Refactoring embedding of video in notebooks

This commit is contained in:
Jason Antic
2019-04-16 19:52:52 -07:00
parent 552958fa74
commit 1d0ae23ec5
3 changed files with 43 additions and 130 deletions
+7 -57
View File
@@ -138,8 +138,6 @@
"import fastai\n",
"from fasterai.visualize import *\n",
"from pathlib import Path\n",
"import base64\n",
"from IPython import display as ipythondisplay\n",
"torch.backends.cudnn.benchmark=True"
]
},
@@ -153,28 +151,6 @@
"!wget https://www.dropbox.com/s/336vn9y4qwyg9yz/ColorizeVideo_gen.pth?dl=0 -O ./models/ColorizeVideo_gen.pth"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"file_name = 'video.mp4'\n",
"source_dir = './video/source/'\n",
"source_path = source_dir + file_name\n",
"dest_dir = './video/result/'\n",
"dest_path = dest_dir + file_name"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!mkdir file_dir"
]
},
{
"cell_type": "code",
"execution_count": null,
@@ -188,21 +164,6 @@
"colorizer = get_video_colorizer()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def show_video():\n",
" video = io.open(dest_path, 'r+b').read()\n",
" encoded = base64.b64encode(video)\n",
" ipythondisplay.display(HTML(data='''<video alt=\"test\" autoplay \n",
" loop controls style=\"height: 400px;\">\n",
" <source src=\"data:video/mp4;base64,{0}\" type=\"video/mp4\" />\n",
" </video>'''.format(encoded.decode('ascii'))))"
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -220,10 +181,13 @@
"### Instructions\n",
"\n",
"#### source_url\n",
"YouTube, Imgur, Twitter, Reddit ... files of type .gif, .gifv and .mp4 work. NOTE: If you want to use your own video, upload it first to a site like YouTube. \n",
"YouTube, Imgur, Twitter, Reddit, Vimeo, etc. Many sources work! GIFs also work. Full list here: https://ytdl-org.github.io/youtube-dl/supportedsites.html NOTE: If you want to use your own video, upload it first to a site like YouTube. \n",
"\n",
"#### render_factor\n",
"The default value of 21 has been carefully chosen and should work -ok- for most scenarios (but probably won't be the -best-). This determines resolution at which video is rendered. Lower resolution will render faster, and colors also tend to look more vibrant. Older and lower quality film in particular will generally benefit by lowering the render factor. Higher render factors are often better for higher quality videos and inconsistencies (flashy render) will generally be reduced, but the colors may get slightly washed out. "
"The default value of 21 has been carefully chosen and should work -ok- for most scenarios (but probably won't be the -best-). This determines resolution at which video is rendered. Lower resolution will render faster, and colors also tend to look more vibrant. Older and lower quality film in particular will generally benefit by lowering the render factor. Higher render factors are often better for higher quality videos and inconsistencies (flashy render) will generally be reduced, but the colors may get slightly washed out. \n",
"\n",
"#### How to Download a Copy\n",
"Simply right click on the displayed video and click \"Save video as...\"!"
]
},
{
@@ -236,26 +200,12 @@
"render_factor = 21 #@param {type: \"slider\", min: 7, max: 46}\n",
"\n",
"if source_url is not None and source_url !='':\n",
" colorizer.colorize_from_url(source_url, file_name, render_factor)\n",
" show_video()\n",
" video_path = colorizer.colorize_from_url(source_url, 'video.mp4', render_factor)\n",
" show_video_in_notebook(video_path)\n",
"else:\n",
" print('Provide a video url and try again.')"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "A5WMS_GgP4fm"
},
"source": [
"#◢ Download\n",
"\n",
"* In the menu to the left, click **Files**\n",
"* If you don't see the 'DeOldify' folder, click \"Refresh\"\n",
"* By default, rendered video will be in /DeOldify/video/result/"
]
},
{
"cell_type": "markdown",
"metadata": {