├── .gitignore
├── LICENSE
├── README.md
├── fish.gif
├── infer.sh
└── source.m4
/.gitignore:
--------------------------------------------------------------------------------
1 | *.mp4
2 | *.mov
3 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 Roboflow
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # 🚨🚨🚨 REPO DEPRECATED 🚨🚨🚨
2 |
3 | * For Realtime Video (or webcam): use [Roboflow `inference`](https://inference.roboflow.com); docs for [realtime video streaming are available here](https://inference.roboflow.com/quickstart/run_model_on_rtsp_webcam/).
4 | * For Async/Recorded Video: Roboflow now provides a [new video inference API](https://blog.roboflow.com/roboflow-video-inference-api/), please visit [the Hosted Video Inference docs](https://docs.roboflow.com/deploy/video-inference) to learn more.
5 |
6 |
7 |
8 | # Roboflow Video Inference
9 | Example script to do inference on a video file with
10 | [Roboflow Infer](https://docs.roboflow.com/inference/hosted-api)
11 |
12 | 
13 |
14 | An example video (gif) generated with this utility script from a Roboflow model
15 | with the following command:
16 |
17 | ```
18 | ROBOFLOW_KEY=xxxxxxxx ./infer.sh rf-aquarium-merged/3 IMG_3203.mov fish.gif --fps_in 3 --fps_out 12 --scale 4
19 | ```
20 | ## Getting Started
21 |
22 | Colab Tutorial Here:
23 |
24 |
25 |
26 | ## Installation
27 |
28 | The shell script you need is [`infer.sh`](infer.sh) in this repo.
29 |
30 | To use it
31 | * copy that file to your local machine,
32 | * add execute permissions `chmod +x infer.sh`,
33 | * install the requirements (see below)
34 | * and then use it:
35 |
36 | ```
37 | # Simple usage with ROBOFLOW_KEY env var set inline
38 | ROBOFLOW_KEY=xxxxx ./infer.sh [YOUR_DATASET]/[YOUR_VERSION] video_in.mp4 video_out.mov
39 | ```
40 |
41 | To obtain your `ROBOFLOW_KEY`, go to
42 | [your account settings page](https://app.roboflow.com/account/api) and copy
43 | your `API Key` (*not* your `Publishable Key`). Treat this API Key like a password;
44 | it gives access to your Roboflow account and is meant to remain a secret.
45 |
46 | The model ID (`[YOUR_DATASET]/[YOUR_VERSION]` in the command above) is obtained from the Roboflow
47 | UI after training. Click "Example Web App" in the "Use Your Trained Model" section
48 | and copy it from the pre-filled text field at the top of the page.
49 |
50 | ## Requirements
51 |
52 | The script's main requirements are [`ffmpeg`](https://www.ffmpeg.org/),
53 | `base64`, and `curl`. On most modern Unix-like operating systems, you will only
54 | need to install `ffmpeg` because the other requirements are preinstalled.
55 |
56 | ### macOS
57 |
58 | Already includes `base64` and `curl`.
59 |
60 | Use [`homebrew`](https://brew.sh/) to install ffmpeg: `brew install ffmpeg`
61 |
62 | ### Ubuntu
63 |
64 | Already includes `base64` and `curl`.
65 |
66 | Use `apt` to install ffmpeg: `sudo apt install ffmpeg`
67 |
68 | ### Windows
69 |
70 | Download `ffmpeg` from [their website](https://www.ffmpeg.org/download.html) and
71 | install [`git` for Windows](https://git-scm.com/downloads) which conveniently
72 | includes `base64` and `curl`.
73 |
74 | ## Options
75 |
76 | A `ROBOFLOW_KEY` environment variable with
77 | [your Roboflow API Key](https://app.roboflow.com/account/api)
78 | is required.
79 |
80 | The [`infer.sh`](infer.sh) script accepts the following parameters:
81 |
82 | | Parameter | Example | Description
83 | | --- | --- | ---
84 | | `--host` | `--host "http://localhost:9001"` | The Roboflow Infer host; set for [On-Device Inference](https://docs.roboflow.com/inference/nvidia-jetson) (default: `https://infer.roboflow.com`).
85 | | `--confidence` | `--confidence 50` | The minimum threshold for the model to output box predictions (default: `50`).
86 | | `--overlap` | `--overlap 50` | The maximum amount two predicted boxes of the same class can intersect before being combined (default: `50`).
87 | | `--stroke` | `--stroke 5` | The thickness of the predicted bounding boxes (default: `5`).
88 | | `--labels` | `--labels` | Enable printing the class names (implicit default: off)
89 | | `--classes` | `--classes car` | A comma separated (no whitespace) list of classes to predict (default: show all).
90 | | `--fps_in` | `--fps_in 6` | The sample rate from the input video in frames per second (default: 6).
91 | | `--fps_out` | `--fps_out 24` | The render speed; setting higher than `fps_in` gives a timelapse effect (default: 24).
92 | | `--scale` | `--scale 2` | The amount to shrink the video; eg 2 to make video_out width and height 2x smaller than video_in (default: 1).
93 | | `--tmp` | `--tmp .` | The `tmp` directory; must be writable (default: `/tmp`).
94 | | `--retries` | `--retries 3` | The number of times to retry a failed inference (default: `3`).
95 | | `--parallel` | `--parallel 8` | The number of concurrent frames to send to the model (default: `8`).
96 | | model | `xx-mymodel--1` | The Roboflow model to use for inference (required).
97 | | video_in | `video_in.mp4` | The input video file (required).
98 | | video_out | `video_out.mp4` | The output video file (required). Can be of any format supported by `ffmpeg`'s encoder (eg `.mov`, `.mp4`, `.gif`).
99 |
100 | ## Building
101 |
102 | [The infer script](infer.sh) is built with [`argbash`](https://argbash.io)
103 | (a code generator that adds smart parameter parsing for bash scripts)
104 | from [`source.m4`](source.m4).
105 |
106 | To build, clone this repo, [install `argbash`](https://argbash.readthedocs.io/en/stable/install.html),
107 | then run the following in the repo's top-level directory:
108 |
109 | ```
110 | argbash source.m4 -o infer.sh
111 | ```
112 |
113 | You can then use your newly generated [`infer.sh`](infer.sh) as described above.
114 |
115 | ## License
116 |
117 | This example repo is released under an MIT License. You will need to train a model
118 | with [Roboflow Train](https://docs.roboflow.com/train) which is goverened by
119 | the [Roboflow Terms of Service](https://roboflow.com/terms).
120 |
121 |
122 | **_Note: Update from November 2023 - Roboflow now provides a [new video inference API](https://blog.roboflow.com/roboflow-video-inference-api/), please visit this link to learn more. This repository is archived._
123 | **
124 |
--------------------------------------------------------------------------------
/fish.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/roboflow/video-inference/898da8e34ee6f0fa7c0d9a0251c90453d0ae5837/fish.gif
--------------------------------------------------------------------------------
/infer.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | ##################################################
4 | # Roboflow Video Inference Example #
5 | # Bash script released under MIT License #
6 | # Copyright (c) 2021 Roboflow Inc #
7 | # #
8 | # https://github.com/roboflow-ai/video-inference #
9 | ##################################################
10 |
11 | # Created by argbash-init v2.10.0
12 | # ARG_OPTIONAL_SINGLE([host],[],[The Roboflow Infer host; set for On-Device Inference],["https://infer.roboflow.com"])
13 | # ARG_OPTIONAL_SINGLE([confidence],[c],[The minimum threshold for the model to output box predictions.],[50])
14 | # ARG_OPTIONAL_SINGLE([overlap],[o],[The maximum amount two predicted boxes of the same class can intersect before being combined.],[50])
15 | # ARG_OPTIONAL_SINGLE([stroke],[s],[The thickness of the predicted bounding boxes.],[5])
16 | # ARG_OPTIONAL_BOOLEAN([labels],[l],[Print the class names])
17 | # ARG_OPTIONAL_SINGLE([fps_in],[],[The sample rate from the input video (in frames per second).],[6])
18 | # ARG_OPTIONAL_SINGLE([fps_out],[],[The render rate (setting higher than fps_in will give a timelapse effect).],[24])
19 | # ARG_OPTIONAL_SINGLE([scale],[],[The amount to shrink the video; eg 2 to make video_out width and height 2x smaller than video_in.],[1])
20 | # ARG_OPTIONAL_SINGLE([tmp],[t],[The tmp directory; must be writable.],["/tmp"])
21 | # ARG_OPTIONAL_SINGLE([retries],[r],[The number of times to retry a failed inference.],[3])
22 | # ARG_OPTIONAL_SINGLE([parallel],[p],[The number of concurrent frames to send to the model.],[8])
23 | # ARG_OPTIONAL_SINGLE([classes],[f],[The classes to show, separated by a comma (no spaces).],[])
24 | # ARG_OPTIONAL_BOOLEAN([verbose],[v],[Print debugging information.])
25 | # ARG_POSITIONAL_SINGLE([model],[The Roboflow model to use for inference (required).])
26 | # ARG_POSITIONAL_SINGLE([video_in],[The input video file (required).])
27 | # ARG_POSITIONAL_SINGLE([video_out],[The output video file (required).])
28 | # ARG_DEFAULTS_POS()
29 | # ARG_HELP([