Why Closed-loop Perceptual Quality Measuring Beats All Other Optimization Methods

The market is heating up with solutions that claim to reduce the size of video files by impressive percentages, some up to 50%. But reducing bitrate is only one side of the coin what happens to the quality of the video when bitrate is reduced? How can you make sure that the right bits are eliminated and the visual quality is not compromised? I only know one way to do it right: Verifying video quality using perceptual quality measuring.

Perceptual quality measuring goes beyond existing quality measures such as PSNR and SSIM, and quantifies the actual visual quality of the content, demonstrating a very high correlation with subjective human results. How can I be so sure? With 6 years of intensive research and development here at Beamr, you’ll have to trust me on this.

I’m also relying on testing according to the strict ITU BT.500 standard requirements for image quality, where the correlation of our own quality measure with subjective results has been proven. I can vouch for the testing we conducted with real users under actual viewing conditions that validated that the optimized version is imperceptible to the original.

Video optimization based on perceptual quality measuring is done by determining the subjective quality level of the input and output video streams, using this information to control the video encoding process. The key advantage of this method is guaranteeing the preservation of perceptual quality by actually checking the encoded content in a closed loop, on a frame-by-frame basis. Then specific encoding parameters are modified until every output frame is perceptually identical to the input frame.

Other optimization methods use pre-filtering, meaning that they work in an open loop since the video is filtered before it’s encoded. These methods don’t check the output frames and are unable to feed back the information to the pre-filter since they don’t employ a quality measure. This means they have no way of guaranteeing that the output of the encoding or optimization process is perceptually identical to the input.

Furthermore, some optimization solutions require information about the viewing conditions of the video, which creates the need for special client-side software and a real-time back channel between the client and pre-filter. In absence of such information, the pre-filter makes assumptions about the viewing conditions, which may not be accurate.

Based on what I hear from premium content owners and producers, pre-filtering solutions are suitable only for specific use cases, such as videos that originate from low-quality smartphones and contain a lot of noise. But they are a non-starter in any general application, where video quality levels are to be held high, regardless of the input content.

In these applications, closed-loop inspection of the output video frame, while comparing the result to the input frame using a subjective quality measure (provided it features high correlation with human vision), is the only way to ensure that the perceptual quality of the video is never compromised.

I hope you now have a better understanding of the difference between the various optimization methods, and the advantage of perceptual quality measuring over all other methods. If you have any questions, please contact me through Facebook, Twitter or LinkedIn.

Beamr @ IBC 2015

The Beamr team is already at the International Broadcasting Convention (IBC) in Amsterdam, setting up for a great show. This is where we can best demonstrate the what, why and how of media optimization.

Visitors at our main booth Hall 3, Booth 3.A29h, in the Israeli Pavilion, will be able to experience media optimization first hand, via a full scale demonstration of Beamr Video on a 4K screen.

Those particularly interested in cloud solutions are welcome to visit us at Amazon Web Services, in Hall 14, Booth 14.N29, where we will be showcasing Beamr Video Cloud Service. You can also come and hear my presentation on Media Optimization in the Cloud at the AWS IBC Theater (14.N29) on Friday, September 11 at 12:00 pm, and Sunday, September 13 at 2:30 pm.

Let’s Get Practical
Whether you are or aren’t planning to be at IBC, I wanted to share the following (excellent) document written by Jan Ozer, describing how to integrate Beamr Video into a video encoding workflow.

Click here to download the document.

I’m excited to have the opportunity to explore new technologies, strategies and trends at IBC, and would be happy to meet you at the show to share insights, discuss industry trends and give you a first-hand demo of our media optimization products.

Looking forward to seeing you at IBC, and hearing from you on our Facebook, Twitter or LinkedIn accounts.

Over the Top: The War for TV is Heating Up in Q3

Video Compression Taking Center Stage

TV is at a tipping point. Over the top, or OTT, is the industry term for video content delivered over the Internet, but you probably know it better as Netflix, HBO Go or Hulu.  With Netflix counting more than 40 million subs in the US and HBO Go enabling access to their most popular content outside of a pay TV package, tech companies are investing heavily to build rich ecosystems of video content delivered over the Internet. The result is a panoply of content options across more devices, which is creating a nation of potential cord cutters.

