DEV Community

Nikolas
Nikolas

Posted on

Compressing videos with jobs

Hey everyone,

How do you compress video files for faster uploads, sharing, or saving on storage space. Depending on your use case, there are different ways to go about this: You might need something quick and simple/dirty, or you might be looking for a more scalable solution (that handles large files or batches of videos in the background).

Here are a few scenarios where you might need video compression:

Possible Use cases:

*Quick video compression for one-off uploads or sharing. You might just need to reduce a file size before sending it to a platform like YouTube or Instagram.

*Efficient handling of multiple videos at once, without blocking other processes in your app. Think about batch uploads where you don’t want users to wait for each video to compress.

*Handling larger video files that might be too heavy for on-the-fly compression, especially when you're dealing with a lot of data.
Optimizing for storage and bandwidth, especially for streaming platforms, where you need to reduce file sizes to minimize load times and bandwidth costs.

Any other use cases that I missed?

Here are two approaches:

  1. Compress Video API (Quick & Simple) This one is pretty straightforward. You send a video file (or even a URL from YouTube, Dailymotion, etc.), and the API compresses it for you. It’s a normal API, meaning it’s a synchronous process: send in the video, wait for it to finish compressing, then get your result.

When to use it:

  • You need fast, on-the-fly compression for a few videos.
  • You’re working with smaller files and don’t mind waiting for compression to finish before moving on.

It’s best for those who need to compress videos for quick uploads or easier sharing online.

  1. Job-Based Video Compression API (Asynchronous, Batch-Friendly)

If you’ve got a lot of videos to compress or you need to handle large files without blocking other tasks, the Job-Based API is where things get interesting. In this case, you submit a job, and the API will process it in the background.

You don’t have to wait around – it’s all queued up, and you can get back to other things while it works its magic.

When to use it:

  • High volume or larger files that would take too long to process synchronously.
  • If you’ve got a batch of videos and want to queue them up for processing without slowing down your workflow.

I tend to think that this is better for platforms that need to handle video uploads in the background (think media sites or streaming platforms with lots of content to compress).

For example, let’s say you run a platform that lets users upload videos, and you need to compress all of them before streaming.

Instead of blocking your users while each video gets processed, you queue the jobs and let them complete in the background, keeping everything running.

So, which one is best?

  • If you’re just looking for quick compression for a handful of videos, the Compress Video API is probably the better fit.
  • But, if you’re handling larger-scale compression or need to process videos asynchronously (like batch uploads or background tasks), the Job-Based Video Compression API is going to make your life a lot easier.

Both APIs are available on ApyHub, and you can play around with them + I Would love to hear how you’re handling video compression in your projects or what tools you’re using.

API: https://apyhub.com/utility/compress-video
Job API: https://apyhub.com/utility/job-compress-video

Anyone using video compression in a different way or have some cool use cases to share?

Cheers!

Nikolas

Top comments (0)