Skip to content

Commit

Permalink
user guide: add script to record on all cams from braid
Browse files Browse the repository at this point in the history
  • Loading branch information
astraw committed Jan 25, 2024
1 parent ebf1bc0 commit d4c46a2
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
56 changes: 56 additions & 0 deletions strand-braid-user/scripts/record-mp4-video-braid-all-cams.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env python
import argparse
import json
import time
import sys
from urllib.parse import urlparse
import requests # https://docs.python-requests.org/en/latest/user/install


class BraidProxy:
def __init__(self, braid_url):
self.callback_url = urlparse(braid_url)._replace(path="callback").geturl()
# Setup initial session
self.session = requests.session()
r = self.session.get(braid_url)
if r.status_code != requests.codes.ok:
print(f"request URL: {braid_url}")
print("request failed. response:")
print(r.text)
raise RuntimeError("connection to braid failed.")

def send(self, cmd_dict):
body = json.dumps(cmd_dict)
r = self.session.post(
self.callback_url, data=body, headers={"Content-Type": "application/json"}
)
if r.status_code != requests.codes.ok:
print(
"error making request, status code {}".format(r.status_code),
file=sys.stderr,
)
sys.exit(1)


def main():
parser = argparse.ArgumentParser()

parser.add_argument(
"--braid-url",
type=str,
default="http://127.0.0.1:33333/",
help="URL of Braid",
)
args = parser.parse_args()
braid = BraidProxy(braid_url=args.braid_url)

braid.send({"DoRecordMp4Files": True})
print("Recording for 5 seconds...")
time.sleep(5.0)

braid.send({"DoRecordMp4Files": False})
print("...finished.")


if __name__ == "__main__":
main()
7 changes: 6 additions & 1 deletion strand-braid-user/users-guide/src/scripting-with-python.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@ can also be controlled from a Python script. The general technique is to use a
Python library to connect to a running Strand Cam (or Braid) program exactly
like a web browser does it.

## Demo: changing tracking settings from a Python script
## Demo: recording a video using Strand Camera from a Python script

TODO: describe how to use and modify the [`record-mp4-video.py`
demo](https://github.com/strawlab/strand-braid/blob/main/strand-braid-user/scripts/record-mp4-video.py).

## Demo: recording multiple videos using Braid from a Python script

TODO: describe how to use and modify the [`record-mp4-video-braid-all-cams.py`
demo](strand-braid-user/scripts/record-mp4-video-braid-all-cams.py).

## Advanced: automating manual actions

TODO: describe how to use the developer tools to watch the network requests from
Expand Down

0 comments on commit d4c46a2

Please sign in to comment.