To get a video ready for consumption on web and mobile devices, you will have to first upload the master video file on to the server. And then encode the file before delivery. This is a time-consuming process. In an industry where ‘Who gets the eyeball first?’ plays an important role in video becoming a success, saving every minute is paramount. The lesser time the process takes, the better.
Usually, the process of uploading and encoding are done in sequence. The time taken for this process can be reduced significantly by encoding video chunks even while the video upload is still in progress.
Things to remember when encoding video chunks
- This process is only suitable for large video uploads especially for files > 50 MB.
- The conversion component needs to be fixed (~10-20 seconds), irrespective of video size.
- We should encode the last chunk only after the video upload is completed.
Process for encoding
As you start uploading the video, follow the steps below.
- After the first chunk of 10MB is uploaded,
- Get video details – video bitrate & audio bitrate
- Calculate the number of seconds of video in the chunk of 10 MB
- Fix the time-slice for encoding based on the above calculation
- Calculate start-time and end-time for the subsequent chunk and slice-time
- Call ffmpeg for encoding with the partial uploaded video, start-time, end-time.
- If ‘encoding process’ runs into an error, abort the chunk encoding and fall back to full conversion
- If the ‘encoding process’ is successful,
- Mark the chunk as completed
- And append the converted video to the video_list
- In the last chunk, along with the above steps, call a new ffmpeg to concatenate all the chunk videos in the list. If this process runs into an error, abort the chunk encoding and fall back to full conversion.
What are your thoughts on this article? reach out to us at email@example.com if you would like to discuss!
Looking to launch your own streaming service?