Parallel Processing Using Python for Faster Video Processing

Object Detection

Parallel Processing Using Python for Faster Video Processing

Sabina Pokhrel / April 9, 2020

How can we speed up video processing? Parallel processing is the answer!

If you want to process a number of video files, it might take from minutes to hours, depending on the size of the video, frame count, and frame dimensions.

If you are processing images in batches, you can utilize the power of parallel processing and speed up the task.

In this post, we will look at how to use Python for parallel processing of videos.

We will read video from the disk, perform face detection, and write the video with output of face detection (bounding boxes) back to the disk.

Let’s get started.

Install Dependencies

We will need the following packages:

OpenCV: is a computer vision library that is commonly used. In this post, we will use OpenCV to read and write video files.

To install OpenCV on your device, you can use either pip command or apt-get command.


FFmpeg: is a cross-platform solution to record, convert, and stream audio and video. In this post, we will use FFmpeg to join multiple video files.

To install FFmpeg, use the following apt-get command:

Import Python Libraries

Let’s import the required Python libraries.

Details of libraries used:

cv2: OpenCV library to read from and write to video files.

time: to get the current time for calculating code execution time.

subprocess: to start new processes, connect to their input/output/error pipes, and obtain their return codes.

multiprocessing: to parallelize the execution of a function across multiple input values, distributing the input data across processes

xailient: library for face detection

Video Processing Pipeline Using Single Process

We will first define a method to process video using a single process. This is the way we would normally read a video file, process each frame, and write the output frames back to the disk.

Let’s create another function that calls the video processor, takes note of start and end times, and calculates the time taken to execute the pipeline and the frames processed per second.

Video Processing Pipeline Using Parallel Processing

Now, let’s define another function for processing video that utilizes multiprocessing.

The way the above function works is that the video processing job, which is normally done using one process, is now divided equally amongst the total number of processors available on the executing device.

If there are four processors, and the total number of frames in the video to be processed is 1,000, then each processor gets 250 frames to process, and these are executed in parallel. This means that each process will create a separate output file, and so when the video processing is completed, there are four different output videos.

To combine these output videos, we will use FFmpeg.

Create a pipeline to run the multiprocessing of video and calculate time to execute and frames processed per second.

Single Processing Versus Parallel Processing

I ran this experiment on a Lenovo Yoga 920 with the Ubuntu18.04 operating system. The number of logical processors available on this device is eight.

From this experiment, we can observe 2x more frames being processed per second when using all cores to process the video, making parallel processing a far more efficient choice for your video processing needs.

Spread the love

About the Author

    Sabina is an AI Specialist and Machine Learning Engineer. She is a Writer and a former Editorial Associate at Towards Data Science.

Trusted by

Xailient’s commercial partners

Press releases

March 14, 2022

Xailient specializes in extremely efficient low-power computer vision. Intel's OpenVINO specializes in maximizing the performance and speed of computer vision AI workloads. OpenVINO improved Xailient FPS 9.5x on Intel hardware to 448 FPS. Together, Xailient-Intel outperforms the comparable MobileNet_SSD by 80x. Even after Intel worked the OpenVINO magic on MobileNet_SSD, Xailient-OpenVINO is 14x faster.

November 29, 2021

Xailient’s Face Recognition enables high-speed edge AI processing with low-power consumption using Sony’s IMX500 – a chip so small it can fit on the tip of your finger.

OnEdge Newsletter

A weekly newsletter with the best hand-picked resources about Edge AI and Computer Vision

OnEdge is a free weekly newsletter that keeps you ahead of the curve on low-powered Edge devices and computer vision AI.


You’ll get insights and resources into:

  • Edge computing use cases.
  • Market trends in Edge computing.
  • Computer Vision AI at the Edge.
  • Machine learning at the Edge.
Cookie Policy