Whats up in Free codecs? Opus and Daala - Xiph.orggreg/gstreamer-daala-opus.pdf · Pyramid Vector...

41
Whats up in Free codecs? Opus and Daala Greg Maxwell <[email protected]> (Mozilla/Xiph.Org) GStreamer Conference 2013-10-23

Transcript of Whats up in Free codecs? Opus and Daala - Xiph.orggreg/gstreamer-daala-opus.pdf · Pyramid Vector...

Page 1: Whats up in Free codecs? Opus and Daala - Xiph.orggreg/gstreamer-daala-opus.pdf · Pyramid Vector Quantization Preserving the overall “energy” in a band turned out to be perceptually

Whats up in Free codecs?Opus and Daala

Greg Maxwell <[email protected]>(Mozilla/Xiph.Org)

GStreamer Conference2013-10-23

Page 2: Whats up in Free codecs? Opus and Daala - Xiph.orggreg/gstreamer-daala-opus.pdf · Pyramid Vector Quantization Preserving the overall “energy” in a band turned out to be perceptually

Why free codecs matter

● Codecs are used by all multimedia software– Every cost from codecs ends up repeated a

million-fold

● Encumbered codecs are a billion dollar toll-tax on communications tools

● Codec licensing is used a weapons in competitive battles– Licensing regimes are universally discriminatory

● The success of the Internet was based on innovation without asking permission

Page 3: Whats up in Free codecs? Opus and Daala - Xiph.orggreg/gstreamer-daala-opus.pdf · Pyramid Vector Quantization Preserving the overall “energy” in a band turned out to be perceptually

Why free codecs matter (cont)

...or begging for forgiveness● Many applications can't tolerate any codec

licensing costs at all– even the cost of just counting the users is too

much

● Ignoring the licensing creates risks that can show up at any time– a tax on success

● Compatibility is usually the big cost, not cpu, bandwidth, etc.

Page 4: Whats up in Free codecs? Opus and Daala - Xiph.orggreg/gstreamer-daala-opus.pdf · Pyramid Vector Quantization Preserving the overall “energy” in a band turned out to be perceptually

Changing the game

● Creating good codecs isn't easy...

– But we don't need many, without weird competitive pressures the whole world can cooperate

– Best implementations of the patented codecs are already often the free software ones

● Where RF is established non-free codecs see no adoption. See: JPEG. Network effect decides

● Unfortunately many different people care about many different things

● Convincing everyone means being better in almost every way, not just one or two

Page 5: Whats up in Free codecs? Opus and Daala - Xiph.orggreg/gstreamer-daala-opus.pdf · Pyramid Vector Quantization Preserving the overall “energy” in a band turned out to be perceptually

What is Opus?

● Lossy audio codec “designed for the Internet”– Extremely flexible, suitable for

almost any application,

switchable in realtime

● Result of work by Xiph.Org, Skype (Microsoft), Broadcom, Mozilla, and many others

● Mixture of old and new technology ● Published as IETF RFC 6716 in Sept 2012

Page 6: Whats up in Free codecs? Opus and Daala - Xiph.orggreg/gstreamer-daala-opus.pdf · Pyramid Vector Quantization Preserving the overall “energy” in a band turned out to be perceptually

Why a new audio codec?

● Originally two types of audio codecs– Speech codecs: low-delay voice, limited

bandwidth

– Audio codecs: high-delay music, fullband

● We want (and can now afford) the best of both worlds

● No efficient, high-quality, very low latency options existed

● Licensing complications inhibited compatibility on the internet

Page 7: Whats up in Free codecs? Opus and Daala - Xiph.orggreg/gstreamer-daala-opus.pdf · Pyramid Vector Quantization Preserving the overall “energy” in a band turned out to be perceptually

Audio codec “map” in 2010

Application CodecVoIP with PSTN AMR-NB / Speex

Wideband VoIP/videoconference AMR-WB / Speex

High-quality videoconference G.719

Low-bitrate music streaming HE-AAC / ≈Vorbis

High-quality music streaming AAC-LC / Vorbis

Low-delay broadcast AAC-LD

