Reducing Instagram’s native video processing time by 94 percent | Tech Reddy


  • In our goal to focus on efficiency, Instagram’s engineers have developed a way to process new videos that reduces the cost of producing original video encoding by 94 percent.
  • In this way, Meta’s video infrastructure can be scaled continuously without the need to add more machines.
  • Advanced encodings free up resources for more people to watch, providing clearer video and better playback. This is especially beneficial for people in countries with slow internet connections.

The increase in the Instagram user base of more than 2 billion active users per month requires us to get the best performance from our traffic of users. At the beginning of 2021, we ran the indicators that show that in 12 months we will not have enough to provide video transmission for everyone. But in our never-ending quest to ensure efficiency, we found a way to handle this growing demand and expand our infrastructure by doing more with the machines we have us.

Instagram creates a variety of posted videos, each of which has a different personality. By repurposing one type of video codec to help render another, we reduced the computing resources we spend on low-view video codecs by 94 percent. With more resources available, we can produce more advanced encoding – allowing more people to see clearer video and play it more easily.

Where does Instagram spend video analytics?

We create two types of video encoding for every video we post on Instagram:

  1. Coding small functionality compatible with all Instagram clients. Their smaller addition makes it easier for older devices to unpack and play.
  2. Advanced coding use the latest enhancement technologies for higher quality playback. In the example below, the close-ups of the two video frames show that we can provide sharper information with fewer bits (note the brightness of the video on the side right compared to that on the left).

The problem was that we spent more than 80 percent of our resources processing low-performance code. If we continue on that path, at the very least we will have enough of our resources within a year. As a result, videos may take longer to render – or not render at all. Only 15 percent of the total watch time was covered by our advanced encoders, and we thought that spending all our computers on low-performance components would not be able to provide the video encoder watch time. advanced.

Taking on heavy workloads

Instagram creates two classes of low performance codes. For each video, we generate adaptive bit rate (ABR) encoding — our most commonly viewed sub-process. For continuous playback, customers can choose the version that suits their connection speed so that it does not stop due to changes in bandwidth – a so-called method. adaptive bit flow.

We rarely offer progressive encoding, another kind of small work, but we still do it to maintain compatibility with older versions of the Instagram app that don’t support ABR playback.

In the past, we generated ABRs and progressive encoders from the original file sent by the client to our backend. But this process hogs resources: As the following command shows, it takes 86.17 seconds of CPU time to convert a 23-second video to 720p.

$ time ffmpeg -i input.mp4 -vf scale=-1:720 -c:v libx264 output.mp4
86.17s user 1.32s system 964% cpu 9.069 total

We noticed that the two sets of encoders have the same settings. They used the same codec with only minor differences in the encoding profile and preset. Then it dawned on us: We can do it replace our original ABR codecs with video frames of progressive codecs by recompiling them into the ABR file structure.. This eliminates the cost of generating our original ABR encoder. The following command times show that it takes only 0.36 seconds to render the display file and compress the video frames into an ABR file structure for a single input video.

$ time MP4Box -add input.mp4 -dash 2000 -profile dashavc264:onDemand -out manifest.mpd 
0.36s user 2.22s system 95% cpu 2.690 total

This approach frees up the account for advanced encoding, although it comes at the expense of the compression efficiency of our original ABR encoding. Our theory is that publishing a lot of advanced coding will be very useful for people who use Instagram.

Instagram video statistics

Creating a framework to test our theory

We need to test our concept before we send it to print. If we compare the original ABR codes before and after our changes, we can only see the reductions. We also need to measure the net effect from more advanced encodings. The diagram below shows the higher latency we expected for the advanced encoders after the software was freed from our original ABR. This improves the compression efficiency of the new original ABR.

Instagram video statistics

To measure this, we created a test framework that replicates a subset of traffic across a test pool and a control pool of equal processing power. We saved the encodings from each source in different namespaces so that we could identify them later as part of the control or test list of videos. So, at the time of posting, people will see the codes from one catalog or the other. This allows us to measure whether the new coding scheme is better.

Instagram video statistics

From this test, we proved that although we are reducing the input power of the basic ABR encoders in the test pool, the higher viewing time for the advanced encoders is more than done.

The push to publish

After launching this optimization, we saw significant gains in savings and higher coding latency. Our new coding scheme reduced the cost of producing our original ABR coding by 94 percent. With more resources available, we were able to increase the overall watch time of the advanced encoders by 33 percent. This means that today more people on Instagram will see clearer videos that play better. This is very important to provide a good experience to people in countries with slow internet connections.

A lot of technical work is needed, because the demand of Instagram will increase on our traffic of users. Keep it up!

Over the years, Instagram has constantly worked to improve its product offerings. Given our scale – with up to 2 billion monthly active users on our platform and more than 140 billion unique videos played across Instagram and Facebook every day – we can make huge profits. our work. If this sounds good to you, join in!

Thank you

Thanks to Haixia Shi for introducing the idea for this nice optimization. Thanks to Richard Shyong for implementing the optimization and testing framework, which allows us to measure all the best investments. Thanks to Runshen Zhu and Ang Li for discussions that led to investment in this section. We would like to thank our colleagues Atasay Gokkaya, Justin Li, Chia-I Wei, and Zainab Zahid for help in testing the pool provisioning and discussions about the software efficiency.


Source link