Skip to content

Commit

Permalink
Add more play methods
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikWin committed Aug 20, 2024
1 parent bea582e commit 89fea90
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
2 changes: 2 additions & 0 deletions docs/src/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ This plays this result:
<source src="https://f.dominik.win/data/dve2/quickstart-hello-world.mp4" type="video/mp4" />
</video>

> Some Jupyter environments are weird (i.e., VS Code), so `.play()` might not work. Using `.play(..., method="iframe")` may help.
It's worth noting that we are playing frames in order here and outputing video at the same framerate we recieved, but that doesn't need to be the case.
Here are some things other things you can now try:

Expand Down
2 changes: 1 addition & 1 deletion vidformer-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "vidformer-cli"
version = "0.4.0"
version = "0.4.1"
edition = "2021"

[dependencies]
Expand Down
20 changes: 17 additions & 3 deletions vidformer-py/src/vidformer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""A Python library for creating and viewing videos with vidformer."""

__version__ = "0.4.0"
__version__ = "0.4.1"

import subprocess
from fractions import Fraction
Expand Down Expand Up @@ -80,8 +80,6 @@ def _to_json_spec(self):
def play(self, server, method="html"):
"""Play the video live in the notebook."""

from IPython.display import IFrame, HTML

spec, sources, filters = self._to_json_spec()
spec_json_bytes = json.dumps(spec).encode("utf-8")
spec_obj_json_gzip = gzip.compress(spec_json_bytes, compresslevel=1)
Expand Down Expand Up @@ -112,9 +110,17 @@ def play(self, server, method="html"):
namespace = resp["namespace"]
hls_js_url = server.hls_js_url()

if method == "link":
return hls_video_url
if method == "player":
return hls_player_url
if method == "iframe":
from IPython.display import IFrame

return IFrame(hls_player_url, width=1280, height=720)
if method == "html":
from IPython.display import HTML

# We add a namespace to the video element to avoid conflicts with other videos
html_code = f"""
<!DOCTYPE html>
Expand Down Expand Up @@ -439,6 +445,14 @@ def __getitem__(self, idx):
raise Exception("Source index must be a Fraction")
return SourceExpr(self, idx, False)

def play(self, *args, **kwargs):
"""Play the video live in the notebook."""

domain = self.ts()
render = lambda t, i: self[t]
spec = Spec(domain, render, self.fmt())
return spec.play(*args, **kwargs)


class StorageService:
def __init__(self, service: str, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion vidformer/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "vidformer"
version = "0.4.0"
version = "0.4.1"
description = "A data-systems focused library for declarative video synthesis."
authors = ["Dominik Winecki <dominikwinecki@gmail.com>"]
edition = "2021"
Expand Down

0 comments on commit 89fea90

Please sign in to comment.