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:
- bbb_sunflower_1080p_60fps_normal.mp4
- bbb_sunflower_1080p_30fps_normal.mp4
- bbb_sunflower_2160p_30fps_normal.mp4
Operate MS Azure
- Register an account on Azure and apply for student subscription if you are a student.
- 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.
- 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.
- 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
- 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.
- Confirm transcoding configs and wait for the process getting done. The progress can be checked on the “Transforms + jobs” page.
- 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.
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.
Hardware | Software |
---|---|
Intel(R) Core(TM) i5-7300HQ @ 2.50GHz | ffmpeg 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.
Hardware | Software |
---|---|
Intel(R) HD Graphics 630 | ffmpeg 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 preset | Job duration | File size (MB) | Compression ratio |
---|---|---|---|
Baseline | 17m 11s | 127.21 | 48 % |
Baseline (iGPU) | 10m 34s | 92.24 | 35 % |
H265ContentAwareEncoding | 12m 35s | 218.94 | 83 % |
H265AdaptiveStreaming | 12m 22s | 243 | 92 % |
H265SingleBitrate1080p | 9m 31s | 282.07 | 107 % |
Input file:
- bbb_sunflower_1080p_60fps_normal.mp4 (339.37 MB)
Transform preset | Job duration | File size (MB) | Compression ratio |
---|---|---|---|
Baseline | 28m | 134.48 | 40 % |
Baseline (iGPU) | 10m 34s | 93.48 | 28 % |
H265ContentAwareEncoding | 19m 45s | 279.9 | 82 % |
H265AdaptiveStreaming | 17m 43s | 318.01 | 94 % |
H265SingleBitrate1080p | 12m 26s | 281.66 | 83 % |
Input file:
- bbb_sunflower_2160p_30fps_normal.mp4 (603.69 MB)
Transform preset | Job duration | File size (MB) | Compression ratio |
---|---|---|---|
Baseline | 71m 19s | 289.23 | 48 % |
Baseline (iGPU) | 10m 34s | 104.61 | 17 % |
H265ContentAwareEncoding | 37m 19s | 528.32 | 88 % |
H265AdaptiveStreaming | 39m 58s | 577.98 | 96 % |
H265SingleBitrate4K | 25m 15s | 729.55 | 121 % |
H265SingleBitrate1080p | 11m 42s | 281.74 | 47 % |
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:
- Why not using GPU for transcoding?
- What’s the difference between the terms “transcode” and “remux”?
- What’s the meaning of each encoding preset on Azure?
- How to do if the student verification of azure account is unsuccessful, when you are really a student?
Answers are welcomed to comment below.