Converting H.264 Videos to VP9 In Linux / Ubuntu

Orange Pi Development Boards

1080p videos are all good, but my Internet connection’s upload speed is limited to 512 Kbps, so for example uploading a 20 minutes H.264 video shot at 1080p30 may easily take 10 hours, even after some processing with Handbrake. So this week-end I investigated how I could reduce the upload size, and going with H.265 codec appeared to be a good idea at first. So I tried again H.265 encoding in Handbrake in Ubuntu 14.04, and discovered that adjusting CRF (constant quality factor) to 25 with H.265 was roughly equivalent to 20 with H.264, and both the compression ratio and encoding speed were greatly improved compared to default settings with a minor degradation in quality. If you happen to have a second generation Nvidia Maxwell graphics card you may want to check Nvidia Video Encoding SDK for speedier encoding.

All was good until I decided to upload a test video, and I soon discovered that neither YouTube nor Vimeo would support H.265 with the former ending the upload with “The video has failed to process. Please make sure you are uploading a supported file type.”. Back to the drawing board, and I decided to give VP9 a try using ffmpeg/avconv using instructions here and there.

My computer is running Ubuntu 14.04 LTS, but I also have a virtual machine with the latest Ubuntu version, in this case Ubuntu 15.10, and I tried in both.

First install avconv with


and check whether VP9 is enabled in

  • Ubuntu 15.10

  • Ubuntu 14.04 LTS


Ubuntu 15.10 has a more recent version of avconv with VP9, but Ubuntu 14.04, so I looked for a PPA for avconv, but did not find any, instead installed ffmpeg. avconv and ffmpeg are very similar, because although both are developed by separate teams, the former is a fork of the latter, and in the instructions below you can replace avconv by ffmpeg and vice-versa.

So here’s about to install a more recent version of ffmpeg in Ubuntu 14.04:


Once this is done, Ubuntu 14.04 also supports VP9 decoding and encoding.


I tested various VP9 (lipvpx) parameters, and encoding time varies greatly depending on the options.

The video sample, taken straight from my camera, is a 16-second MOV/H.264/1080p30 video recorded at about 45 Mbps and 97.5MB in size. I filmed a TV screen with some text as I though it might be easier to detect differences. When I used H.265 wit CRF 25 it took about 25 seconds in Handbrake with the resulting file being 7.6MB large.

After various trail and errors, I encoded the sample with two command lines, including one using -cpu-used 5 for faster encoding (over twice as fast), but lower quality:


The first one took 2 minutes 56 seconds (Video size: 4.1 MB), while the second was significantly faster, as it completed the task in 1 minute and 17 seconds (Video size: 4.3MB). I uploaded all three files to YouTube to let you guys compare the quality after upload. The videos need to be watched on a 16:9 screen (1920×1080 or greater) and at 1080p for proper comparison.

  • Original H.264 Camera Sample 1 (97.5 MB, ~ 44 Mbps video,  ~30 minutes upload)
  • Sample 1 encoded with VP9 at 2000 kbps (4.1 MB, ~2 minutes upload)
  • Sample 1 video encoded with VP9 at 2000 kbps wit cpu-used 5 option (4.3 MB, ~2 minutes upload)

I repeated the same test by with another video shot outdoors, and encoding to VP9 with cpu-used 5

  • Original H.264 Camera Sample 2 (26.2 MB, ~45 Mbps video, ~8 minutes upload):
  • Sample 2 video encoded with VP9 at 2000 kbps and cpu-used 5 option (1.6MB, ~25 seconds encoding, ~1 minute upload)

For some reasons, the camera samples from the camera were not as good as I would have expected, and even after YouTube processing the original camera samples look very similar to the original.

If you are not a big fan of the command line, you can also install Selene to encode VP9 video using a graphical user interface:


VP9 Encoding with Selene in Ubuntu 15.10 (Click to Enlarge)
VP9 Encoding with Selene in Ubuntu 15.10 (Click to Enlarge)

Once you start the program, click Add Files, select preset “WebM Video (webm), and click on the bottom right icon to adjust the preset settings such as codec (VP8/VP9), bitrate, and so on.  VP9 encoding in Ubuntu 14.04 did not work, even after install ffmpeg, as the program appears to only use avconv, but I did work in Ubuntu 15.10.

I selected VP9, variable bitrate, 2000 kbps and “best” speed at first, but I should have read the tooltips, as the encoding was done at about 0.3 fps in my machine (AMD FX8350 with 16GB RAM), and speed settings are described as below (with actual command show below):

  • Best: best quality, slower
  • Good: good quality, faster
  • Realtime:  good quality fastest

So the speed option in Selene is actually to modify deadline in avconv/ffmpeg, and the slider in the GUI is to adjust cpu-used from 0 to 5.

Any tips to improve encoding speed vs quality are more than welcome.

Support CNX Software - Donate via PayPal or become a Patron on Patreon

3
Leave a Reply

avatar
3 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
3 Comment authors
cnxsoftValdikSSCdan Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
Cdan
Guest
Cdan

VP9 is not optimized for home PC encoding, it is specifically tailored to encoding video across datacenter servers with large numbers of CPU’s in action, in other words Youtube’s own gear.

However in time it will hopefully be optimized better for home use particularly with VP10 if it becomes the defacto codec for Internet streaming media.

The reason H.265/HEVC is not supported is because the IP licensing around it is toxic, a group broke away from MPEG LA (H.264/H.265 license pool) and demanded outrageous fees for anyone streaming video over the internet. Some of the companies involved tried this many years ago with MPEG-4 ASP (DivX/XviD) and it killed that format dead as no one would use it other than pirates.

So big tech companies were spooked and have now sided with Google on VP10 being the next gen codec, H.265 will still be used in Blu-ray/TV but not internet media sites, those will remain H.264 until VP10 is ready.

ValdikSS
Guest
ValdikSS

You can use CRF encoding with vp9 too. Set bitrate to 0 and CRF to some value.:

-b:v 0 -crf 35