2014 demonstrated the OTT race was on but in Q3 2015 we are seeing it pick up the pace – with OTT offerings involving mobile service providers as well as SVOD players like Netflix, Amazon Instant Video, HULU, and PlutoTV – while at the same time we’ve seen a drop off in network stocks, started by Disney.

While it’s clear that the way we deliver television is changing, the future isn’t here yet. The race to find new and better ways of interacting with TV has resulted in a new wave of innovation, as startups and corporate America race to rethink the viewing experience.

Traditional TV distributors, such as cable companies, are responding as they recognize shifting viewing behaviors driven by millennials, who have been leading the migration to digital. This means networks without a sufficiently robust online offering, are being quickly left in the dust by subscribers seeking more flexible content options, which is why independent streaming services are now having their moment in the spotlight.

Offer the right content on a device with a superior user experience and there’s no stopping OTT. It sounds simple enough, but there are still challenges. Content providers, broadcasters and tech companies moving content to OTT, are now struggling to maintain streaming quality across connected devices on increasingly crowded bandwidth. Without a quality user experience, OTT can’t thrive.

As video traffic now consumes 64% of the Internet according to Cisco, Q3 saw an increasing number of content providers looking for solutions to decrease the streaming size of their files in order to improve the quality of the streaming experience – bringing the need for additional video compression efficiency to the forefront. The formation of a second patent pool called HEVC Advance has created some uncertainties regarding royalty payments for the HEVC video codec.  This has driven some of the largest tech companies including:  Amazon, Cisco, Google, Intel, Microsoft, Mozilla and Netflix to announce the formation of the Alliance for Open Media, a group seeking to create a royalty-free compression technology that is competitive in performance to existing state-of-the-art codecs.

Regardless of the codec technology, optimizing the compression to ensure maximum quality at the lowest bitrate continues to be our focus here at Beamr. Our technology, which currently supports H.264 and HEVC, and can easily be expanded to support any emerging or future video codec, provides the most efficient and effective way to ensure a service is able to produce the highest quality video possible, addressing the streaming quality struggle. In light of what’s going on in the industry at the moment, we’re excited to announce that we’ll be attending the upcoming IBC conference, where we’ll have the opportunity to showcase our technology both in the Israeli Pavilion and at the Amazon AWS booth. We’re thrilled to be a part of such a big conference and to be presenting alongside the AWS team.

Integrating Media Optimization into a Video Processing Workflow

After introducing the concept of media optimization and understanding its value –improving viewing experience for streaming services, reducing storage and delivery costs – we can focus on a more practical issue: How to integrate media optimization into an existing video processing workflow.

A typical video processing workflow begins with a high quality file, called a Master or Mezz file.  This is a high-resolution, high-bitrate version of content, which serves as the reference for creating all other versions.

The first step is to encode the video file into various profiles, which are sets of parameters (resolutions, bitrates, encoding modes) that fit a particular end-device or connectivity bandwidth. Typically, each video title is encoded into 10-15 different profiles, at different resolutions and bitrates.  The player app in each client device “pulls” the right version from the streaming server based on the capabilities of the device, and momentary data bandwidth available.  This method is called Adaptive Bitrate Streaming (ABR), and is commonly used for delivery of OTT video content.

The second step is packaging the video file for delivery.  ABR protocols, such as HLS and MPEG-DASH, divide each encoded file into small segments or packets, which flow over the network more easily and provide flexibility when switching between the different profiles. For paid streaming services, there is an additional step of encrypting the video content to ensure that only eligible customers gain access.

After the video is encoded, packaged and encrypted, it is placed on a server that delivers the streams to the end user.  The content from the server is typically cached by a CDN to enable better performance and lower delivery costs for global distribution.

Media optimization reduces the bitrate of video streams while preserving their quality.  Therefore, the best place to apply media optimization is right after encoding the file, and before packaging it.  The initial encode is required to provide a quality reference to the media optimizer, which then preserves this quality in its output.

Since packaging depends on the bitrate of the files, the packaging and encryption step is performed after optimizing them.  In such a workflow, you first encode the video with your chosen ABR profiles, and then optimize each one of them.  Finally, the streams are optimized, packaged, encrypted (if necessary) and delivered to the end user.

