0

I tried to encode mp4 4K with H.264 format to webm format using ffmpeg libvpx, I need to convert them to multi resolution 1080p - 144p. I was run following command :

ffmpeg -i  source-4K.h264.mp4  -c:v libvpx-vp9 -s hd720 -b:v 1500k -keyint_min 150 -g 150 -tile-columns 4 -frame-parallel 1 -an -f webm -dash 1 out-hd720.webm

and I found that video from 360p and above are slowly processed, so I am thinking to use nvidia card (P4 card on Google Cloud) to accelerate the process. but I haven't found any articles / resources nor command to do video encoding using libvpx with hardware acceleration.

4

Libvpx has no hardware encoding or acceleration support of any kind, it's purely a software implementation. There are some VP9 hardware encoders out there but they're few in number and neither Nvidia or AMD have one. However, if you have an Intel CPU from the Skylake architecture or newer you should be able to use Intel's QuickSync hardware encoder built into their CPUs. I don't have the hardware to test it and don't know which OS you're on, but to use it on Linux I think you'd do something like this: ffmpeg -vaapi_device /dev/dri/renderD128 -i 16.mov -vf 'format=nv12,hwupload' -c:v vp9_vaapi -g 150 -bf 4 -compression_level 1 -bsf:v vp9_raw_reorder,vp9_superframe -b:v 15M -an 16_vp9.webm

You may find that the quality leaves much to be desired which is often the case with hardware encoders, most of them are built for speed over quality. So a better approach might be tuning libvpx for faster encoding. For starters you should use -row-mt 1 to enable row-based multithreading which can speed up encoding quite a bit, especially at higher resolutions and when you have lots of cores/threads available. Next you might want to adjust the encoding speed for HD resolution videos by setting -cpu-used 2. This is similar to x264's -preset option and it adjusts the speed/efficiency tradeoff. The default in FFmpeg is 1 which is the slowest most people would want to go; 0 basically triples the encoding time.

Depending on how old your version of FFmpeg and libvpx are, you might also want to set the number of encoding threads manually. I'm not sure which version of FFMpeg or libvpx changed this, but in the past you had to set your -threads by hand or else FFmpeg would only use a single thread for encoding. Also, the -frame-parallel option was removed from libvpx quite some time ago. It's ignored in the libvpx code so there's no detriment to using it, but it offers no benefit either.

I also recommend checking out Google's VP9 Encoding Guide. It's a pretty good reference on which parameters and bitrates you might want to use for different resolutions.

  • Can I ask you something about your recent edit on the FFmpeg wiki regarding libvpx? Your edit says -speed 4 in the first pass is actually detrimental, yet it's mentioned in the Google documentation here). But I guess the latter is simply incorrect? (I haven't yet verified running the commands.) – slhck Jan 30 at 19:21
  • VP9 encoding was only added in Kaby Lake. – mirh Nov 24 at 12:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.