Skip to content

Commit

Permalink
Vp8 (#97)
Browse files Browse the repository at this point in the history
* Adding some vp8 tests, still a WIP.

Signed-off-by: [email protected] <[email protected]>

* We dont actually need the yml file for a still.

Signed-off-by: [email protected] <[email protected]>

* Remove irrevelant table.

Signed-off-by: [email protected] <[email protected]>

* Fix links

Signed-off-by: [email protected] <[email protected]>

* Updated VP9 section

Signed-off-by: [email protected] <[email protected]>

* Adding very basic rav1e test.

Signed-off-by: [email protected] <[email protected]>

* Minor update to rav1, in testing its not great.

Signed-off-by: [email protected] <[email protected]>

* Update with arnr-strength.

Signed-off-by: [email protected] <[email protected]>

* Minor tweaks to vp8 setup.

Signed-off-by: Sam Richards <[email protected]>

* -qscale 3 does not map to 90% compression.

Signed-off-by: [email protected] <[email protected]>

* Adding a graph for preset.

Signed-off-by: [email protected] <[email protected]>

* Added a codec web test page to test a variety of codecs.

Signed-off-by: [email protected] <[email protected]>

* Fixes to make it legal html.

Signed-off-by: [email protected] <[email protected]>

* Make sure the labels are right.

Signed-off-by: [email protected] <[email protected]>

* Adding more tests, that were used in the ASWF open source days presentation.

Signed-off-by: [email protected] <[email protected]>

* Add a note about alpha for vp9.

Signed-off-by: [email protected] <[email protected]>

* Add a crf value for the quickstart.

Signed-off-by: [email protected] <[email protected]>

* Adding VP8 Docs.

Signed-off-by: [email protected] <[email protected]>

* Changing the preset to 5 from 9, addresses some artifacts.

Signed-off-by: [email protected] <[email protected]>

* Defining the column ordering of the graphs.

Signed-off-by: [email protected] <[email protected]>

---------

Signed-off-by: [email protected] <[email protected]>
Signed-off-by: Sam Richards <[email protected]>
Co-authored-by: [email protected] <[email protected]>
  • Loading branch information
richardssam and SamRichardsDisney authored Jul 27, 2024
1 parent 0e325f3 commit 2821106
Show file tree
Hide file tree
Showing 82 changed files with 5,645 additions and 59 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,5 @@ enctests/sources/enc_sources/chimera_wind
enctests/results.old
tmp
enctests/wedge_results
framerate/circle_grad/jpg
framerate/circle_grad/png
31 changes: 19 additions & 12 deletions EncodeAv1.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@ It has a more limited support for pix-formats currently only supporting: yuv420p

Supported pixel formats: yuv420p yuv420p10le

Color modes -

| main | 8 or 10 bit | 4:2:0 |
| high | 8 or 10 bit | 4:2:0 or 4:4:4 |
| professional | 8 or 10 or 12 bit | 4:2:0 4:2:2 or 4:4:4 |

Example encoding:

<!---
Expand All @@ -59,15 +53,15 @@ comparisontest:
-->
```
ffmpeg -r 24 -start_number 1 -i inputfile.%04d.png -frames:v 200 -c:v libsvtav1 \
-pix_fmt yuv420p10le -crf 18 -preset 9 -svtav1-params tune=0 -sws_flags lanczos \
-pix_fmt yuv420p10le -crf 18 -preset 5 -svtav1-params tune=0 -sws_flags lanczos \
-vf "scale=in_range=full:in_color_matrix=bt709:out_range=tv:out_color_matrix=bt709" \
-color_range tv -colorspace bt709 -color_primaries bt709 -color_trc iec61966-2-1\
-y outputfile.mp4
```

| --- | --- |
| **-crf 18** | This is the constant rate factor, controlling the default quality in the range 0-63. By default this is set to 50, which is a little on the low side, using values closer to 18 is recommended, but this does come at the expense of file-size. For more on this see the [CRF comparison](#crf-comparison-for-libsvtav1) below. |
| **-preset 9** | Help with a trade-off between encoding speed and compression efficiency. Supported preset range in the 0-13. See below for comparisons |
| **-preset 5** | Help with a trade-off between encoding speed and compression efficiency. Supported preset range in the 0-13. See below for comparisons |

See also:
* [SVT-AV1 ffmpeg](https://gitlab.com/AOMediaCodec/SVT-AV1/-/blob/master/Docs/Ffmpeg.md)
Expand All @@ -85,6 +79,14 @@ To help pick appropriate values with the CRF flag, we have run the [Test Framewo

### Preset values for libsvtav1

| ![](enctests/reference-results/av1-preset-test-encode_time.png) This is showing preset values against encoding time. |
| ![](enctests/reference-results/av1-preset-test-filesize.png) This is showing preset values against file size. |
| ![](enctests/reference-results/av1-preset-test-vmaf_harmonic_mean.png) This is showing preset values against VMAF harmonic mean |
| ![](enctests/reference-results/av1-preset-test-psnr_y_harmonic_mean.png) This is showing preset values against PSNR harmonic mean |

These graphs are with a CRF of 15 for four different media clips, its showing that the preset values are affecting the amount of compression, but not affecting the quality of the result, at the expense of the encoding time (at least up to preset 9).


See: [SVT-AV1 Common Questions](https://gitlab.com/AOMediaCodec/SVT-AV1/-/blob/master/Docs/CommonQuestions.md)


Expand Down Expand Up @@ -115,6 +117,10 @@ ffmpeg -r 24 -start_number 1 -i inputfile.%04d.png -frames:v 200 -c:v libaom-av1
| -cpu-used 6 | This sets how efficient the compression will be. The default is 1, changing this will increase encoding speed at the expense of having some impact on quality and rate control accuracy. Values above 6 are reset to 6 unless real-time encoding is enabled. See below for comparison. |
| -row-mt 1 | This enables row based multi-threading (see [here](https://trac.ffmpeg.org/wiki/Encode/VP9#rowmt)) which is not enabled by default. |
| -usage allintra | Encodes for all intra-frames |
| -arnr-strength | This decreases the amount of noise reduction you get, setting it to 1 helps preserve grain, and some noisy pictures |
| -aom-params: tune-content=film | There is a tune parameter, but it just seems to make the picture grainy, and is not recommended |

Libaom has an aggressive denoiser, which can be pretty good for animated media, but can be a problem for live-action, particularly if there is noisy content, such as water or particles. CRF needs to be lowered to counter this, which does affect encoding speed.

### cpu-speed Comparison for libaom-av1

Expand All @@ -129,13 +135,14 @@ To help pick appropriate values with the cpu-speed flag, we have run the [Test F

See Also - note these are all guides for AOMENC (the AOM encoder that is part of libaom), but many of the parameters map to ffmpeg:
* [A 2nd generation guide to aomenc-av1](https://forum.doom9.org/showthread.php?t=183906)
* [Making aomenc-AV1/libaom-AV1 the best it can be in a sea of uncertainty]((https://old.reddit.com/r/AV1/comments/lfheh9/encoder_tuning_part_2_making_aomencav1libaomav1/)
* https://github.com/master-of-zen/Av1an/blob/master/docs/Encoders/aomenc.md
* [Making aomenc-AV1/libaom-AV1 the best it can be in a sea of uncertainty](https://old.reddit.com/r/AV1/comments/lfheh9/encoder_tuning_part_2_making_aomencav1libaomav1/)
* [Av1an](https://master-of-zen.github.io/Av1an/Encoders/aomenc.html)
* [AV1 Codec Wiki](https://wiki.x266.mov/docs/encoders/aomenc)

## librav1e
[librav1e](https://github.com/xiph/rav1e) is the Xiph encoder for AV1.
[librav1e](https://github.com/xiph/rav1e) is the Xiph encoder for AV1, written in rust.

Supported pixel formats:
yuv420p yuvj420p yuv420p10le yuv420p12le yuv422p yuvj422p yuv422p10le yuv422p12le yuv444p yuvj444p yuv444p10le yuv444p12le

There is no CRF flag, so we are ignoring this for now, but it could be promising down the road.
There is no CRF flag, so you use the -gp flag, the recommended starting point is about 100. However, we have been unable to get an substantial speed improvement over AOM.
28 changes: 22 additions & 6 deletions EncodeMJPEG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ parent: Codec Comparisons

# MJPEG - Motion JPEG

[Motion JPEG](https://en.wikipedia.org/wiki/Motion_JPEG) has historically been quite common in the VFX industry, and is part of the default quicktime codecs, so is well supported on players, although not typically supported in web browsers.
[Motion JPEG](https://en.wikipedia.org/wiki/Motion_JPEG) has historically been quite common in the VFX industry, and is part of the default Quicktime codecs, so is well supported on players, although not typically supported in web browsers.

While it does compress quickly, and maintains its quality fairly well, we would recommend other codecs at higher bit-depths such as vp9, h264 or h265 (or even Prores or DNxHD), which will also compress better than mjpeg.



## MJPEG

mjpeg has a limited range of pixel formats:
Expand All @@ -35,15 +33,15 @@ comparisontest:
-->
```
ffmpeg -r 24 -start_number 1 -i inputfile.%04d.png -frames:v 200 \
-c:v mjpeg -qscale:v 4 outputfile.mov
-c:v mjpeg -qscale:v 2 outputfile.mov
```


## Recomended Flags
## Recommended Flags

| --- | --- |
| **-qscale:v 3** | This is the compression factor, which goes from 2 to 31 where 2 is the best quality. |
| **-qscale:v 2** | This is the compression factor, which goes from 2 to 31 where 2 is the best quality. See alternative approach for better encoding. |


### qscale:v Comparison
Expand All @@ -54,3 +52,21 @@ Below is a comparison of different Qscale rates
| ![](enctests/reference-results/mjpeg-qscale-tests-filesize.png) This is showing qscale:v values against file size. |
| ![](enctests/reference-results/mjpeg-qscale-tests-vmaf_harmonic_mean.png) This is showing qscale:v values against VMAF harmonic mean |
| ![](enctests/reference-results/mjpeg-qscale-tests-psnr_y_harmonic_mean.png) This is showing qscale:v values against PSNR-Y harmonic mean |

## Alternative approach

You can generate the individual jpeg files using another tool, and then use ffmpeg to stitch them together. For example, to convert a series of png frames to jpeg, you can use oiiotool:
```
oiiotool -v --parallel-frames -i PNGFILES.%05d.png --compression jpeg:95 -o JPEGFILES.%05d.jpg
```
and then stitch them together with:
```
ffmpeg -f image2 -r 24 -i JPEGFILES.%05d.jpg -vcodec copy outputfile.mov
```

This gives you more fine grain control over the quality setting, although it gives you less control over the jpeg compression, since it will always be YUV420, where you do get more control with ffmpeg.
Its actually hard to get an exact mapping between the ffmpeg -qscale setting and the jpeg quality. The highest ffmpeg setting is 2, and that roughly maps to a jpeg quality setting of 86%.
So if you require higher quality than 86% then use this approach. Settings below 95% do produce artifacts, so this is the recommended approach if you *have* to do this, a 10-bit encoder would be better though.

Below shows a comparison of jpeg compression to filesize for a HD sized image sequence of 200 frames.
![](enctests/reference-results/mjpeg-compression-tests-filesize.png)
90 changes: 90 additions & 0 deletions EncodeVP8.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
---
layout: default
nav_order: 4.5
title: VP8 Encoding
parent: Codec Comparisons
---

# VP8

VP8 is an open-source and royalty free codec developed by the [Alliance for Open Media](https://trac.ffmpeg.org/wiki/Encode/VP8) (AOMedia), a non-profit industry consortium. It will only encode to 8-bit 4:2:0 using the webm container. It is possible to get a similar quality to h264, but not typically at the same compression ratio. It is recommended that you consider [VP9](EncodeVP9.html) which is a considerably better codec. VP8 does support an alpha channel (via the yuva420p pixfmt).

General ffmpeg info on VP8 is [here](https://trac.ffmpeg.org/wiki/Encode/VP8), and on the encoder in general [https://www.webmproject.org/docs/encoder-parameters/](https://www.webmproject.org/docs/encoder-parameters/).

VP8 has browser support in:
* Chrome.
* Edge
* Firefox
* Opera

VP8 is supported by mkv and webm containers, no support exists for mov or mp4.

## libvpx

libvpx has a limited range of pixel formats:
yuv420p yuva420p


Example encoding:

<!---
name: test_vp8
sources:
- sourceimages/chip-chart-1080-16bit-noicc.png.yml
comparisontest:
- testtype: idiff
compare_image: ../sourceimages/chip-chart-1080-16bit-noicc-yuv420p10le.png
- testtype: assertresults
tests:
- assert: less
value: max_error
less: 0.00195
-->
```
ffmpeg -r 24 -start_number 1 -i inputfile.%04d.png -frames:v 200 \
-c:v libvpx -crf 20 -b:v 200M -pix_fmt yuv420p \
-qmin 0 -qmax 50 -quality good -speed 4 \
-sws_flags spline+accurate_rnd+full_chroma_int \
-vf "scale=in_range=full:in_color_matrix=bt709:out_range=tv:out_color_matrix=bt709" \
-color_range tv -colorspace bt709 -color_primaries bt709 -color_trc iec61966-2-1 \
-y outputfile.webm
```



## Recommended Flags

```
-crf 20 -quality good -b:v 200M -speed 4
```

| --- | --- |
| **-crf 20** | This is the constant quality rate factor, controlling the default quality, similar to h264. The range is a little different to h264, so you may need to test. |
| *-quality good* | May require additional testing, but so far switching to *-quality best* increased the duration, but didn't increase the VMAF score (which is already pretty high with these values of crf). |
| -b:v 200M | Unlike with h264, and vp9 you need to set the bit rate, but you can set it to a high number, and this is the max it would be. |
| -speed 4 | It sets how efficient the compression will be. Unless you are using -quality best, this doesnt seem to have a setting for |

Its possible you might want to change the [GOP](https://aws.amazon.com/blogs/media/part-1-back-to-basics-gops-explained/#:~:text=Simply%20put%2C%20a%20GOP%20is,30%20frames%2C%20or%201%20second.) values (changed with the -g flag), since the default is 240 frames.


### CRF Comparison

Below is a comparison of different CRF rates, with -b:v 200M and -quality good



| ![](enctests/reference-results/vp8-crf-test-encode_time.png) This is showing CRF values against encoding time. |
| ![](enctests/reference-results/vp8-crf-test-filesize.png) This is showing CRF values against file size. |
| ![](enctests/reference-results/vp8-crf-test-vmaf_harmonic_mean.png) This is showing CRF values against VMAF harmonic mean |
| ![](enctests/reference-results/vp8-crf-test-psnr_y_harmonic_mean.png) This is showing CRF values against psnr y harmonic mean |

### Speed Comparison

Below is a comparison of different speed rates, -quality good vs. -quality best and with -crf 22, -b:v 200M.

This shows that with -quality good the filesize doesnt vary, but with increasing speed settings the encoding time goes down.

| ![](enctests/reference-results/vp8-speed-tests-encode_time.png) This is showing speed against encoding time. |
| ![](enctests/reference-results/vp8-speed-tests-filesize.png) This is showing speed values against file size. |
| ![](enctests/reference-results/vp8-speed-tests-vmaf_harmonic_mean.png) This is showing speed values against VMAF harmonic mean |
| ![](enctests/reference-results/vp8-speed-tests-psnr_y_harmonic_mean.png) This is showing speed values against psnr y harmonic mean |
5 changes: 3 additions & 2 deletions EncodeVP9.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ VP9 has browser support in:
* Safari - works for 8-bit and 10-bit but fails on 10-bit 444 and 12-bit RGB.

VP9 is supported by mp4 and webm containers, no support exists for mov.
VP9 does support an alpha channel (via the yuva420p pixfmt).

Outside of the web browser, VP9 support is pretty much limited to Davinci Resolve, Houdini, Blender, ffmpeg and VLC.
Outside of the web browser, VP9 support is pretty much limited to Davinci Resolve (Mac R/W, windows Read-only), Houdini, Blender, ffmpeg and VLC.

The two codecs we will cover are:
* [libvpx-vp9](#libvpx-vp9)
Expand Down Expand Up @@ -58,7 +59,7 @@ ffmpeg -r 24 -start_number 1 -i inputfile.%04d.png -frames:v 200 -c:v libvpx-vp9



## Recomended Flags
## Recommended Flags

```
-crf 22 -quality good -b:v 0 -speed 2 -row-mt 1
Expand Down
2 changes: 1 addition & 1 deletion Quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ comparisontest:
```console
ffmpeg -r 24 -start_number 1 -i inputfile.%04d.png -pix_fmt yuv420p \
-vf "scale=in_color_matrix=bt709:out_color_matrix=bt709" \
-frames:v 100 -c:v libx264 -preset slower \
-frames:v 100 -c:v libx264 -preset slower -crf 18 \
-color_range tv -colorspace bt709 -color_primaries bt709 -color_trc iec61966-2-1 \
-movflags faststart outputfile.mp4
```
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ The main wiki page for this for now is [here](https://wiki.aswf.io/pages/viewpag
3. [AV1](EncodeAv1.html)
4. [HEVC/H.265](EncodeHevc.html)
5. [MJPEG](EncodeMJPEG.html)
6. [VP8](EncodeVP8.html)
6. [VP9](EncodeVP9.html)
7. [DNxHD](EncodeDNXHD.html)
7. [Metadata NCLC/NCLX](ColorPreservation.html#nclc)
Expand Down
2 changes: 1 addition & 1 deletion compare.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
}} );
</script>
</head>
<a href="/EncodingGuidelines">Testing Home</a>
<a href="/">Testing Home</a>
<body style="background-color:rgb(65 65 65); color:rgb(200,200,200); ">
<div id="header_wrap" class="outer">
<header class="inner main-content"">
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions enctests/test_configs/swsscale_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ test_sws:
name: test_sws
sources:
# - ../sourceimages/smptehdbars_10.dpx.yml
- ../sourceimages/zoneplate_rgb16.png.yml
- ../sourceimages/zoneplate_rgb16.png
- ../sourceimages/bellnuitHDTestchart.tif
- ../sourceimages/SonyF35.StillLife_srgb.png
- sources/hdr_sources/sparks_srgb/sparks_srgb.06201.png
Expand Down Expand Up @@ -72,7 +72,7 @@ test_oiio:
name: test_oiio
sources:
# - ../sourceimages/smptehdbars_10.dpx.yml
- ../sourceimages/zoneplate_rgb16.png.yml
- ../sourceimages/zoneplate_rgb16.png
- ../sourceimages/bellnuitHDTestchart.tif
- ../sourceimages/SonyF35.StillLife_srgb.png
- sources/hdr_sources/sparks_srgb/sparks_srgb.06201.png
Expand Down
53 changes: 53 additions & 0 deletions enctests/test_configs/vp8_color_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
test_vp8_color_420:
app: ffmpeg
comparisontest:
- testtype: idiff
compare_image: ../sourceimages/chip-chart-1080-16bit-noicc-yuv420p10le.png
- testtype: assertresults
tests:
- assert: less
value: max_error
less: 0.00195
description: vp9 color tests of different pix-fmts
encoding_template: ffmpeg -y {input_args} -i "{source}" {encoding_args}
-y "{outfile}"
name: test_vp8_color_420
sources:
- ../sourceimages/chip-chart-1080-16bit-noicc.png.yml
suffix: .mkv
wedges:
vp8-yuv420p10le-good: &basevp8
-c:v: libvpx
-quality: good
-crf: 4
-b:v: 200M
-vf: '"scale=in_color_matrix=bt709:out_color_matrix=bt709"'
-color_primaries: bt709
-color_range: tv
-color_trc: bt709
-colorspace: bt709
-pix_fmt: yuv444p10le
-strict: experimental

vp8-yuv420p-best:
<< : *basevp8
-pix_fmt: yuv420p

vp8-yuv420p-bv0:
<< : *basevp8
-pix_fmt: yuv420p
-b:v: 0

vp8-yuv420p-qminmax:
<< : *basevp8
-pix_fmt: yuv420p
-qmin: 0
-qmax: 50
---
reports:
description: This is testing vp9 color encoding.
directory: vp9-color-encode
name: vp9-color-tests
templatefile: colorweb.html.jinja
title: Ffmpeg vp9 encoding color tests
Loading

0 comments on commit 2821106

Please sign in to comment.