A good media optimization solution preserves all the attributes of its input file, so the packaging step can be applied to the optimized file in exactly the same way as it would have been performed for the regular encoded file.  It’s also important that a media optimization solution preserves the locations of the key frames (I-frames) in each ABR stream, so they are synchronized after optimization.  This ensures that the client device can seamlessly switch between the encoded ABR streams, based on available bandwidth.

As you can see, integrating media optimization into a workflow is pretty straightforward.  Once you have your content management and processing workflows in place, it’s just an additional process to run in the system.  Future posts will cover more advanced issues such as integrating watch folder functionality, eliminating unnecessary ABR profiles after optimization and controlling the workload of optimizing several files in parallel.

Media Optimization: What’s In It for Me?

In last week’s post we introduced the concept of media optimization: taking an already-compressed media file and reducing the file size or bitrate as much as possible, without affecting its perceptual quality. So, now that we’ve told you what media optimization is, let’s take a look at the why.

Why would you want to reduce the bitrate of your video files?  Well, one obvious reason is cost.  Video files are huge, and can reach gigabytes of data for full-length movies, even when compressed for delivery over the Internet.  On top of that, production companies need to produce several different versions of their video files, to target different devices (TVs, laptops, mobiles), as well as accommodate different bandwidth capabilities of end users.  So, typically, for each video title this would mean 10-15 different versions, at different resolutions and bitrates.  This of course increases storage requirements significantly. A fairly large library of hundreds or thousands of video titles, each one in a dozen different versions, can result in a hefty storage bill, whether the files are on-premises or in the cloud.

Yet, the cost of video storage is still small compared to the cost of video delivery, especially for popular titles that have thousands, or even millions of views.  In Amazon cloud, for example, storing one Gigabyte of data costs around 3 cents per month, and delivering one Gigabyte of data in the US costs 2-8 cents per month, depending on volume.  When the cost of storage is multiplied by the number of versions per title (10-15, as described above) and the cost of delivery is multiplied by the number of viewers per title (hopefully thousands or more if you are doing well…), this adds up, very quickly.

The main concern for many content providers, accordingly, is content delivery network (CDN) costs. Imagine if companies could optimize video files, reducing the file size by 35 percent while retaining full quality – resulting in a 35 percent reduction in monthly CDN costs; who could say no to that?

So, where’s the catch?  It probably costs something to optimize files, and how does that cost compare to the amount saved?  As detailed in a blog post by Dan Rayburn, EVP of StreamingMedia.com and Principal Analyst at Frost & Sullivan, Beamr Video provides a positive ROI after only 1500 views.  This means a savings of $10,000 per 1 million views, demonstrated in our ROI whitepaper.

In addition to cost savings, there is a benefit of media optimization that can be even more critical to business: Improving user satisfaction. We are all familiar with the buffering icon shown when a video can’t be played due to insufficient bandwidth. This is not something users want to see. Often, it will cause users to either abandon the title they are watching, or search for a different service with faster streaming.  Video UX measurement firm Conviva has shown that consumer’s loyalty to over-the-top streaming services is tied the viewing experience: one in three viewers leaves to find content elsewhere whenever experiencing playback degradation; and 40 percent reported reduced affinity for a service after just one bad experience.

Ultimately, fewer bitrates means a faster video stream and a better viewing experience – over the user’s existing bandwidth. M-Go, the premium digital streaming service and joint venture between Technicolor and DreamWorks, reported 50 percent fewer buffering events and 20 percent faster stream starts after using Beamr Video to optimize their files.

Optimizing video files not only decreases storage and delivery costs, but also enables faster streams and fewer buffering events, increasing user retention. The next question you are probably asking is how to integrate media optimization into a video processing workflow?  We’ll have more on that in next week’s post…

What the Heck is Media Optimization?

Good question…  If you search Google for Media Optimization, most of the results you find are for Social Media Optimization, the process of optimizing a website to enable easy sharing on social media channels.  Well, the media optimization we are referring to is quite different… First of all, we are talking about a different meaning of the term media: Not a communication channel, but a file containing some digital content, such as a photo, video or music file.