Network music performance

Page 8: Whats up in Free codecs? Opus and Daala - Xiph.orggreg/gstreamer-daala-opus.pdf · Pyramid Vector Quantization Preserving the overall “energy” in a band turned out to be perceptually

Audio codec “map” in 2013

Application CodecVoIP with PSTN OpusWideband VoIP/videoconference OpusHigh-quality videoconference OpusLow-bitrate music streaming OpusHigh-quality music streaming OpusLow-delay broadcast OpusNetwork music performance Opus

Page 9: Whats up in Free codecs? Opus and Daala - Xiph.orggreg/gstreamer-daala-opus.pdf · Pyramid Vector Quantization Preserving the overall “energy” in a band turned out to be perceptually

Codec Landscape

Page 10: Whats up in Free codecs? Opus and Daala - Xiph.orggreg/gstreamer-daala-opus.pdf · Pyramid Vector Quantization Preserving the overall “energy” in a band turned out to be perceptually

Overview of Opus

● Extremely flexible– Bit-rates from 6 kb/s to 510 kb/s

– Narrowband (8 kHz) to fullband (48 kHz)

– Frame sizes from 2.5 ms to 60 ms

– Speech and music support

– Mono and stereo

● All changeable dynamically with in-band signalling

● Multichannel too (though not dynamically switchable)

Page 11: Whats up in Free codecs? Opus and Daala - Xiph.orggreg/gstreamer-daala-opus.pdf · Pyramid Vector Quantization Preserving the overall “energy” in a band turned out to be perceptually

Optimized for the Internet?

● More than the ability to conceal lost packets● Wide range of operating conditions (delay, bit-

rate, loss) that vary with time● Transports data in bytes● RTP payload: the simpler the better● Designed to be hard to implement wrong● BSD licensed reference implementation

Page 12: Whats up in Free codecs? Opus and Daala - Xiph.orggreg/gstreamer-daala-opus.pdf · Pyramid Vector Quantization Preserving the overall “energy” in a band turned out to be perceptually

Greater than the sum of its parts

● Merger of two technologies– SILK: Skype's linear prediction-based speech

codec

– CELT: Xiph.Org's transform-based low-delay audio codec

● Massive automated testing● Large scale public development

– Constant iteration with early deployment

Page 13: Whats up in Free codecs? Opus and Daala - Xiph.orggreg/gstreamer-daala-opus.pdf · Pyramid Vector Quantization Preserving the overall “energy” in a band turned out to be perceptually

Google results on speech

Wideband / Fullband

Page 14: Whats up in Free codecs? Opus and Daala - Xiph.orggreg/gstreamer-daala-opus.pdf · Pyramid Vector Quantization Preserving the overall “energy” in a band turned out to be perceptually

HydrogenAudio results on Music (64kbps)

Page 15: Whats up in Free codecs? Opus and Daala - Xiph.orggreg/gstreamer-daala-opus.pdf · Pyramid Vector Quantization Preserving the overall “energy” in a band turned out to be perceptually

Opus has been a big success

● State of the art codec for almost all audio applications

● Royalty free (with protective patent licenses)● Deployed to hundreds of millions of devices

(already!)– Mandatory to implement in WebRTC

● Standardized in a recognized standards body● Ongoing work improving performance● More info at http://opus-codec.org/

irc://irc.freenode.net/opus

Page 16: Whats up in Free codecs? Opus and Daala - Xiph.orggreg/gstreamer-daala-opus.pdf · Pyramid Vector Quantization Preserving the overall “energy” in a band turned out to be perceptually

So what about video?

● Some existing royalty free formats– Theora is circa 1999/2000 technology

– VP8 solidly better than H264 baseline profile, but the bar was moving to high profile at release

– VP9 advances performance but shares the same architecture technically and politically

● Structural similarity to patented tech makes FUD too easy

● Single company sponsorship makes some parties uncomfortable, even with permissive licenses

Page 17: Whats up in Free codecs? Opus and Daala - Xiph.orggreg/gstreamer-daala-opus.pdf · Pyramid Vector Quantization Preserving the overall “energy” in a band turned out to be perceptually

