Skip to main content

Processing Video Files

Stream can be used to programmatically process video files. The time required to process a video file depends on the machine's CPU Passmark score. See our benchmarks.

Process a Single Video

To run Stream on a video file (e.g. mp4), specify the video filename.

  1. Make sure that the video file is stored within the Stream folder.
  2. For example, with the Stream directory c:\stream and the file c:\stream\Videos\my_video.mp4
  3. Edit url parameter in configurations file:
    url = /user-data/Videos/my_video.mp4
  4. After editing, start or restart the container
danger
  • If the configurations file is edited, the container needs to be restarted.
  • You can process a limited number of hours per month. View your current usage in the video column.

File Upload API

If you need to check a variety of video files, so that you don't have to restart the container, you can use the stream as webservice.

  1. Edit the camera url in your config.ini file and set:
    url = file-upload
  2. Run the container with -p 8081:80. For example:
docker run --restart="unless-stopped" -t --name stream \
-p 8081:80 \
-v c:\users\kyt\documents\stream:/user-data -e LICENSE_KEY=XXXXX -e TOKEN=YYYYY \
platerecognizer/alpr-stream
  1. Upload the video. Here's an example using CURL (not using curl? try this).
curl -F "upload=@/path/to/car.avi" http://localhost:8081
  1. Calling the file upload API will not return the prediction results. Those are available in your outputs configured in your config.ini. The JSON response from the call contains information about usage and indicates whether the file processing was successful.

For a Python example, see this File Upload script.

Parameters

The Upload API accepts optional parameters with the video upload, allowing modifications to the configurations for the video being uploaded without requiring a restart.

The API supports a wide array of parameters that can be adjusted during video upload, including:

  • mask_id
  • video_fps
  • max_reconnection_delay
  • sample
  • memory_decay
  • max_prediction_delay
  • detection_rule
  • regions
  • region_config
  • merge_buffer
  • user_data

Examples

You can adjust these parameters by simply giving values to the parameters you want to adjust in your request (the only exception to this is user_data). Here is how you can adjust configurations upon upload using curl:

  • To adjust the sample rate for a video, simply append your curl command with a sample form field like this: curl -F "upload=@/path/to/car.avi" -F "sample=3" http://localhost:8081
  • And, for list-type parameters like regions, indicate multiple values by repeating the parameter name: curl -F "upload=@/path/to/car.avi" -F "regions=us" -F "regions=eu" http://localhost:8081
  • To modify multiple parameters in a single request, simply include all the desired parameters in your curl command: curl -F "upload=@/path/to/car.avi" -F "sample=3" -F "regions=us" -F "regions=eu" http://localhost:8081

mask_id

The mask_id parameter is used to override the detection zone mask. By default, Stream uses a detection zone named camera_id. But if mask_id is given, Stream looks for a detection zone named camera_id. For more information on detection zones and how to create them, see the Detection Zones documentation.

  • Here's an example, in config.ini I have a camera-1 with url = file-upload. By default, the detection zone camera-1 will be used. If I want to use camera-2 instead, I do: curl -F "upload=@/path/to/car.avi" -F mask_id=camera-2 http://localhost:8081

user_data

To update user_data, rather than passing user_data as a parameter, you should use the id and data parameters in your command. Here, id represents the camera ID, and data contains the new user data. For example, if your camera ID is camera-2 and you wish to update the user data to your-new-user-data, the curl command would be structured as follows: curl -F "id=camera-2" -F "data=your-new-user-data" http://localhost:8081

For detailed information on parameter types and default values, consult the Configuration documentations.

caution

These additional parameters will only affect the video upload they are given with. The only exception to this is user_data. Changes in user_data will also effect subsequent video uploads. You can update user_data at any time, even outside of video uploads, as described in the in Sending Additional Information.

Note that none of these configuration modifications will change your config.ini file.

What is the meaning of "Connection reset by peer"?

This error happens when Stream is not able to communicate a response to the client (the program uploading the video). This can happen if the client crashed or was stopped while uploading or waiting for a response. It is an indication that some of the data sent may not have been received. Check if the client is using a timeout.

Process an Entire Folder of Videos

The API above can be used to process all the videos in a folder. This Python script takes as input a folder and processes all the files in it. Windows users can also use this executable.

 python -f /path/to/folder -s http://localhost:8081
Floating button icon
CTRL + .