So what does it mean for your digital media file to be optimized?  In order to understand the optimization process, we first need to understand a common process that is applied to digital media files: Compression.  When you capture media, such as a photo or video, it contains a lot of data.  A photo for example contains 3 color values for each pixel: Red, Green and Blue.  And there are millions of pixels in each photo; an 8 Megapixel camera, for example, has 8 million pixels, so the original captured image has 24 million numbers that represent the color values of the image, 3 for each pixel.  Clearly not all this information is needed: The human eye cannot distinguish between every individual color combination value for a pixel, and the color values of adjacent pixels are typically very similar.  So there isn’t a real need to store the individual color value of each pixel – this huge amount of information has a lot of redundancy to it.  

Compression is the process which removes this redundancy, eliminating unnecessary information and representing the media file in a much more compact form.  For photos, the most common method of compression is the JPEG standard.  An 8 Megapixel photo would require 24 Megabytes of information to fully represent the color values of each pixel (3 bytes representing Red, Green and Blue components for each pixel).  After JPEG compression, the file size of the photo, which is saved by the camera, is reduced to around 2-3 Megabytes.

So once a photo is already compressed, how can you further optimize it?  The answer lies in the nature of JPEG compression, which is not content-adaptive. In JPEG, you manually set your desired quality level for the photos, and the JPEG compressor applies the same amount of compression to all content types. But some content types, such as smooth surfaces and solid colors, can be compressed further with no loss in quality.  Out-of-focus areas of the photo can also be compressed further without the user noticing any change.  

So in fact, after JPEG compression there is room for further optimization of the photo’s file size, by performing adaptive compression that takes into account the specific content of the photo, and the attributes of the human visual system.  This is exactly the process of optimization: Reducing the file size of a digital media file, while retaining the full quality and resolution of the original file.  This is similar to people that go on a diet – their size is smaller, but they are still the same person… So it’s no coincidence that the slogan of our photo optimization technology is JPEGmini – Your Photos on a Diet!.

Now consider video files: The same story, but a much bigger problem!  With 4K video, you have 25 or 30 of these 8 Megapixel photos every second.  Multiply that by a 90 minute movie, or even a 3 minute music video, and you get a huge amount of data.  Video compression standards such as H.264 and HEVC do a lot to reduce the file size of these streams, turning them into something that is manageable and can be streamed over the Internet (if you have a decent broadband connection).  But these standards are also not content-adaptive: You need to set your desired bitrate, and all of your files are encoded to that same bitrate.  However, there are scenes in the video that require less bitrate, and will not be affected (quality-wise) by some additional compression.  If you could identify these scenes, as well as individual video frames and increase their compression too, you would end up with an optimized file!  A file that has the same quality and resolution as the input file, but lower bitrate.  This is exactly what is done by Beamr Video, which reduces the bitrate of already-compressed video files, without affecting their quality or lowering their resolution.

So now you have it: Media optimization is reducing the file size or bitrate of already-compressed media files to the minimum possible, while still retaining their full quality and resolution.  But why would you want to optimize files anyway?  Well, it turns out this is exactly the topic of next week’s post, so stay tuned…

360-degree Videos Bring a New Cinematic Experience, but Create Delivery & Viewing Challenges

The movie industry has been around for over 100 years, but the cinematic experience hasn’t changed much: Basically, you watch the action happening on a screen in front of you.  This is true from the earliest silent movie theatres to the latest iPad tablet apps and OTT streaming to Smart TVs. 3D movies give some depth to the experience, and large screens such as IMAX can make it more immersive, but the core experience of watching a movie is the same. Over the years, some attempts to enhance the experience have been made, for example scratch-and-smell Odorama cards,  or 4D movies where some action in the theatre is synchronized to events on screen, but these have not gained wide acceptance in the market.

Now, imagine a movie that is all around you.  You are in the middle of all the action, you can look to the right, to the left, behind you and even upwards; and see what’s happening all around.  This is the experience enabled by a new type of media: 360-degree videos.  Somewhat similar to Virtual Reality (VR), 360-degree movies are best watched with a VR headset such as the Oculus Rift or HTC Valve.  But in contrast to VR, the content of 360-degree videos is not computer-generated graphics, but real-world content, captured by a set of cameras or a special spherical camera.

