|
|
Line 39: |
Line 39: |
| = AV1 Codec Testing = | | = AV1 Codec Testing = |
| | | |
− | [[AV1 Codec Testing]] | + | I decided this section would be cleaner if I put it on its own page: [[AV1 Codec Testing]] |
− | | |
− | <i>Last updated 3/11/2020</i>
| |
− | | |
− | AV1 is the newest emerging video coding format currently under development by AOMedia. I was interested in trying it out and seeing how it compares to my current favorite x265, and also the older x264. Keep in mind I'm doing this for my own purposes, so the following benchmarks are not comprehensive and are limited to my own intended use cases.
| |
− | | |
− | The AV! ligrary <code>libaom-av1</code> is not currently available in ffmpeg by default. I found a good script someone made for compiling ffmpeg with support for AV1:
| |
− | https://gist.github.com/sparrc/026ed9958502072dda749ba4e5879ee3
| |
− | | |
− | I downloaded the script:
| |
− | <source>
| |
− | wget https://gist.githubusercontent.com/sparrc/026ed9958502072dda749ba4e5879ee3/raw/e22698ead1984cd86b943f3473bd4bfb98591808/install-ffmpeg.sh
| |
− | </source>
| |
− | <i>Note: as always, never download and run a script without reading it yourself to determine that it dos not do anything malicious.</i>
| |
− | | |
− | I ran the script:
| |
− | <source>
| |
− | sudo bash install-ffmpeg.sh
| |
− | </source>
| |
− | | |
− | this script installs the custom ffmpeg into <code>~/bin/ffmpeg</code>.
| |
− | | |
− | I chose a relatively small MTS file for testing:
| |
− | <source>
| |
− | du -h 00056.MTS
| |
− | </source>
| |
− | <pre class="out">
| |
− | 38M 00056.MTS
| |
− | </pre>
| |
− | | |
− | === Runtime Benchmarks (Interlacing) ===
| |
− | | |
− | In the following benchmarks, the relevant time is the "real" time. The original test MTS file is encoded with video:h264, audio:ac3, and has interlacing. Each encoding process I do below uses all defaults for the format, and encodes the audio to aac.
| |
− | | |
− | ==== x264 benchmark ====
| |
− | <source>
| |
− | time ~/bin/ffmpeg -loglevel -8 -i 00056.MTS -c:v libx264 out_x264.mp4
| |
− | </source>
| |
− | <pre class="out">
| |
− | real 0m28.159s
| |
− | user 1m43.388s
| |
− | sys 0m0.176s
| |
− | </pre>
| |
− | | |
− | ==== x265 benchmark ====
| |
− | <source>
| |
− | time ~/bin/ffmpeg -loglevel -8 -i 00056.MTS -c:v libx265 out_x265.mp4
| |
− | </source>
| |
− | <pre class="out">
| |
− | real 0m43.420s
| |
− | user 2m40.852s
| |
− | sys 0m0.304s
| |
− | </pre>
| |
− | | |
− | ==== av1 benchmark ====
| |
− | <source>
| |
− | time ~/bin/ffmpeg -loglevel -8 -i 00056.MTS -c:v libaom-av1 -strict -2 out_av1.mp4
| |
− | </source>
| |
− | <pre class="out">
| |
− | real 177m27.737s
| |
− | user 413m16.620s
| |
− | sys 0m6.688s
| |
− | </pre>
| |
− | <i>Note: The "-strict -2" parameter allows for the use of experimental codecs.</i>
| |
− | | |
− | ==== Conclusion ====
| |
− | | |
− | As you can see, the AV1 encoding took orders of magnitude longer.
| |
− | * x264 = 28 seconds
| |
− | * x265 = 43 seconds
| |
− | * AV1 = 2 hours, 57 minutes, 27 seconds
| |
− | | |
− | | |
− | === Runtime Benchmarks (De-Interlacing) ===
| |
− | | |
− | In the following benchmarks, I decided to include de-interlacing.
| |
− | | |
− | ==== x264 benchmark (de-interlacing) ====
| |
− | <source>
| |
− | time ~/bin/ffmpeg -loglevel -8 -i 00056.MTS -vf yadif -c:v libx264 outd_x264.mp4
| |
− | </source>
| |
− | <pre class="out">
| |
− | real 0m29.251s
| |
− | user 1m47.480s
| |
− | sys 0m0.260s
| |
− | </pre>
| |
− | | |
− | ==== x265 benchmark (de-interlacing) ====
| |
− | <source>
| |
− | time ~/bin/ffmpeg -loglevel -8 -i 00056.MTS -vf yadif -c:v libx265 outd_x265.mp4
| |
− | </source>
| |
− | <pre class="out">
| |
− | real 0m42.207s
| |
− | user 2m34.120s
| |
− | sys 0m0.328s
| |
− | </pre>
| |
− | | |
− | ==== av1 benchmark (de-interlacing) ====
| |
− | <source>
| |
− | time ~/bin/ffmpeg -loglevel -8 -i 00056.MTS -vf yadif -c:v libaom-av1 -strict -2 outd_av1.mp4
| |
− | </source>
| |
− | <pre class="out">
| |
− | real 162m54.203s
| |
− | user 377m0.452s
| |
− | sys 0m4.940s
| |
− | </pre>
| |
− | | |
− | ==== Conclusion ====
| |
− | | |
− | The times are not significantly different from my first test that included interlacing, but interestingly choosing to de-interlace marginally reduced the runtime in every test.
| |
− | * x264 = 29 seconds
| |
− | * x265 = 42 seconds
| |
− | * AV1 = 2 hours, 42 minutes, 54 seconds
| |
− | | |
− | === File Size Comparison ===
| |
− | | |
− | The files starting with <code>out_</code> are interlaced, and <code>outd_</code> are de-interlaced.
| |
− | | |
− | <source>
| |
− | du -h out_*;du -h outd*
| |
− | </source>
| |
− | <pre class="out">
| |
− | 11M out_av1.mp4
| |
− | 15M out_x264.mp4
| |
− | 5.6M out_x265.mp4
| |
− | 8.2M outd_av1.mp4
| |
− | 13M outd_x264.mp4
| |
− | 4.1M outd_x265.mp4
| |
− | </pre>
| |
− | | |
− | ==== Conclusion ====
| |
− | | |
− | The best codec for file size, by a pretty large margin, is still x265. De-interlacing also results in smaller file size for all codecs.
| |
− | | |
− | === Video Quality Comparison ===
| |
− | | |
− | In this test, I will take a cropped portion of the same frame from each file so that I can visually compare them.
| |
− | | |
− | I used <code>ffmpeg</code> to extract the 10th frame from each file:
| |
− | <source lang="sh">
| |
− | for x in *.{MTS,mp4};do ffmpeg -i $x -vf "select=eq(n\,9)" -vframes 1 $x.png;done
| |
− | </source>
| |
− | <i>Note: the "select" parameter takes a sequence starting at 0, so the 10th frame is 9.</i>
| |
− | | |
− | I thought it was notable to look at the different in file size of the images:
| |
− | <source>
| |
− | du -h *.png
| |
− | </source>
| |
− | <pre class="out">
| |
− | 2.9M 00056.MTS.png
| |
− | 2.1M out_av1.mp4.png
| |
− | 2.0M outd_av1.mp4.png
| |
− | 2.4M outd_x264.mp4.png
| |
− | 2.1M outd_x265.mp4.png
| |
− | 2.4M out_x264.mp4.png
| |
− | 2.2M out_x265.mp4.png
| |
− | </pre>
| |
− | | |
− | I then cropped a portion of each image starting at pixels X=0,y=250 with a size of 500x300. To do this automatically, it used the Imagemagick <code>convert</code> command:
| |
− | <source lang="sh">
| |
− | for x in *.png;do convert $x -crop 500x300+0+250 ${x/\.png/_crop\.png};done
| |
− | </source>
| |
− | | |
− | ==== Image Comparison ====
| |
I've seen very good quality and significantly smaller file sizes in videos encoded with H.265.
ffmpeg -i infile.mp4 -c:v libx265 outfile.mp4
ffmpeg -i 000000.MTS -vf yadif -c:v libx265 outfile.mp4
In the terminal, go into your folder full of images.
neuro@gamma:~/timelapse$ ls
DSC05145.JPG DSC05163.JPG DSC05181.JPG DSC05199.JPG DSC05217.JPG
DSC05146.JPG DSC05164.JPG DSC05182.JPG DSC05200.JPG DSC05218.JPG
DSC05147.JPG DSC05165.JPG DSC05183.JPG DSC05201.JPG DSC05219.JPG
DSC05148.JPG DSC05166.JPG DSC05184.JPG DSC05202.JPG DSC05220.JPG
...
ffmpeg -r 20 -f image2 -pattern_type glob -i "*.JPG" -c:v libx265 ../out.mp4
ffmpeg -r 20 -f image2 -start_number 05200 -i DSC%05d.JPG -frames:v 30 -c:v libx265 ../out.mp4