Skip to content

Instantly share code, notes, and snippets.

@ndgnuh
Created April 26, 2023 07:43
Show Gist options
  • Save ndgnuh/e251b842fb98b242f2d63d37dfed19e0 to your computer and use it in GitHub Desktop.
Save ndgnuh/e251b842fb98b242f2d63d37dfed19e0 to your computer and use it in GitHub Desktop.
from argparse import ArgumentParser
from subprocess import Popen
# docker run -p 9993:80 -v ./:/usr/share/nginx/html/ nginx:stable-alpine3.17-slim
# docker run -v ./:/tmp jrottenberg/ffmpeg:snapshot-alpine -i "rtsp://..." -c copy -hls_time 2 -hls_wrap 10 "/tmp/stream.m3u8"
def main():
parser = ArgumentParser()
parser.add_argument("--port", "-p", type=int)
parser.add_argument("--rtsp", "-i", required=True)
parser.add_argument("--name", "-o", default="stream", help="Streaming slug, eg. 'stream' => 'http://localhost/stream.m3u8'")
args = parser.parse_args()
nginx = Popen(["docker", "run", "-p", f"{args.port}:80", "-v", "./:/usr/share/nginx/html/", "nginx:stable-alpine3.17-slim"])
ffmpeg = Popen(["docker", "run", "-v","./:/tmp",
"jrottenberg/ffmpeg:snapshot-alpine",
"-i", args.rtsp, "-c", "copy", "-hls_time", "2", "-hls_wrap", "10",
f"/tmp/{args.name}.m3u8"])
nginx.wait()
ffmpeg.wait()
try:
nginx.kill()
ffmpeg.kill()
except Exception:
pass
if __name__ == "__main__":
main()
<head>
<link href="https://vjs.zencdn.net/8.3.0/video-js.css" rel="stylesheet" />
</head>
<body>
<video
id="my-video"
class="video-js"
preload="auto"
width="1280"
height="960"
data-setup="{}"
muted
autoplay
>
<source src="http://localhost:9993/stream.m3u8" type="application/x-mpegURL" />
<p class="vjs-no-js">
To view this video please enable JavaScript, and consider upgrading to a
web browser that
<a href="https://videojs.com/html5-video-support/" target="_blank"
>supports HTML5 video</a
>
</p>
</video>
<script src="https://vjs.zencdn.net/8.3.0/video.min.js"></script>
<script src="https://unpkg.com/browse/@videojs/[email protected]/dist/videojs-http-streaming.min.js></script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment