{"id":647,"date":"2022-11-04T13:00:15","date_gmt":"2022-11-04T13:00:15","guid":{"rendered":"https:\/\/fde.cat\/index.php\/2022\/11\/04\/reducing-instagrams-basic-video-compute-time-by-94-percent\/"},"modified":"2022-11-04T13:00:15","modified_gmt":"2022-11-04T13:00:15","slug":"reducing-instagrams-basic-video-compute-time-by-94-percent","status":"publish","type":"post","link":"https:\/\/fde.cat\/index.php\/2022\/11\/04\/reducing-instagrams-basic-video-compute-time-by-94-percent\/","title":{"rendered":"Reducing Instagram\u2019s basic video compute time by 94 percent"},"content":{"rendered":"<p><span>In our constant quest to <a href=\"https:\/\/engineering.fb.com\/2019\/03\/14\/data-center-engineering\/accelerating-infrastructure\/\" target=\"_blank\" rel=\"noopener\">prioritize efficiency<\/a>, Instagram\u2019s engineers have developed a way to process new videos that reduces the cost to produce basic video encodings by 94 percent.<\/span><br \/>\n<span>With this method in place, <a href=\"https:\/\/engineering.fb.com\/2021\/04\/05\/video-engineering\/how-facebook-encodes-your-videos\/\" target=\"_blank\" rel=\"noopener\">Meta\u2019s video infrastructure<\/a> can continue to scale without needing to add more machines.<\/span><br \/>\n<span>This frees up resources so more people can watch advanced encodings, which provide clearer video that plays more smoothly. This is especially beneficial for people in countries that have slower internet connections.<\/span><\/p>\n<p><span>Instagram\u2019s growing user base of more than 2 billion monthly active users requires us to get the best possible performance from our fleet of servers. In early 2021, we ran projections that showed that within 12 months we would not have enough capacity to provide video uploads for everyone. But in our never-ending quest to prioritize efficiency, we uncovered a way to handle this increasing demand and <a href=\"https:\/\/engineering.fb.com\/2022\/09\/06\/data-center-engineering\/viewing-the-world-as-a-computer-global-capacity-management\/\" target=\"_blank\" rel=\"noopener\">scale our infrastructure<\/a> by doing more with the machines we already have.\u00a0<\/span><\/p>\n<p><span>Instagram creates multiple encoded versions of uploaded videos, each with different characteristics. By repurposing one type of video encoding to help generate another type, we reduced the compute resources we spend on less-watched video encodings by 94 percent. With more resources available, we can produce more advanced encodings \u2014 allowing more people to experience clearer video with smoother playback.<\/span><\/p>\n<h2><span>Where Instagram spends video compute<\/span><\/h2>\n<p><span>We generate two types of video encoding for each video uploaded to Instagram:<\/span><\/p>\n<p>Minimum functionality encodings<span> are compatible with all Instagram clients. Their lower-efficiency compression is easier for older devices to decode and play.<\/span><br \/>\nAdvanced encodings<span> use <a href=\"https:\/\/engineering.fb.com\/2018\/04\/10\/video-engineering\/av1-beats-x264-and-libvpx-vp9-in-practical-use-case\/\" target=\"_blank\" rel=\"noopener\">newer compression technologies<\/a> for higher-quality playback. In the example below, close-ups of two video frames show that we can provide sharper detail with fewer bits (note the clarity of the video on the right compared with that on the left).<\/span><\/p>\n<div class=\"wp-video\"><!--[if lt IE 9]&gt;document.createElement('video');&lt;![endif]--><br \/>\n<a href=\"https:\/\/engineering.fb.com\/wp-content\/uploads\/2022\/11\/Facebook_VIDEO_COMPUTE_1X1.mp4\">https:\/\/engineering.fb.com\/wp-content\/uploads\/2022\/11\/Facebook_VIDEO_COMPUTE_1X1.mp4<\/a><\/div>\n<p><span>The problem was that we were spending more than 80 percent of our resources processing minimum functionality encodings. If we stayed on that trajectory, minimum functionality would monopolize our resources within a year. As a result, videos would start to take longer to publish \u2014 or fail to publish altogether. Our advanced encodings covered only 15 percent of total watch time, and we projected that spending all our compute on minimum functionality versions would soon prevent us from being able to provide advanced video encoding watch time.\u00a0<\/span><\/p>\n<h2><span>Removing redundant workloads<\/span><\/h2>\n<p><span>Instagram creates two classes of minimum functionality encodings. For every video, we generate basic adaptive bit rate (ABR) encodings \u2014 our most-watched minimum functionality type. For the steadiest playback, clients can select the version that best fits their connection speed to prevent stalling caused by changes in bandwidth \u2014 a technique called <\/span><a href=\"https:\/\/howvideo.works\/#adaptive-bitrate-streaming\" target=\"_blank\" rel=\"noopener\"><span>adaptive bit rate streaming<\/span><\/a><span>.<\/span><\/p>\n<p><span>We rarely deliver progressive encodings, the other minimum functionality type, but we continue to produce them to maintain compatibility with old versions of the Instagram app that don\u2019t support ABR playback.<\/span><\/p>\n<p><span>Traditionally, we have created both ABR and progressive encodings from the original file the client uploaded to our back end. But this process hogs compute resources: As the following terminal command shows, it takes 86.17 seconds of CPU time to transcode a 23-second video to 720p.<\/span><\/p>\n<p>$ time ffmpeg -i input.mp4 -vf scale=-1:720 -c:v libx264 output.mp4<br \/>\n86.17s user 1.32s system 964% cpu 9.069 total<\/p>\n<p><span>We noticed that the settings of the two sets of encodings were similar. They used the same codec with only minor differences in the encoding profile and preset. Then it dawned on us: We could<\/span> replace our basic ABR encodings with the progressive encodings\u2019 video frames by repackaging them into an ABR-capable file structure<span>. This would virtually eliminate the cost of generating our basic ABR encodings. The following terminal command times show that it takes only 0.36 seconds to generate a manifest file and repackage the video frames into an ABR-capable file structure for the same input video.<\/span><\/p>\n<p>$ time MP4Box -add input.mp4 -dash 2000 -profile dashavc264:onDemand -out manifest.mpd<br \/>\nvideo_output.mp4<br \/>\n0.36s user 2.22s system 95% cpu 2.690 total<\/p>\n<p><span>This approach frees up compute for advanced encoding production, although it comes at the expense of the compression efficiency of our basic ABR encodings. Our theory was that <\/span>generating a greater number of advanced encodings would be a net positive for people who use Instagram.<\/p>\n\n<h2><span>Building a framework to test our theory<\/span><\/h2>\n<p><span>We needed to prove our theory before we could ship to production. If we compared the basic ABR encodings before and after our change, we would see only regressions. We also needed to measure the net effect from more advanced encodings. The diagram below shows the higher watch time we expected for advanced encodings after freeing up compute from our basic ABR. This would make up for the poorer compression efficiency of the new basic ABR.<\/span><\/p>\n\n<p><span>To measure this, we built a testing framework that replicated some small percentage of traffic across a test pool and a control pool of equal processing power. We saved the encodings from each pool to different namespaces so we could later identify them as part of the control or test catalog of videos. Then, at delivery time, people would see encodings from only one catalog or the other. This would allow us to measure whether the new encoding scheme was better.<\/span><\/p>\n\n<p><span>From this test, we proved that although we were degrading the compression efficiency of the basic ABR encodings in the test pool, the higher watch time for advanced encodings more than made up for it.<\/span><\/p>\n<h2><span>Pushing to production<\/span><\/h2>\n<p><span>After we launched this optimization, we saw major gains in compute savings and higher advanced encoding watch time. <\/span>Our new encoding scheme reduced the cost of generating our basic ABR encodings by 94 percent.<span> With more resources available, we were able to increase the overall watch time coverage of advanced encodings by 33 percent. This means that today more people on Instagram get to experience clearer video that plays more smoothly. This is especially important in providing a great experience to people in countries that have slower internet connections.<\/span><\/p>\n<p><span>There is still more engineering innovation needed, as Instagram\u2019s growing user base will continue to place increasing demand on our fleet of servers. Stay tuned!<\/span><\/p>\n<p><span>Over the years, Instagram has worked continuously to i<a href=\"https:\/\/engineering.fb.com\/2022\/10\/31\/ml-applications\/instagram-notification-management-machine-learning\/\" target=\"_blank\" rel=\"noopener\">mprove its product offerings<\/a>. Given our scale \u2014 including 2 billion monthly active users on our platform and more than 140 billion Reels plays across Instagram and Facebook every day \u2014 our work can make a huge impact. If this sounds interesting to you, <a href=\"https:\/\/www.facebookcareers.com\/jobs\/?is_leadership=0&amp;teams%5B0%5D=Software%20Engineering&amp;is_in_page=0\">join us!<\/a><\/span><\/p>\n<h2><span>Acknowledgments<\/span><\/h2>\n<p><span>Thanks to Haixia Shi for incepting the idea for this efficiency optimization. Thanks to Richard Shyong for implementing the optimization and the testing framework, which enables us to measure all compute efficiency investments. Thanks to Runshen Zhu and Ang Li for discussions that resulted in the investment in this scope. Thanks to our partners Atasay Gokkaya, Justin Li, Chia-I Wei, and Zainab Zahid for helping with testing pool provisioning and discussions on video compute efficiency.<\/span><\/p>\n<p>The post <a href=\"https:\/\/engineering.fb.com\/2022\/11\/04\/video-engineering\/instagram-video-processing-encoding-reduction\/\">Reducing Instagram\u2019s basic video compute time by 94 percent<\/a> appeared first on <a href=\"https:\/\/engineering.fb.com\/\">Engineering at Meta<\/a>.<\/p>\n<p>Engineering at Meta<\/p>","protected":false},"excerpt":{"rendered":"<p>In our constant quest to prioritize efficiency, Instagram\u2019s engineers have developed a way to process new videos that reduces the cost to produce basic video encodings by 94 percent. With this method in place, Meta\u2019s video infrastructure can continue to scale without needing to add more machines. This frees up resources so more people can&hellip; <a class=\"more-link\" href=\"https:\/\/fde.cat\/index.php\/2022\/11\/04\/reducing-instagrams-basic-video-compute-time-by-94-percent\/\">Continue reading <span class=\"screen-reader-text\">Reducing Instagram\u2019s basic video compute time by 94 percent<\/span><\/a><\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","footnotes":""},"categories":[7],"tags":[],"class_list":["post-647","post","type-post","status-publish","format-standard","hentry","category-technology","entry"],"jetpack_featured_media_url":"","jetpack-related-posts":[{"id":295,"url":"https:\/\/fde.cat\/index.php\/2021\/08\/31\/how-facebook-encodes-your-videos\/","url_meta":{"origin":647,"position":0},"title":"How Facebook encodes your videos","date":"August 31, 2021","format":false,"excerpt":"People upload hundreds of millions of videos to Facebook every day. Making sure every video is delivered at the best quality \u2014 with the highest resolution and as little buffering as possible \u2014 means optimizing not only when and how our video codecs compress and decompress videos for viewing, but\u2026","rel":"","context":"In &quot;Technology&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":795,"url":"https:\/\/fde.cat\/index.php\/2023\/11\/21\/writing-and-linting-python-at-scale\/","url_meta":{"origin":647,"position":1},"title":"Writing and linting Python at scale","date":"November 21, 2023","format":false,"excerpt":"Python plays a big part at Meta. It powers Instagram\u2019s backend and plays an important role in our configuration systems, as well as much of our AI work. Meta even made contributions to Python 3.12, the latest version of Python. On this episode of the\u00a0Meta Tech Podcast, Meta engineer Pascal\u2026","rel":"","context":"In &quot;Technology&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":682,"url":"https:\/\/fde.cat\/index.php\/2023\/02\/21\/how-meta-brought-av1-to-reels\/","url_meta":{"origin":647,"position":2},"title":"How Meta brought AV1 to Reels","date":"February 21, 2023","format":false,"excerpt":"We\u2019re sharing how we\u2019re enabling production and delivery of AV1 for Facebook Reels and Instagram Reels. We believe AV1 is the most viable codec for Meta for the coming years. It offers higher quality at a much lower bit rate compared with previous generations of video codecs. Meta has worked\u2026","rel":"","context":"In &quot;Technology&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":492,"url":"https:\/\/fde.cat\/index.php\/2021\/10\/20\/facebook-engineers-receive-2021-ieee-computer-society-cybersecurity-award-for-static-analysis-tools\/","url_meta":{"origin":647,"position":3},"title":"Facebook engineers receive 2021 IEEE Computer Society Cybersecurity Award for static analysis tools","date":"October 20, 2021","format":false,"excerpt":"Until recently, static analysis tools weren\u2019t seen by our industry as a reliable element of securing code at scale. After nearly a decade of investing in refining these systems, I\u2019m so proud to celebrate our engineering teams today for being awarded the IEEE Computer Society\u2019s Cybersecurity Award for Practice for\u2026","rel":"","context":"In &quot;Technology&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":166,"url":"https:\/\/fde.cat\/index.php\/2020\/12\/30\/2020-year-in-review-connectivity-innovations-faster-apps-and-progress-toward-net-zero\/","url_meta":{"origin":647,"position":4},"title":"2020 year in review: Connectivity innovations, faster apps, and progress toward net zero","date":"December 30, 2020","format":false,"excerpt":"It goes without saying that 2020 has been a challenging year, to put it lightly. But if anything, the COVID-19 pandemic has shined a light on our need to connect as people. For Facebook, that meant our work has become more important than ever. Whether it was finding new and\u2026","rel":"","context":"In &quot;External&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":613,"url":"https:\/\/fde.cat\/index.php\/2022\/07\/26\/launching-instagram-messaging-on-desktop\/","url_meta":{"origin":647,"position":5},"title":"Launching Instagram Messaging on desktop","date":"July 26, 2022","format":false,"excerpt":"In 2020 we launched Instagram Messaging (referred to in this post simply as \u201cMessaging\u201d) for personal desktop computers. We believe that this feature will improve everyday experiences and enable new use cases for all of our desktop web users. In this post, we go through some of our overall learnings\u2026","rel":"","context":"In &quot;Technology&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/fde.cat\/index.php\/wp-json\/wp\/v2\/posts\/647","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fde.cat\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fde.cat\/index.php\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/fde.cat\/index.php\/wp-json\/wp\/v2\/comments?post=647"}],"version-history":[{"count":0,"href":"https:\/\/fde.cat\/index.php\/wp-json\/wp\/v2\/posts\/647\/revisions"}],"wp:attachment":[{"href":"https:\/\/fde.cat\/index.php\/wp-json\/wp\/v2\/media?parent=647"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fde.cat\/index.php\/wp-json\/wp\/v2\/categories?post=647"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fde.cat\/index.php\/wp-json\/wp\/v2\/tags?post=647"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}