March 2015 marked an important milestone for this emerging segment: YouTube started supporting 360-degree videos in the Google Chrome browser, and in the YouTube Android app (iOS support followed a few weeks later).  This opened new opportunities for content creators to showcase their surround video storytelling capabilities. Recently, YouTube announced support for 360-degree video ads, and 3D support for these videos is expected later this year.  In this post, I will show you how 360-degree videos are captured, and what are the challenges in creating and delivering them to viewers.

Capture The World

The most common way to capture 360-degree videos today is using a rig that holds several GoPro video cameras, each one of them positioned at a different angle, which together capture a spherical field of view around them.  Examples of such rigs include the Freedom360 which holds 6 GoPro cameras, and the Google Jump that holds 16 GoPro cameras and captures 3D 360-degree video.  These rigs and the required GoPro cameras can easily cost a few thousands dollars, at the same time they produce high-quality video and are available today.

If you are looking for a less expensive solution, and much more lightweight, you can use the Ricoh Theta M15 or the Kodak SP360 spherical cameras, which are available for around $200-$300.  And just around the corner are the next generation of these cameras, such as the 360Fly, Giroptic, Bubl and SpheriCam, which are being funded on Kickstarter.  These cameras cost between $300 and $1000, and produce higher quality videos than the current generation single-camera solutions.  Last week Nokia made a surprise comeback to the consumer electronic scene, with its announcement of the OZO professional 360-degree video camera, expected in Q4 2015.

If you’re using a rig of cameras, you also need to go through the extra step of “stitching” the separate videos from each camera into a single 360-degree video file.  There are two major brands for stitching software: Videostitch, and AutoPano Video by Kolor (which was acquired by GoPro).  After stitching your movies, they are ready for upload to YouTube.

See All Around

For viewing 360-degree content, the most popular apps are those which support YouTube content: Currently the Google Chrome browser, and YouTube apps on iOS and Android. When viewing on Chrome, you can pan in all directions using your mouse, or use click on the on-screen navigation bar.  In the YouTube apps, navigation is more natural: You simply move your device around to pan in different directions.  When you do this, make sure you are either standing up or sitting on a swivel chair, otherwise when you reach certain angles you can easily strain your neck…

Kolor also makes the Kolor Eyes free software for PC, Mac, iOS and Android that lets you view 360-degree videos.  With the Kolor Eyes software, you can even zoom in and out and of the video, and try alternative projections of the video such as Mirror Ball, Little Planet and FishEye.

But without a doubt, the best way to view 360-degree videos is with a VR headset, or the cheaper smartphone holder alternatives such as the Google Cardboard.  When using these devices, you simply move your head in the direction that you want to view, and since the screen (or screens) fill your whole field of view, you get a truly immersive experience.

The Delivery Challenge

While 360-degree videos create a new and exciting experience for viewing, delivering them over today’s network infrastructure can be quite challenging. The reason is that the total resolution of the video is 4 to 9 times higher than the viewport resolution (the part of the video that you actually see on your screen at any given time).  So if you want the video viewport to be in full HD resolution (1920×1080) on your screen, your 360-degree video should be at least 4K resolution (3840×2160).  The challenges in delivering 4K video over the Internet are well known, but for 360-degree videos there is an additional challenge: 4K video is mostly viewed on 4K TVs, which support the new HEVC codec, providing better bandwidth efficiency than the current H.264 (AVC) codec.  But 360-degree videos are viewed on the current generation of PCs and mobile devices, which don’t support HEVC yet.  This results in very high bitrates, or more often,  very low quality for the resulting video.  Luckily, we have the technology to reduce the bitrate of H.264 video streams by up to 50% without compromising their quality, so we welcome 360-degree videos and are up to the challenge of delivering them in high quality and low bitrate to viewers everywhere.

I’m passionate about 360-degree videos.  If you feel the same, you are welcome to contact me at dror@beamr.com or through our Facebook and Twitter channels.

Effects of a Crowded Net on Streaming Service ARPU

Do we have any hope of surviving the multi-screen, place shifting consumer?

If you are reading this post then you already know that video has taken over the Internet, so I will spare you a paragraph of needless recitals from the latest industry polls stating as such.  Instead I wish to discuss an overlooked solution, known as media optimization, to the video congestion problem, and the positive impact it can have on revenue in the form of ARPU (Average Revenue Per User).

