How to Upload Large Videos Across the Web

how_to_upload_large_video

There has been an unprecedented growth in file sizes over the years, and as larger resolutions become more common, video file sizes are increasing, too. This growing demand makes it crucial to optimize the upload process, especially when dealing with bandwidth limitations, file size restrictions, and many more to ensure smooth user experiences.

In this article, we’ll review how to upload large videos efficiently. Whether you’re building a video-heavy application or enhancing an existing platform, these tips will help you optimize performance and streamline the upload process for your users.

In this article:

Why Are Video Files So Large?

There are many different factors that contribute to the size of a video file, with bitrate being one of the most important. Bitrate refers to the amount of data processed per second of video, where higher bitrates result in better video quality but also larger file sizes.

The codecs used also significantly affect how video files are compressed and unpacked. Compression algorithms like H.264 or H.265 can compress video files to reduce their size without sacrificing much quality, but the efficiency of these codecs varies.

Additionally, the duration of the video has a direct impact—longer videos naturally have more data, leading to larger files. Frame rate (measured in frames per second, or FPS) is another determining factor; higher frame rates (like 60 FPS) provide smoother playback but also increase the file size due to the additional frames being captured and processed.

Finally, the quality of the audio stream in the video can add to the overall file size, especially if the audio is high fidelity. Higher resolution videos, such as those in 4K, contain far more pixels than standard 1080p or 720p videos, which translates to larger file sizes. The more pixels in a video, the more data is required to represent each frame, increasing the file size exponentially as the resolution increases.

Different Ways to Upload Large Videos

There are several ways of uploading large videos across the web. Below, we’ll go over some effective ways on how to upload large videos with Cloudinary.

Uploading Videos to Cloud Storage

One of the most efficient ways to upload large video files is using a cloud-based platform like Cloudinary. Cloudinary offers an API-driven approach to managing media assets, including easily handling large video files. It supports chunked uploads, which allows large files to be uploaded in smaller, manageable chunks, reducing the risk of timeouts or interruptions in the upload process.

The chunked upload process divides the video file into smaller parts, which are then uploaded sequentially. This approach is beneficial for uploading large video files because it reduces the risk of failure and improves overall performance. If a network interruption occurs during the upload process, only the interrupted chunk must be re-uploaded rather than the entire file.

Let’s look at how we can programmatically upload large video files to the Cloudinary Cloud. We will begin by writing a sample code that allows us to upload files to the Cloudinary cloud:

const cloudinary = require('cloudinary').v2;
// Configure Cloudinary with your credentials
cloudinary.config({
  cloud_name: 'your_cloud_cloud_name',
  api_key: 'your_api_key',
  api_secret: 'your_api_secret'
});
cloudinary.v2.uploader.upload("elephants_4k.mp4").then(result=>console.log(result));

Here, we are simply setting up our Cloudinary API using our Cloudinary credentials and uploading a video file elephants_4k.mp4 using Cloudinary’s upload() method.

how_to_upload_large_video

Cloudinary’s upload() method can upload files up to 100MB in size. However, for file sizes larger than 100MB, and based on your plan, you’ll need to use the upload_large() method. As mentioned before, this method uploads large files to the cloud in chunks, so it is often relevant for video files, as they tend to have larger file sizes.

By default, the upload_large() method uploads files as raw files if the resource_type parameter is not specified. So you will need to define the resource_type as "video":

cloudinary.v2.uploader.upload_large("elephants_4k.mp4", 
   { resource_type: "video" }, 
  function(error, result) {console.log(result, error); });

If you want to upload files in different chunk sizes, you can use the chunk_size parameter in upload_large() method. The method is, by default, set to 20 MB but can be set to as low as 5 MB. For example, we can upload our file with a chunk size of 7 MB by setting the parameter as:

cloudinary.v2.uploader.upload_large("elephants_4k.mp4", 
   { resource_type: "video" , 
    chunk_size: 7000000 }, 
  function(error, result) {console.log(result, error); });

Using Third-Party Software

