Skip to content

Commit

Permalink
Feat/containers3 (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
KenwoodFox authored Jul 31, 2023
1 parent 684a3b5 commit 1435c0c
Show file tree
Hide file tree
Showing 40 changed files with 776 additions and 586 deletions.
88 changes: 46 additions & 42 deletions Houston-Streamer/RobotStreamer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import logging
import subprocess as sp
import utils.rsUtils as rsutil
import cv2 as cv

# import importlib.util
# spec = importlib.util.spec_from_file_location(
Expand Down Expand Up @@ -41,6 +40,7 @@ def __init__(self):
self.camera_id = "5505"
self.api_server = "https://api.robotstreamer.com"
endpointData = rsutil.getVideoEndpoint(self.api_server, self.camera_id)
print(endpointData)

# ffmpeg
videoHost = endpointData["host"]
Expand All @@ -52,49 +52,53 @@ def __init__(self):
self.api_server, self.camera_id, self.stream_key
)

# ffmpegSettings = [
# "ffmpeg",
# "-f",
# "image2pipe",
# "-vcodec",
# "png",
# "-r",
# "25",
# "-i",
# "-", # Inject pil images here
# "-f",
# "mpegts",
# "-codec:v",
# "mpeg1video",
# "-b:v",
# "2500K",
# "-bf",
# "0",
# "-muxdelay",
# "0.001",
# f"http://{videoHost}:{videoPort}/{self.stream_key}/{self.streamWidth}/{self.streamHeight}/",
# ]

# # This is the ffmpeg pipe streamer!
# self.pipe = sp.Popen(ffmpegSettings, stdin=PIPE, stderr=STDOUT, stdout=DEVNULL)

self.ffmpeg = (
ffmpeg.input(
filename="pipe:",
format="rawvideo",
pixel_format="bgr24",
s="1080x720",
framerate=25,
)
.output(
f"http://{videoHost}:{videoPort}/{self.stream_key}/{self.streamWidth}/{self.streamHeight}/",
format="mpegts",
vcodec="mpeg1video",
)
.run_async(pipe_stdin=True)
ffmpegSettings = [
"ffmpeg",
"-f",
"image2pipe",
"-vcodec",
"png",
"-r",
"25",
"-i",
"-", # Inject pil images here
"-f",
"mpegts",
"-codec:v",
"mpeg1video",
"-b:v",
"2500K",
"-bf",
"0",
"-muxdelay",
"0.001",
f"http://{videoHost}:{videoPort}/{self.stream_key}/{self.streamWidth}/{self.streamHeight}/",
]

print(
f"http://{videoHost}:{videoPort}/{self.stream_key}/{self.streamWidth}/{self.streamHeight}/"
)

# This is the ffmpeg pipe streamer!
self.ffmpeg = sp.Popen(
ffmpegSettings, stdin=PIPE, stderr=STDOUT, stdout=DEVNULL
)

self.cam = cv.VideoCapture(0)
# self.ffmpeg = (
# ffmpeg.input(
# filename="pipe:",
# format="rawvideo",
# pixel_format="bgr24",
# s="1080x720",
# framerate=25,
# )
# .output(
# f"http://{videoHost}:{videoPort}/{self.stream_key}/{self.streamWidth}/{self.streamHeight}/",
# format="mpegts",
# vcodec="mpeg1video",
# )
# .run_async(pipe_stdin=True)
# )

# Graphics and resources
self.fontSize = 20 # This is easer than getting a tuple from ImageFont.getsize
Expand Down
62 changes: 62 additions & 0 deletions Houston-Streamer/resources/Buttons.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
[
{
"label": "Robot Controls",
"button_panels": [
{
"label": "SSTV Controls",
"buttons": [
{
"label": "BW (robot)",
"price": 0,
"command": "B"
},
{
"label": "Color (robot)",
"price": 10,
"command": "C"
}
]
},
{
"label": "Movement Controls (vote based)",
"buttons": [
{
"label": "Left",
"price": 0,
"command": "L",
"keycode": 37
},
{
"label": "Right",
"price": 0,
"command": "R",
"keycode": 39
},
{
"label": "Forward",
"price": 0,
"command": "F",
"keycode": 38
},
{
"label": "Back",
"price": 0,
"command": "B",
"keycode": 40
}
]
},
{
"label": "Misc",
"buttons": [
{
"label": "Version",
"price": 0,
"command": "V",
"keycode": 41
}
]
}
]
}
]
107 changes: 107 additions & 0 deletions Houston-UI/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/

# Pipenv
Pipfile*
28 changes: 9 additions & 19 deletions Houston-UI/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,27 +1,17 @@
FROM debian:latest
FROM python:3.10

# Setup home
ARG HOME="/app"
ENV HOME=${HOME}
LABEL maintainer="[email protected]"

# Set the working directory to app home
WORKDIR ${HOME}
COPY . /app

# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
WORKDIR /app

# Install deps
RUN apt update \
&& apt install -y postgresql gcc python3-dev musl-dev python3-pip gunicorn

# Python deps
RUN pip install --upgrade pip
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt

COPY . .
# Git commit
ARG GIT_COMMIT
ENV GIT_COMMIT=$GIT_COMMIT

EXPOSE 5000
EXPOSE 8080

ENTRYPOINT ./entrypoint.sh
ENTRYPOINT ["./entrypoint.sh"]
33 changes: 30 additions & 3 deletions Houston-UI/Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
test:
#export FLASK_APP="app/app.py" && flask run
flask --app app/app.py --debug run
.PHONY: help clean run build

# Help
help:
@echo " help - Prints this help."
@echo " clean - Shortcut for git clean -fdX"
@echo " build - Builds the required containers locally"
@echo " run - Build and run the app locally"
@echo " docker - Build and run the app using docker"

# For local development pipenv
run:
pipenv run flask --app MissionController/main.py --debug run

# For local development (docker)
docker: build
# docker-compose -f docker-compose.yml build && docker-compose -f docker-compose.yml up
docker-compose -f docker-compose.yml up

# Build container locally
build:
# Generate tag
echo TAG=$(shell git rev-parse --abbrev-ref HEAD | sed 's/[^a-zA-Z0-9]/-/g') > .env

# Build
docker-compose build --build-arg GIT_COMMIT=$(shell git describe --abbrev=8 --always --tags --dirty) --build-arg DEBUG=True


clean:
git clean -fdx
3 changes: 3 additions & 0 deletions Houston-UI/MissionController/consts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Some general consts, consider moving to YAML

MISSION_EPOCH = 1696118400
Loading

0 comments on commit 1435c0c

Please sign in to comment.