So what about video? (cont)

● Lets take some of the strategy that worked in Opus, and apply it to video:– Work in a public process in a recognized SDO with

a strong IPR disclosure policy and Opus-like patent licensing

– Question assumptions in the conventional structure of video codecs, no sacred cows

– Target applications where high flexibility is essential

– optimize for perception not PSNR

Page 18: Whats up in Free codecs? Opus and Daala - Xiph.orggreg/gstreamer-daala-opus.pdf · Pyramid Vector Quantization Preserving the overall “energy” in a band turned out to be perceptually

Daala

● Daala is the name of our current project to these ends, still in very early development

● Technological Differences (so far)– Multisymbol arithmetic coding

– Lapped Transforms

– Frequency Domain Intra-prediction

– Pyramid Vector Quantization

– Chroma From Luma

– Overlapping-block motion compensation

Page 19: Whats up in Free codecs? Opus and Daala - Xiph.orggreg/gstreamer-daala-opus.pdf · Pyramid Vector Quantization Preserving the overall “energy” in a band turned out to be perceptually

30 sec. intro to compression

Lossy compression works like this:– Prediction: Considering what you know about this content

or typical content predict the next data.

– Transform: Rearrange the information to

make it more compressible

– Quantization: Compute the difference

from prediction and lower its resolution.

– Entropy coding: The quantized error signal is (hopefully) random numbers from some probability distribution.

● Pack it efficiently into the bitstream

Page 20: Whats up in Free codecs? Opus and Daala - Xiph.orggreg/gstreamer-daala-opus.pdf · Pyramid Vector Quantization Preserving the overall “energy” in a band turned out to be perceptually

20

Arithmetic Coding

● Given some symbol probabilities efficiently

pack symbols into a bitstream● Inherently serial: Major performance limitation

in hardware● There are many fast approximations if your

symbols are binary– But many of them are patented

● What about non-binary?– We used multisymbol coding in Opus

Page 21: Whats up in Free codecs? Opus and Daala - Xiph.orggreg/gstreamer-daala-opus.pdf · Pyramid Vector Quantization Preserving the overall “energy” in a band turned out to be perceptually

21

Arithmetic Coding

● Turns out that non-binary coding makes part of the process inherently parallel.

● Reduces the serial part in direct proportion to

the symbol range. ● ~2x speedup on test

on top of VP8● Multisymbol probability

modelling is harder but

often more powerful.

0

1

A

B

CD

AA

ABACAD

BABB

BCBD

DADB

DCDD

CACB

CCCD

ABAABB

ABCABD

AAA

AABAACAAD

ADAADB

ACAACB

BAABAB

BACBAD

BBABBB

DAADAB

BAABAB

BACBAD

BBABBB

CAACAB

Range: [58/108, 59/108)

0 5 10

Page 22: Whats up in Free codecs? Opus and Daala - Xiph.orggreg/gstreamer-daala-opus.pdf · Pyramid Vector Quantization Preserving the overall “energy” in a band turned out to be perceptually

Lapped Transforms

Page 23: Whats up in Free codecs? Opus and Daala - Xiph.orggreg/gstreamer-daala-opus.pdf · Pyramid Vector Quantization Preserving the overall “energy” in a band turned out to be perceptually

23

Lapped Transforms

● No more blocking artifacts, without loop filter● Computationally cheaper than wavelets● Better compression than DCT / wavelets● Doesn't completely disrupt block based

DCT infrastructure4-point 8-point 16-point

KLT 7.5825 dB 8.8462 dB 9.4781 dB

DCT 7.5701 dB 8.8259 dB 9.4555 dB

LT 8.6060 dB 9.5572 dB 9.8614 dB

9/7 Wavelet 9.46 dB

Page 24: Whats up in Free codecs? Opus and Daala - Xiph.orggreg/gstreamer-daala-opus.pdf · Pyramid Vector Quantization Preserving the overall “energy” in a band turned out to be perceptually

Typical intra-prediction

The intra-prediction modes for 4x4 blocks in WebM (VP8).