If you prefer not to directly handle the upload process or want to provide flexibility for users to upload videos from various sources, Cloudinary’s upload widget offers seamless integration with third-party services. To integrate third-party services, simply start by defining the Cloudinary upload widget in your web app:

<script src="https://upload-widget.cloudinary.com/latest/global/all.js" type="text/javascript"></script>  

<script type="text/javascript">  
var myWidget = cloudinary.createUploadWidget({
  cloudName: 'my_cloud_name',
  uploadPreset: 'my_preset'}, (error, result) => {
    if (!error && result && result.event === "success") {
      console.log('Done! Here is the image info: ', result.info);
    }
  }
)

document.getElementById("upload_widget").addEventListener("click", function(){
    myWidget.open();
  }, false);
</script>

After defining your Cloudinary upload widget, you can define a sources parameter like:

cloudinary.openUploadWidget({
  cloudName: "your_cloud_name", uploadPreset: "your_upload_preset",
  sources: [ 'local', 'url', 'image_search'],
  googleApiKey: 'AIrFcR8hKiRo' }, (error, result) => { });

This is useful for applications where users store their videos across different platforms. In addition to common sources such as “My Files,” “Web Address,” and “Camera,” the widget supports a wide range of third-party services like Dropbox, Shutterstock, Getty Images, and many more. These upload sources are presented in multiple tabs for desktop users or as selectable options for mobile users:

how_to_upload_large_video

This allows your users to upload videos from a range of sources directly into your application without having to download them locally first. For more details on how to configure these third-party upload sources, refer to Cloudinary’s documentation.

Using Compression To Make Smaller Files

Video compression is one of the most effective ways to reduce file size without sacrificing quality when handling large video files. Cloudinary makes this process easy by offering automatic formatting and compression through its powerful API. By applying certain parameters, you can significantly reduce file sizes while maintaining video quality for end users.

Cloudinary’s auto format and quality features allow for automatic optimization. The auto parameter dynamically selects the most appropriate format and compression level based on the user’s device, browser, and connection speed. This ensures that your videos are delivered quickly and efficiently without requiring manual intervention.

Here’s an example of how you can use Cloudinary to apply automatic formatting and compression:

https://res.cloudinary.com/demo/video/upload/f_auto,q_auto/elephants.mp4

Here, the f_auto parameter automatically selects the best format (e.g., MP4, WebM) depending on the user’s browser capabilities, while the q_auto automatically adjusts the quality for optimal balance between file size and visual fidelity.

For further compression control, you can specify a particular quality level using the q parameter. For instance, q_70 would deliver a video at 70% quality, further reducing the file size.

Lowering Video Resolutions Without Sacrificing Quality

In addition to compression, reducing the resolution of videos is another effective way to manage file size. Cloudinary allows developers to adjust the resolution dynamically while maintaining the visual quality of the content. By using the w (width) and h (height) parameters, you can resize videos without distorting or significantly degrading quality.

Cloudinary also offers a q_auto parameter to automatically determine the appropriate quality based on the content, ensuring that the video remains crisp even at lower resolutions, for instance:

https://res.cloudinary.com/demo/video/upload/w_720,h_480,q_auto/elephants.mp4

In this example, we are using the w_720 and h_480 parameters to resize the video to 720×480 pixels. We are also pairing it with the q_auto parameter to automatically optimize the quality based on the resolution and content.

By combining resolution adjustments and compression techniques, you can effectively reduce file size without compromising the viewing experience. This is particularly useful for delivering videos to users with limited bandwidth or on mobile devices.

how_to_upload_large_video

The Fastest Method for Video File Upload

When it comes to uploading large video files quickly and efficiently, using the right tools is key. Cloudinary is a powerful solution that not only simplifies video uploads but also optimizes them for fast delivery. With features like automatic file compression, adaptive bitrate streaming, and seamless cloud storage integration, Cloudinary helps developers handle video uploads effortlessly while ensuring high-quality playback across devices.

For developers looking to streamline video file uploads and enhance user experience, Cloudinary is a holistic solution that handles everything from upload to delivery. So, sign up to start uploading your large files to Cloudinary today!

FAQs About Uploading Large Video Files

How can I reduce the size of a video before uploading?