Though the death of TV is a popular blogging subject these days, the fact is, consumers are watching more entertainment content than ever.  However, today’s entertainment experience is now spread across multiple devices and screens.  For a content distributor or streaming service provider, the day to day operational challenges are coming from the ever widening device platforms that need to be supported, as well as the ever-increasing “unmanaged” environments where the consumer expectation for quality is higher than ever.  Accenture in their 2015 Digital Consumer Survey found that 33% of TV viewers who watch long form video on IP connected devices complained about buffering or slow start-times as a result of their expectations for a seamless HD content experience.

It seems in the consumer’s view, an iPad Retina should be streaming the same gorgeous video quality as their 60” premium quality HDTV connected to a cable or satellite box.  Lost to the customer is the fact that the iPad is streaming over a Wi-Fi network which is likely connected to a congested Internet connection, while the HDTV is connected to wired set-top box.  Do you remember when a 20mbps Internet package felt like overkill?

As in life, it’s easy to identify problems but more difficult to find solutions, so rather than dwell on the challenges presented by shifting user behavior and an increasingly crowded Internet I want to introduce a viable solution called media optimization.

Media optimization is a method whereby a digital video file is further compressed beyond the limits of modern day encoder technologies.  Though different techniques and approaches are used, only solutions that are able to retain the original perceptual quality can be viable, as sacrificing video quality in order to save bit-rate is a recipe for customer complaints, reduced ARPU and lost revenue opportunities.

 

How media optimization impacts ARPU

The subject of streaming quality is a complex one since there are multiple technologies and platforms that must all come together at precisely the right time and in the right way in order for a viewer to have a satisfying experience.  For this reason, it’s no wonder that a perfect streaming experience continues to be elusive for even the biggest players in the field.  However, it is possible to deliver a better experience today than yesterday with the addition of a single step to your workflow, and this is media optimization.

Media optimization can reduce buffering events by nearly 50%, and improve stream start times by up to 20% across viewing sessions.  This can be a huge service differentiator as Conviva reported in their most recent 2015 Viewer Experience report that 28.8% of video views in 2014 suffered from buffering.  Furthermore, 58.4% of views suffered from low resolution, which was likely driven by the nature of ABR (Adaptive Bit Rate) switching down profiles as the player attempted to maintain a steady consistent stream rather than buffer.

It stands to reason that a smaller file will transverse the network with greater ease than a larger file.  Which means media optimizations is an ideal tool for improving streaming user experience for any service that wishes to increase viewing time and customer satisfaction.  These will create higher revenues for ad-driven services by increasing ad viewing time, reduce churn for subscription services, and create more frequent rentals for transactional VOD models.

Thank you for reading.  I love digital media and have an excellent understanding of the challenges today’s streaming service operators face, as well as the solutions that are available to them and I would be happy to discuss your specific needs.  You may contact me at: mark@beamr.com.

Introducing Beamr Blogger – Mark Donnigan

Hi, my name is Mark Donnigan.  As the Vice President of Marketing at Beamr, I am responsible for the corporate communications, market development and commercial success of Beamr products.

My formal education is in computer science and music, a combination which lead me to Cornell University where I completed MBA Certificate courses, and in the process became extra passionate about combining business, technology, movies and music to create and deliver amazing entertainment experiences. Today, I am excited and inspired to be delivering next generation media optimization solutions for digital distributors and publishers seeking to create the best consumer experiences possible.

Specific areas of expertise include streaming delivery technology, digital content business models, content licensing, content security and DRM. As a result of the ecosystem experience I’ve amassed, I feel most fortunate to be able to travel and speak widely on behalf of Beamr, addressing the rising need for media optimization solutions in today’s network congested reality where video commands more than one-third of all Internet traffic during peak hours. Streaming Media, Digital Hollywood, Media Summit NYC, OTT Executive Summit and Fierce Online Video are some examples of conferences I have spoken at or media outlets where my thought leadership was featured.

I look forward to sharing insights into the exciting world of media and entertainment distribution in future posts; ideas which I hope can shape the future of digital entertainment and new media distribution. I’d love to hear back from you at our Facebook, Twitter or LinkedIn accounts. Let’s lean into this exciting golden age of entertainment together.

