15

Recently I wanted to try out the Webm codecs VP8 and VP9 but when I ran ffmpeg to encode a H.264 MP4 file into one of the other two codecs, I realized that the encoding is (by almost an order of magnitude) slower.

A 1080p30 video from H.264 to VP9 at 3 MBit/s is being encoded at around 6-7 fps while the same video encodes at around 40 fps to H.264. I used the libvpx-vp9 codec in ffmpeg for the VP9 format. I am getting the same results for VP8 and Theora too.

Can someone explain to me why VP9 is so much slower? I tried a different machine which gave me similar resullts using Handbrake.

1
14

libvpx-vp9 is a much slower encoder than libx264 but the default settings of threads in ffmpeg (0=auto) is not effective for libvpx. Manually setting it gives a speed bump. e.g.

ffmpeg -i in.mp4 -c:v libvpx-vp9 -threads 4 out.mp4

On a 4-core machine, when encoding a 1080-30p H.264 stream, I get a bump from 3.8 fps to 10 fps.

3
  • One should also mention that there are different speed presets, i.e., -preset for libx264 and -speed for libvpx-vp9. See ffmpeg -h full. These can make quite a difference, but they also affect quality or compression efficiency.
    – slhck
    May 23 '17 at 7:10
  • 1
    I tried it on rather old machines but I did use 4 threads since both machines are quad-core. The -speed option didn't make a huge difference for me
    – comfreak
    May 23 '17 at 9:04
  • @comfreak See also: developers.google.com/media/vp9/the-basics
    – slhck
    May 23 '17 at 13:54
4

VP9 is a more more complex codec providing better compression. Video compression/performance ratio tends to be exponentially. You should expect the VP9 replacement (AV1) to be even slower.

5
  • 1
    So in other words, even though the codec "only" produces a relatively small size improvement, it may be much slower? Are the results I got representative?
    – comfreak
    May 23 '17 at 9:02
  • 1
    VP9 can be up to 50% more efficient in terms of quality, @comfreak. I wouldn't call that small. You can't just compare the resulting file size.
    – slhck
    May 23 '17 at 11:49
  • @slhck: So you are saying that 3MBit/s can encode more original information than H.264 and therefore a lower bit rate than the source material in H.264 might be an option to speed things up?
    – comfreak
    May 23 '17 at 13:48
  • 1
    @comfreak Using a lower bitrate will not automatically increase the speed of the encoding process. I'm just saying that there is a tradeoff between compression efficiency and speed, and many streaming providers for example would rather invest the CPU time to create higher quality streams at lower overall bitrate, to conserve space and bandwidth. Using more efficient codecs (like VP9 or HEVC over H.264) also helps in that regard.
    – slhck
    May 23 '17 at 13:54
  • But essentially, if speed is the most important factor for you, you should stick with older codecs (e.g., H.264), less compression-efficient presets, and perhaps also look into GPU-assisted encoding, e.g. with NVENC.
    – slhck
    May 23 '17 at 13:56

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.