From time to time, I like to record clips and videos of me and the guys playing video games. Also record a video or two when cycling. But what I don’t like is when my phone runs out of storage because the videos was recorded with the wrong codec.

Idea

I want to test 7 different codecs in this blog post.

  • H264 (mp4)
  • H265 (mp4)
  • VP9 (webm)
  • AV1 (mp4)
  • Theora (ogg)
  • MPEG-1 (mpeg)
  • MPEG-2 (mpeg)

MPEG-1, 2 and Theora I added as a joke.

The plan:

  • Use ffmpeg
  • Have a base video
  • Re-encode the video to the different codecs.
  • Write down the time it took to re-incode, and the size of the output file.

The Setup

My hardware is pretty basic now-a-days, but still pretty powerfull for what it is.

  • OS: Fedora Linux 40 (Workstation Edition) x86_64
  • Kernel: Linux 6.9.8-200.fc40.x86_64
  • CPU: AMD Ryzen 9 3950X (32) @ 3.50 GHz
  • GPU: NVIDIA GeForce RTX 2070
  • Memory: 62.70 GiB

The video to be re-incoded is big_buck_bunny_480p_h264.mov . I have chosen the 480p resolution, since I don’t want to wait a month before all videos has been encoded.

The Numbers

Notice: The container used will have an impact on filesize and speed, but since some codecs don’t support some containers, and can’t really benchmark the impact of the container. I have also not chosen a preset for the encodings. Presets suchs as realtime and very slow can impact the file size by quite a bit. perhapse I test this at another date.

The benchmark is very simple. For convinience, I rename the original video to original_480p_H264.mov. I run this command:

time ffmpeg -i original_480p_H264.mov -ss 0 -t 60 -vf "pad=ceil(iw/2)*2:ceil(ih/2)*2" -c:v libx264 -b:v 2900k 480p_h264.mov

I use -ss 0 -t 60 to only encode the first minut of the video, since I don’t want to wait for a month for my computer to be done. Plus it’s a nice number, easy to compare with.

I use -vf "pad=ceil(iw/2)*2:ceil(ih/2)*2" since ffmpeg will complain about the height not being devisible by 2. So Padding it fixes the issue.

I use -b:v 2900k to encode the video with the same bitrate as the original file.

Codec Bitrate Size Time To Encode Libraries
H264 2900k 23Mb 0m8s libx264
H265 2900k 23Mb 0m47s libx265
AV1 2900k 21Mb 0m10s libsvtav11
AV1 2900k 23Mb 19m5s librav1e2
VP9 2900k 86Mb 6m56s libvpx-vp9
Theora 2900k 22Mb 0m47s libtheora
MPEG-1 2900k 24Mb 0m1.7s mpeg1video
MPEG-2 2900k 24Mb 0m1.7s mpeg2video

Conclusion

The Short Version

For now, just use H265.

The Slightly Longer Version

AV1 (with libsvtav1) shows the most promise in terms of speed/size ratio, but it’s still too early to come to any conclusion on AV1. AV1 came out in 2018, and the latest update came out in 20193. H265 came out in 2013, and the latest update came out in 20234. Having the codec be more mature is more important to me, than a 2Mb difference.

I have no idea why VP9 has that big of a filesize, since it should compare really well with H265. MPEG-1 and 2 doesn’t look great in terms of visual quality. You also have to remember that MPEG-1 and 2 are really old and quite outdated. Theora is the one that looks the worst, by far. Plus Theora is also quite outdated.

mediainfo big_buck_bunny_480p_h264.mov

General
Complete name                            : big_buck_bunny_480p_h264.mov
Format                                   : MPEG-4
Format profile                           : QuickTime
Codec ID                                 : qt   2005.03 (qt  )
File size                                : 238 MiB
Duration                                 : 9 min 56 s
Overall bit rate                         : 3 343 kb/s
Frame rate                               : 24.000 FPS
Encoded date                             : 2008-05-27 18:32:32 UTC
Tagged date                              : 2008-05-27 18:33:17 UTC
Writing library                          : Apple QuickTime 7.4.1
com.apple.quicktime.player.movie.audio.g : 1.000
com.apple.quicktime.player.movie.audio.t : 0.000
com.apple.quicktime.player.movie.audio.b : 0.000
com.apple.quicktime.player.movie.audio.b : 0.000
com.apple.quicktime.player.movie.audio.p : 0.000
com.apple.quicktime.player.movie.audio.m : (Binary)
com.apple.quicktime.player.movie.visual. : 0.000
com.apple.quicktime.player.movie.visual. : 1.000
com.apple.quicktime.player.movie.visual. : 0.000
com.apple.quicktime.player.movie.visual. : 1.000

Video
ID                                       : 1
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : Main@L3
Format settings                          : 2 Ref Frames
Format settings, CABAC                   : No
Format settings, Reference frames        : 2 frames
Format settings, GOP                     : M=2, N=24
Format settings, Slice count             : 5 slices per frame
Codec ID                                 : avc1
Codec ID/Info                            : Advanced Video Coding
Duration                                 : 9 min 56 s
Bit rate                                 : 2 900 kb/s
Width                                    : 853 pixels
Original width                           : 854 pixels
Height                                   : 480 pixels
Display aspect ratio                     : 16:9
Frame rate mode                          : Constant
Frame rate                               : 24.000 FPS
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
Bits/(Pixel*Frame)                       : 0.295
Stream size                              : 206 MiB (87%)
Language                                 : English
Encoded date                             : 2008-04-21 23:33:24 UTC
Tagged date                              : 2008-05-27 18:33:17 UTC
Color range                              : Limited
Color primaries                          : BT.709
Transfer characteristics                 : BT.709
Matrix coefficients                      : BT.709
Codec configuration box                  : avcC

Audio
ID                                       : 4
Format                                   : AAC LC
Format/Info                              : Advanced Audio Codec Low Complexity
Codec ID                                 : mp4a-40-2
Duration                                 : 9 min 56 s
Source duration                          : 9 min 56 s
Bit rate mode                            : Constant
Bit rate                                 : 448 kb/s
Channel(s)                               : 6 channels
Channel layout                           : C L R Ls Rs LFE
Sampling rate                            : 48.0 kHz
Frame rate                               : 46.875 FPS (1024 SPF)
Compression mode                         : Lossy
Stream size                              : 31.1 MiB (13%)
Source stream size                       : 31.1 MiB (13%)
Language                                 : English
Encoded date                             : 2008-05-27 18:30:18 UTC
Tagged date                              : 2008-05-27 18:33:17 UTC

Other
ID                                       : 2
Type                                     : Time code
Format                                   : QuickTime TC
Duration                                 : 9 min 56 s
Frame rate                               : 24.000 FPS
Time code of first frame                 : 00:00:00:00
Time code of last frame                  : 00:09:56:10
Time code, stripped                      : Yes
Language                                 : English
Encoded date                             : 2008-04-21 23:33:24 UTC
Tagged date                              : 2008-05-27 18:33:17 UTC

Footnotes


  1. libsvtav1 is the current adopted library for encoding AV1 for future development. Plus it’s also the most performant from my benchmark. ↩︎

  2. librav1e is another AV1 library, but from Xiph. It claims to be the fastest, but considering the benchmark, I don’t think the claims holds true. But then again, it depends on the settings. ↩︎

  3. https://en.wikipedia.org/wiki/AV1 ↩︎

  4. https://en.wikipedia.org/wiki/High_Efficiency_Video_Coding ↩︎