Why You Should Also be Excited About AWS Lambda

Websites like JPEGmini.com have a purpose. They tell a story. JPEGmini.com tells the story of image optimization through a web-based, easy-to-use demo. Users are able to experience the product online, hands-on, without further ado. This is the magic of JPEGmini.com.

But our web-based optimization service is not limited to a single photo.  JPEGmini also has a free web service, where users upload large amounts of photos, and download the optimized versions of their photos.

From the user’s point of view, optimizing their photos is very simple. They upload their photos to JPEGmini.com, and we send the optimized photos back, reduced by up to 80%, yet without any visible difference in quality.

Behind the scenes there is a lot going on in order make this happen. Just like any other online service, we run clusters of servers hosted in multiple data-centers in order to process millions of photos.

Being a long-time fan of AWS, it was an easy decision to build upon their infrastructure.

Using the AWS building blocks (EC2, ELB, etc.), it is relatively straightforward to setup multiple web servers behind a load balancer, queue tasks to multiple servers, scale the work force dynamically, manage storage, etc. We let Amazon handle infrastructure, so we can focus on the user experience.

Almost. We still need to configure, manage and monitor all these services and components.

That got me thinking — how could we simplify the backend?

Static websites hosted on S3 provide highly-available, fault-tolerant and scalable websites, with literally zero DevOps required. By combining client-side processing with backend-hosted 3rd party services (e.g. directly accessing AWS services with the js sdk) it is possible to build many dynamic applications. Yet, in our case, one part was still missing — the ability to run our customized photo optimization algorithm on the backend.

Well, not anymore — thanks to AWS Lambda functions.

Briefly, AWS Lambda is a service that runs your code in response to events, managing the compute resources automatically. With AWS Lambda, there is no need for infrastructure management. Say goodbye to the task-queues, servers, load-balancers, and autoscaling. There would even be no more need to monitor servers. It is essentially “serverless” processing.  Very cool.

In contrary to my first impression, Lambda is not limited to just JavaScript and Java. Any native code that can run in a container can also be packaged into a Lambda function (more on this below).

This would also mean less expenses. Lambda pricing is in increments of 100 milliseconds (as opposed to paying by the hour for EC2 servers). Essentially, better optimization of the pay-per-use model.

A Lambda-based backend means less effort for developers, IT and system engineers.

It is both serverless and simple. If your website requires back-end processing, and this can be broken into small compute tasks, you should think about making use of Amazon Lambda.

The technical details

The JPEGmini Lambda function is intended to replace the backend servers performing the actual image optimization. With the Lambda-based architecture, users upload their images directly to S3, which triggers our Lambda function for each new image. The function optimizes the image, and places the resulting image back on S3.

Out of the box, AWS Lambda supports the Node.JS and Java 8 runtimes, and those are the only two options you get to choose from when defining the function in the AWS Console. The less known fact is that you can bundle any code (including native compiled binaries) and execute it from within the JavaScript or Java Lambda function.

When defining the Lambda function, you can either edit the code inline (on the website), which is probably good enough for small hello-world type functions, or upload a pre-packaged zip file with all the code. The latter makes a lot more sense when the code uses external dependencies, grows in size, or when you manage your code with git (or similar). Packaging a zip file also lets you include native compiled binaries into the zip, and then execute them from within your code.

We used the AWS JS SDK for Node.js to handle moving files from S3 to the local system and back. The running Lambda function has permission to write into /tmp.  Execution of the pre-compiled JPEGmini binary is done with shelljs, which simplifies waiting for the subprocess to finish, and error handling.

To avoid dynamic dependency issues, we made sure that the JPEGmini binary was statically linked to all dependencies, and verified it works well on an Amazon Linux EC2 instance before trying to get it working within the Lambda context. During development, the console.log function proved to be a very useful debugging tool,l which helped figure out how things were behaving on the file system.

Tying it all together, the resulting function downloads an image from S3 to /tmp, optimizes the image using the native JPEGmini binary, and uploads the result back to S3. We configured an S3 event to trigger our Lambda function when new images are uploaded to the bucket, and we monitor the process via CloudWatch — serverless processing.