Page 25: Whats up in Free codecs? Opus and Daala - Xiph.orggreg/gstreamer-daala-opus.pdf · Pyramid Vector Quantization Preserving the overall “energy” in a band turned out to be perceptually

Typical intra-prediction

Pros:

– Uses image data from neighboring blocks● Only need to remember 1 pixel border

– Parameterizable for any angle θ

– Predicts difficult to code features well● edges are extended

– Efficient implementation (~no multiplies)

Cons:

– Blocks L, UL, U, UR must be decoded

– Poor prediction in textured areas

– Doesn't work with overlapped blocks!

Page 26: Whats up in Free codecs? Opus and Daala - Xiph.orggreg/gstreamer-daala-opus.pdf · Pyramid Vector Quantization Preserving the overall “energy” in a band turned out to be perceptually

Decoding an Intra Frame

Neighboring blocks:Decoded Image

Unpredicted

Predicted

Currently Predicting

Needs Post-filter

Prediction Support

Page 27: Whats up in Free codecs? Opus and Daala - Xiph.orggreg/gstreamer-daala-opus.pdf · Pyramid Vector Quantization Preserving the overall “energy” in a band turned out to be perceptually

Predict in coefficient domain

● We don't have the pixels needed for a traditional intrapredictor

● Lapping reduces the need, but only somewhat● Why not predict in the lapped DCT domain?

– Each coefficient for the block predicted as a weighed sum of the neighbouring blocks coeffs

– If not for the lapping we could have the same predictors either way

● “Directions” don't have a clear meaning in the transform domain, so how do we design these predictors?

Page 28: Whats up in Free codecs? Opus and Daala - Xiph.orggreg/gstreamer-daala-opus.pdf · Pyramid Vector Quantization Preserving the overall “energy” in a band turned out to be perceptually

Machine learning for predictors

Original VP8 modes

K-Means refinement

Training Image

So far: ~0.25 dB more coding gain than classic intrapred, plus actually works with lapped transforms

Page 29: Whats up in Free codecs? Opus and Daala - Xiph.orggreg/gstreamer-daala-opus.pdf · Pyramid Vector Quantization Preserving the overall “energy” in a band turned out to be perceptually

Not just limited to directions

“Mode 1 now predicts periodic texture!”

Page 30: Whats up in Free codecs? Opus and Daala - Xiph.orggreg/gstreamer-daala-opus.pdf · Pyramid Vector Quantization Preserving the overall “energy” in a band turned out to be perceptually

Pyramid Vector Quantization

● Preserving the overall “energy” in a band turned out to be perceptually critical for audio– Opus designed to explicitly preserve energy

● Take a set values and treat them as a point on a sphere: the radius is the energy, the and the angle is “details”. Code these separately.

● Intuitively it makes sense for image coding: Might it be better for low quality blocks to become “noisy” instead of blurry? “Film grain”

● Mixed results so far

Page 31: Whats up in Free codecs? Opus and Daala - Xiph.orggreg/gstreamer-daala-opus.pdf · Pyramid Vector Quantization Preserving the overall “energy” in a band turned out to be perceptually

Chroma from Luma

● RGB -> YUV moves most of the entropy into the luma channel but residual local correlation remains, esp. edge locations

● In the pixel domain predicting chroma from luma can be computationally complex

● But in the frequency domain it's fast!● So far, our CFL results do somewhat worse on

every objective metric● But it looks clearly better!

– Most metrics designed on greyscale

Page 32: Whats up in Free codecs? Opus and Daala - Xiph.orggreg/gstreamer-daala-opus.pdf · Pyramid Vector Quantization Preserving the overall “energy” in a band turned out to be perceptually

32

Motion compensation

● Predict frames from past (sometimes future) frames, compensating for things that move

● Traditional motion compensation displaces blocks of pixels, creates blocking artifacts

Page 33: Whats up in Free codecs? Opus and Daala - Xiph.orggreg/gstreamer-daala-opus.pdf · Pyramid Vector Quantization Preserving the overall “energy” in a band turned out to be perceptually

33

Overlapped Block Motion Compensation (OBMC)