You can reduce the size of a video by compressing it with a tool or software that uses efficient codecs like H.264 or H.265, lowering the resolution, or trimming unnecessary parts.

What is the best format for uploading large video files?

MP4 is widely regarded as the best format for uploading large video files due to its compatibility, efficient compression, and ability to maintain high video quality.

How can I ensure I don’t lose video quality when uploading?

To avoid losing quality, use a high-efficiency codec, avoid over-compressing, and choose a platform that supports adaptive bitrate streaming, which preserves quality across different network conditions.

More from Cloudinary:

Embedding a Video Player in Next.js With Next Cloudinary

How to Upload a Video to Cloudinary in Next.js App Router

QUICK TIPS
Matthew Noyes
Cloudinary Logo Matthew Noyes

In my experience, here are tips that can help you better handle the upload and management of large video files across the web:

  1. Use adaptive bitrate streaming for smooth playback
    Implement adaptive bitrate streaming protocols like HLS (HTTP Live Streaming) or DASH (Dynamic Adaptive Streaming over HTTP). This technique breaks the video into chunks at multiple bitrates, allowing the client to select the appropriate quality dynamically based on the user’s network conditions. This results in a more fluid playback experience, even if network speeds vary.
  2. Leverage multi-threaded or parallel uploads for faster transfers
    If using a platform like Cloudinary or S3, explore multi-threaded uploading to split the file into smaller parts and upload multiple chunks simultaneously. Libraries like tus.io or AWS’s multipart upload offer similar functionality, which can significantly reduce upload times, especially for very large files.
  3. Enable resumable uploads to handle interruptions gracefully
    Implement resumable uploads using protocols like the tus protocol or similar implementations that support partial uploads. This ensures that in the event of a network failure, the upload can continue from where it left off rather than restarting, saving time and bandwidth.
  4. Consider server-side direct uploads for improved reliability
    Use a server-side upload strategy to send video files directly from the client to your cloud storage provider, bypassing your server. This reduces server load, minimizes security risks, and improves performance. With services like Cloudinary, you can set up a direct upload using their upload widget, reducing your infrastructure’s involvement.
  5. Use a Content Delivery Network (CDN) to speed up video delivery
    After uploading, distribute your video using a global CDN like Cloudflare or the one provided by Cloudinary. This ensures videos are served from the closest server to the user, reducing latency and improving the overall experience, especially for global audiences.
  6. Implement chunked uploads with custom chunk sizes
    Adjust chunk sizes based on your network environment and expected file size. For slower connections, smaller chunks (e.g., 5MB) reduce the risk of timeouts. For faster connections, larger chunks (e.g., 20MB) reduce the number of requests needed, making the upload faster and more efficient.
  7. Use advanced compression techniques and codecs
    Modern codecs like H.265 (HEVC) and AV1 offer much better compression rates compared to older formats like H.264. Use tools like FFmpeg to transcode your videos to newer codecs before uploading. This not only reduces file size but also maintains higher quality.
  8. Apply dynamic video optimization for different devices
    Tailor the video’s resolution and quality based on the device and viewing conditions. Automatically downscale videos for mobile devices using services like Cloudinary, which supports dynamic transformations based on screen size and network speed, ensuring the best balance of quality and performance.
  9. Create automated workflows for uploading, transcoding, and distribution
    Set up automated pipelines that handle uploading, processing, and distribution using tools like AWS Lambda, Cloudinary’s webhooks, or Google Cloud Functions. This allows you to trigger transcoding, thumbnail generation, and video optimization tasks immediately after upload, reducing manual intervention.
  10. Use file integrity checks to validate uploads
    Implement checksum verification (e.g., using SHA-256) to ensure that the uploaded file is intact and hasn’t been corrupted during the upload process. This is especially important for large video files, as any corruption could lead to playback issues or additional processing time.

By following these tips, you can streamline your large video file upload process, reduce errors, and deliver a smoother experience for your users. Leveraging advanced features like adaptive streaming and dynamic transformations, especially through platforms like Cloudinary, can significantly improve video quality and performance across different network conditions and devices.

Last updated: Oct 3, 2024