10

I am currently using Ubuntu Focal Fossa 20.04 LTS and I would like to create high quality AV1 files using FFmpeg and librav1e. I have been spurred along by the addition of rav1e support to FFmpeg as 'librav1e'.

The material that I am interested in working with is given here:

  1. Sintel trailer video (720p uncompressed 1.7GB)
  2. Sintel trailer audio (flac 5MB)

It is early days for rav1e support under FFmpeg with not a lot of documentation and published experimentation in place. It would be great to see it all working under an Ubuntu LTS release!

4
  • As it were was looking at this recently. cargo produces a binary which doesn't seem what ffmpeg desires. cargo-c produces .h, .a & .pc files which seems correct but can't get ffmpeg to use... – doug Nov 16 '19 at 6:36
  • @doug I have packaged (for my own use) on my other distro with the following: cargo cinstall --release --destdir=$PKG --prefix=/usr --libdir=/usr/lib$LIBDIRSUFFIX and the release rav1e 0.1 which was accepted by FFmpeg ok. Difficult to package cleanly with all of the 'crates' downloading... – andrew.46 Nov 16 '19 at 8:57
  • Here in 18.04 the repo rustc & cargo are too old it seems. Using rustup gets a working compiler & packager but they are 'installed' to $HOME . So the cinstall works to the point of actually installing where it fails as no permission to install to /usr*. May try again like we used to do for vlc & ffmpeg, I.e keeping the whole build(s) in $HOME – doug Nov 16 '19 at 19:33
  • @doug Removal of the shared libraries seems to do the trick. I am not sure how to tell cargo cinstall not to build these so manual work necessary atm. Also some oddness with installation paths and 'prefix' which I have remedied... – andrew.46 Nov 22 '19 at 7:09
19

It looks like this goal can be accomplished in 4 relatively easy steps, thus allowing Ubuntu Focal Fossa 20.04 LTS to get to grips with AV1 encoding with FFmpeg and rav1e!

1. Get a recent copy of rust...

Focal Fossa and rav1e benefit from a newer version of rust so grab a newer copy as follows:

sudo apt-get install curl
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Follow the defaults (just press 'enter') and then run the following to configure your current shell:

source $HOME/.cargo/env

to allow instant access to the newest rust and friends.

2. Install rav1e

Best to install both the executable (the command rav1e --fullhelp will then show options that can be used from within FFmpeg with the -rav1e-params option) as well as the libraries that FFmpeg will use to successfully compile and produce librav1e.

First the executable, using a simple copy and paste code block:

sudo apt-get install nasm build-essential libssl-dev && 
mkdir -pv $HOME/{bin,ffmpeg_sources,ffmpeg_build} && 
cd $HOME/ffmpeg_sources && 
wget https://github.com/xiph/rav1e/archive/refs/tags/v0.4.1.tar.gz && 
tar xvf v0.4.1.tar.gz && cd rav1e-0.4.1 && 
cargo build --release && 
find target -name rav1e -exec install -m 755 {} $HOME/bin \; && 
strip ~/bin/rav1e && \
cd $HOME/ffmpeg_sources && rm -rfv rav1e-0.4.1

Next install the cargo-c applet as well as the libraries and pkg-config file needed by FFmpeg. First run a one-off command to install cargo-c:

cargo install cargo-c

and then compile rav1e again using the installed cargo-c:

cd $HOME/ffmpeg_sources && tar xvf v0.4.1.tar.gz && \
cd rav1e-0.4.1 && \
cargo cinstall --release \
     --prefix=$HOME/ffmpeg_build \
     --libdir=$HOME/ffmpeg_build/lib \
     --includedir=$HOME/ffmpeg_build/include

Best to then remove the rav1e shared libraries, leaving the static libraries for FFmpeg to pick up (FFmpeg has a problem with the shared rav1e libraries in this location on my system):

rm -v $HOME/ffmpeg_build/lib/librav1e.so*

3. Install FFmpeg

Now go to the FFmpeg trac site and install FFmpeg as instructed, remembering to add:

--enable-librav1e

to the ./configure string. Then the hard work is done :)

4. Run the encoder

A very reasonable encode can then be run on the test files mentioned in the original question:

ffmpeg -i sintel_trailer_2k_720p24.y4m -i sintel_trailer-audio.flac \
       -c:v librav1e -qp 80 -speed 4 \
       -tile-columns 2 -tile-rows 2 \
       -c:a libfdk_aac -b:a 128k \
       sintel_trailer_av1.mp4

Things to manipulate here would be:

  • -qp 80: Uses 'quantizer' mode to encode with a range of 0-255. Smaller values are a higher quality, the default is 100. 80 seems to be the sweet spot for this media clip.
  • -speed 4: Selects the speed preset (0-10) to encode with, 0 is best quality while 10 is the fastest. This particular setting is a nice compromise between speed and quality on my system (2nd generation Threadripper).
  • -tile-columns 2 -tile-rows 2 Quite decent speed enhancements can be made by manipulating rav1e's tile based encoding. The example given here splits the encoding and decoding into 4 segments and seems a decent choice for the suggested input video, feel free to experiment though..

This encodes at many times the speed that is seen with FFmpeg and libaom-av1 and arguably produces far better quality. Doubtless this encoding string can be further refined and I will do this as rav1e, FFmpeg and AV1 encoding mature...

5. Gratuitous screenshot

OK so there is an optional 5th step; taking a screenshot of the completed output file running :)

enter image description here

Additional Notes...

  • FFmpeg Documentation: The docs on the FFmpeg implementation of encoding with rav1e, this can also be seen by searching the FFmpeg man pages, either man ffmpeg-all or man ffmpeg-codecs. Remember that native rav1e options can be seen with rav1e --help and added into any FFmpeg command line by using the -rav1e-params option...
3
  • 1
    @tatsu Good news is that it is all running nicely now on 20.04! I have added to the answer two required extras: sudo apt-get install build-essential libssl-dev and everything roared back to life :) – andrew.46 Apr 25 '20 at 10:38
  • thanks! your guide worked absolutely brilliant! I needed to DECODE so my command was : ffmpeg -i test.av1 -c:v libx264 test.mp4 – tatsu Apr 25 '20 at 15:01
  • 1
    @tatsu Great news! And thanks for giving me the heads up that a 20.04 version needed some changes :) – andrew.46 Apr 25 '20 at 21:21

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.