Compress videos using Azure

2022-03-19

Background

Videos are a large amount of data, they have to be compressed for streaming or storage purpose so that people can watch them daily. A part of the video player’s job is to decompress videos. The standards of these kinds of compression are called codec. Compared with old codec, modern ones generally mean less bitrate to deliver a video under a certain quality, which is greatly beneficial to disk usage and network transportation. For example, when re-encoding from H.264 to H.265, the file size reduced about 50% , and it decreases more on higher resolution videos .

Even though H.265 is much better, H.264 is still dominating the video market. Why? Device/protocol compatibility is a usual public reason, but not the reason on the situation of myself. Now that most of my electronic devices are modern enough to be able to decode H.265 videos, why would I keep “bloated” H.264 video files inside my hard disk / cloud disk? Because the long transcoding process by libx265 is painful to CPUs.

A solution is to use someone else’s CPU. Big companies must have better CPUs … Microsoft Azure seems worthy to try because I got $100 credit for free as a verified student.

Samples

The sample Big Buck Bunny is licensed under Creative Commons Attribution 3.0 and the author is (c) copyright 2008, Blender Foundation / www.bigbuckbunny.org .

3 movie files from the aforementioned project are used as samples in this blog post:

Operate MS Azure

  1. Register an account on Azure and apply for student subscription if you are a student.
  2. Go to “Media service” section, and create an instance of Media service by following its wizard. It take a while to deploy your new instance.

A quick tip to locate any Azure section: use the top search bar.

  1. To transcode video files, you need 3 steps: preparing input file, executing transcoding, and get the output file. It’s tricky that you have to do these 3 steps in 3 different places on Azure. And the sidebar just lists too many items preventing people thinking on where to start.

It’s very easy for untrained individuals to get lost in the maze of Microsoft’s enterprise level application.
azure-mediaservice-demo-panel

  1. Upload input files. If you upload files from your local device, I recommend uploading from the “Assets” page on the sidebar, because only from here can you upload multiple files at once. If your video source has a direct URL, you have to put URL on the “Create a job” page, and this page can be reached on the “Assets” or “Transforms + jobs” page in the sidebar. Do not upload from Azure Blob Storage pages, such as “Storage accounts (classic)” or “Storage browser (preview)": I tried, but it didn’t work.

The demo files has a public direct URL azure-mediaservice-dcreate-job-put-url

  1. Execute transcoding. Click “Create a job” and set the configuration accordingly. For input selection, you can choose videos you uploaded before through “Select an existing asset”. To select transcoding parameters, choose “Encoding” as “Transform type” and select one from built-in presets. You cannot customize parameters so your selection must be within the provided presets if using Azure web client.
  2. Confirm transcoding configs and wait for the process getting done. The progress can be checked on the “Transforms + jobs” page.

azure-mediaservice-job-progress

  1. The way to get processed files can also be confusing. Go to the Media service - Assets page, and find the output assets, and then follow the “Storage link” to view and download files from Azure blob file browser. The following image may help.

azure-mediaservice-download-output-files 9. Delete files to release disk spaces. You’d better do this on the Assets page rather than the Job page. If files are not removed, you will use more disk space so that MS can charge you if your usage exceeds the free quota.

Benchmark

Baseline

Transcoding on my own computer as the baseline.

HardwareSoftware
Intel(R) Core(TM) i5-7300HQ @ 2.50GHzffmpeg version 5.0-full_build-www.gyan.dev

Parameters are like:

ffmpeg -i filename.mp4 -c:v libx265 -c:a aac filename.ffmpeg.libx265.mp4

And iGPU.

HardwareSoftware
Intel(R) HD Graphics 630ffmpeg version 5.0-full_build-www.gyan.dev

Parameters are like:

ffmpeg -hwaccel qsv -i filename.mp4 -c:v hevc_qsv -load_plugin hevc_hw -c:a aac filename.ffmpeg.hevc_qsv.mp4

Results

If there are multiple output files, only the mp4 with highest resolution will be evaluated.

Input file:

  • bbb_sunflower_1080p_30fps_normal.mp4 (263.34 MB)
Transform presetJob durationFile size (MB)Compression ratio
Baseline17m 11s127.2148 %
Baseline (iGPU)10m 34s92.2435 %
H265ContentAwareEncoding12m 35s218.9483 %
H265AdaptiveStreaming12m 22s24392 %
H265SingleBitrate1080p9m 31s282.07107 %

Input file:

  • bbb_sunflower_1080p_60fps_normal.mp4 (339.37 MB)
Transform presetJob durationFile size (MB)Compression ratio
Baseline28m134.4840 %
Baseline (iGPU)10m 34s93.4828 %
H265ContentAwareEncoding19m 45s279.982 %
H265AdaptiveStreaming17m 43s318.0194 %
H265SingleBitrate1080p12m 26s281.6683 %

Input file:

  • bbb_sunflower_2160p_30fps_normal.mp4 (603.69 MB)
Transform presetJob durationFile size (MB)Compression ratio
Baseline71m 19s289.2348 %
Baseline (iGPU)10m 34s104.6117 %
H265ContentAwareEncoding37m 19s528.3288 %
H265AdaptiveStreaming39m 58s577.9896 %
H265SingleBitrate4K25m 15s729.55121 %
H265SingleBitrate1080p11m 42s281.7447 %

Conclusion and Complaint

Azure’s transformation encodings are faster but generates bigger files. Based on the file size, it seems that Azure does not use CPU for video transcoding. So Azure does not provide video encoding service with high compress ratio for storage purpose. Hard disk won’t be saved in this manner. I have to consider other methods for the sake of my hard disk.

As a personal user, I felt very inefficient using Azure web client interface. To transcoding just one video file, I had to jump among around 5 web pages. And I had to add jobs (transcoding tasks) for each file one by one, even if they have the same process parameters. Opening multiple links to different blob storage containers only leading to my Azure account logged out after waiting for several long-time sorts of account-authentication-related redirections. All the redundancy on the top of the complicated and confusing panels just push me back to the simple and super efficient ffmpeg commands. Back to ffmpeg, you only need one line of command and all-set.

Update: iGPU seems the best one according to its speed and its final size. However, the converted video shows very low quality, so it’s not recommended.

Homework

My dear readers, here is your homework:

  1. Why not using GPU for transcoding?
  2. What’s the difference between the terms “transcode” and “remux”?
  3. What’s the meaning of each encoding preset on Azure?
  4. How to do if the student verification of azure account is unsuccessful, when you are really a student?

Answers are welcomed to comment below.

OperationGuideazureffmpegencodingremuxcloud



Support Me

您可以 打赏 支持本文作者

Use Jieba on browser and Deno (NPM-free!)

Upload videos to YouTube Brand Account via API