Skip to content

Commit f7b935b

Browse files
committed
DOC: Demonstrate how to programatically start/stop recording, save
1 parent 1d1ab75 commit f7b935b

File tree

2 files changed

+54
-9
lines changed

2 files changed

+54
-9
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ examples/Bunny.vtp
2727
examples/uGridEx.vtk
2828
examples/input.tiff
2929
examples/Normal071-VascularNetwork.tre
30+
examples/video.mp4
3031

3132
js/lib/ZstdDecompress/web-build/
3233
.pytest_cache/

examples/RecordAVideo.ipynb

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,21 @@
99
"# Install dependencies for this example\n",
1010
"# Note: This does not include itkwidgets, itself\n",
1111
"# The page may need to be reloaded after ipywebrtc is installed\n",
12+
"# And another note: As of this writing, ipywebrtc has not been updated to work\n",
13+
"# with JupyterLab 2 or JupyterLab 3 -- JupyterLab 1 or the Jupyter Notebook is required.\n",
1214
"import sys\n",
13-
"!{sys.executable} -m pip install itk-io ipywebrtc>=0.5.1"
15+
"!{sys.executable} -m pip install itk-io ipywebrtc"
1416
]
1517
},
1618
{
1719
"cell_type": "code",
18-
"execution_count": 1,
20+
"execution_count": 7,
1921
"metadata": {},
2022
"outputs": [],
2123
"source": [
2224
"from urllib.request import urlretrieve\n",
2325
"import os\n",
26+
"import time\n",
2427
"\n",
2528
"import itk\n",
2629
"\n",
@@ -31,7 +34,7 @@
3134
},
3235
{
3336
"cell_type": "code",
34-
"execution_count": 2,
37+
"execution_count": 3,
3538
"metadata": {},
3639
"outputs": [],
3740
"source": [
@@ -44,18 +47,18 @@
4447
},
4548
{
4649
"cell_type": "code",
47-
"execution_count": 3,
50+
"execution_count": 4,
4851
"metadata": {},
4952
"outputs": [
5053
{
5154
"data": {
5255
"application/vnd.jupyter.widget-view+json": {
53-
"model_id": "2d337065a4ba48bdaf7693d44eae7d9c",
56+
"model_id": "216f67a967bb476cafa57ef208dc6df7",
5457
"version_major": 2,
5558
"version_minor": 0
5659
},
5760
"text/plain": [
58-
"Viewer(annotations=False, cmap='BuRd', geometries=[], gradient_opacity=0.22, point_sets=[], rendered_image=<it"
61+
"Viewer(annotations=False, cmap=['BuRd'], geometries=[], gradient_opacity=0.22, point_sets=[], rendered_image=<…"
5962
]
6063
},
6164
"metadata": {},
@@ -71,18 +74,18 @@
7174
},
7275
{
7376
"cell_type": "code",
74-
"execution_count": 4,
77+
"execution_count": 5,
7578
"metadata": {},
7679
"outputs": [
7780
{
7881
"data": {
7982
"application/vnd.jupyter.widget-view+json": {
80-
"model_id": "19b8e9ffead7440ea807df5d810c7a16",
83+
"model_id": "045847c75ed440b4a020960e705f4378",
8184
"version_major": 2,
8285
"version_minor": 0
8386
},
8487
"text/plain": [
85-
"VideoRecorder(autosave=True, filename='widget_video.webm', stream=Viewer(annotations=False, cmap='BuRd', geome"
88+
"VideoRecorder(autosave=True, filename='widget_video.webm', stream=Viewer(annotations=False, background=(0.9333"
8689
]
8790
},
8891
"metadata": {},
@@ -94,6 +97,34 @@
9497
"recorder"
9598
]
9699
},
100+
{
101+
"cell_type": "markdown",
102+
"metadata": {},
103+
"source": [
104+
"The recorder widget has button to record, playback, and download the video, but this is also possible programmatically."
105+
]
106+
},
107+
{
108+
"cell_type": "code",
109+
"execution_count": 9,
110+
"metadata": {},
111+
"outputs": [],
112+
"source": [
113+
"recorder.recording = True\n",
114+
"time.sleep(3)\n",
115+
"recorder.recording = False"
116+
]
117+
},
118+
{
119+
"cell_type": "code",
120+
"execution_count": 13,
121+
"metadata": {},
122+
"outputs": [],
123+
"source": [
124+
"# Save to a different file in a different format\n",
125+
"recorder.save('video.mp4')"
126+
]
127+
},
97128
{
98129
"cell_type": "markdown",
99130
"metadata": {},
@@ -144,6 +175,19 @@
144175
"nbconvert_exporter": "python",
145176
"pygments_lexer": "ipython3",
146177
"version": "3.7.6"
178+
},
179+
"toc": {
180+
"base_numbering": 1,
181+
"nav_menu": {},
182+
"number_sections": false,
183+
"sideBar": false,
184+
"skip_h1_title": false,
185+
"title_cell": "Table of Contents",
186+
"title_sidebar": "Contents",
187+
"toc_cell": false,
188+
"toc_position": {},
189+
"toc_section_display": false,
190+
"toc_window_display": false
147191
}
148192
},
149193
"nbformat": 4,

0 commit comments

Comments
 (0)