● Overlap the predictions from multiple nearby MVs, and blend them with a window

Also a form of multi-hypothesis prediction

Page 34: Whats up in Free codecs? Opus and Daala - Xiph.orggreg/gstreamer-daala-opus.pdf · Pyramid Vector Quantization Preserving the overall “energy” in a band turned out to be perceptually

34

OBMC (cont.)

● Used by Dirac– Also want to avoid blocking artifacts with wavelets

● PSNR improvements as much as 1 dB● Issues

– Motion vectors no longer independent● Can use iterative refinement, dynamic programming

(Chen and Willson, 2000), bigger cost of ignoring this

– Can blur sharp features

– Can add “ghosting” artifacts

– Handling multiple block sizes

Page 35: Whats up in Free codecs? Opus and Daala - Xiph.orggreg/gstreamer-daala-opus.pdf · Pyramid Vector Quantization Preserving the overall “energy” in a band turned out to be perceptually

35

Variable Block Size

● Need a way change block size that doesn’t create blocking artifacts

● Dirac subdivides all blocks to the smallest level and copies MVs– Lots of setup overhead for smaller blocks

– Redundant computations for adjacent blocks with same MV

Page 36: Whats up in Free codecs? Opus and Daala - Xiph.orggreg/gstreamer-daala-opus.pdf · Pyramid Vector Quantization Preserving the overall “energy” in a band turned out to be perceptually

36

Adaptive Subdivision

● Allow artifact-free subdivision in a 4-8 mesh– Neighbors differ by at most 1 level of subdivision

– Fine-grained control (MV rate doubles each level)

– Efficient R-D optimization methods (Balmelli 2001)● Developed for compressing triangle mesh/terrain data

– Larger interpolation kernels, less setup overhead, fewer redundant calculations

Page 37: Whats up in Free codecs? Opus and Daala - Xiph.orggreg/gstreamer-daala-opus.pdf · Pyramid Vector Quantization Preserving the overall “energy” in a band turned out to be perceptually

37

Multiresolution Blending

● Technique due to Burt and Adelson 1983– Decompose predictor into low-pass and high-pass

subbands LL, HL, LH, HH

– Blend with small window in high-pass bands

– Like “enblend” used for panorama stitching

– Reduces “ghosting” and blurring

● Proposed simplification– One level of Haar decomposition (no multiplies)

– Blend LL band like OBMC, copy the rest

– Reduces OBMC multiplies by 75%

Page 38: Whats up in Free codecs? Opus and Daala - Xiph.orggreg/gstreamer-daala-opus.pdf · Pyramid Vector Quantization Preserving the overall “energy” in a band turned out to be perceptually

38

Edge-Directed subpel Interpolation?

● Fractional pixel vectors need interpolation● Possible to do better than linear filters

● All we need is something fast enough for videoDavid Schleef has something, we haven't tried it yet

whole pel

half pel

quarter pel

Page 39: Whats up in Free codecs? Opus and Daala - Xiph.orggreg/gstreamer-daala-opus.pdf · Pyramid Vector Quantization Preserving the overall “energy” in a band turned out to be perceptually

39

Today's formats are a long way from exhausting the possible

How about unblending a cross-fade?

Spatial Sparsity-Induced Prediction for Images and Video: A Simple Way to Reject Structured InterferenceGang Hua and Onur G. Guleryuz (2011)

Page 40: Whats up in Free codecs? Opus and Daala - Xiph.orggreg/gstreamer-daala-opus.pdf · Pyramid Vector Quantization Preserving the overall “energy” in a band turned out to be perceptually

40

The road ahead

● The techniques we've been working with appear to work, but there is much to be done

● Industry is currently distracted figuring out how they're going to deploy HEVC (/VP9)

● Your participation is welcome!– http://xiph.org/daala

● Opus benefited from some applications served by no other audio codec. – Does something similar exist for video?

Page 41: Whats up in Free codecs? Opus and Daala - Xiph.orggreg/gstreamer-daala-opus.pdf · Pyramid Vector Quantization Preserving the overall “energy” in a band turned out to be perceptually

Questions?