I have been encoding some videos in AV1 lately and I thought I’d share my technique for those who may wish to do some AV1 on their own without having a messy setup. I think this is a pretty clean way, ultimately, to use Av1an’s Docker image.

A forewarning: AV1 can be pretty to slow encode with. I’ve been doing it with DVDs where the 640x480 resolution of the video means a frame can be processed relatively quickly, but videos in 1920x1080 or 4k resolutions might be pretty intense where the encode speed only ends up being a frame a second.

Forewarning pt. 2: Something I learned that I CANNOT rely on is trying a faster encode speed to guesstimate the resulting file size and picture quality and then really maximize my results by lowering the encode speed. My observation has been that a slower encode speed will in fact improve the picture quality (and file size), such that I cannot be sure what something will look like without just encoding a very short sample at a slow speed. OK. Let’s begin.

Operating System & Environment

I am using Fedora Linux 38. I’d like to use the Av1an package but that only has an official Arch release. I definitely don’t want to spend time compiling this myself, so I will use the official Docker image instead. And I won’t use Docker, actually, but Podman. I also use the Fish Shell. Its syntax is very slightly different from Bash’s.

Now, Fedora users may know about SELinux. And something that kept happening to me was the security context of some of the files I’m shuffling around my hard drives would end up being not correct, making Podman incapable of seeing the files I’m trying to use. So instead of fixing the context per file (annoying) I just temporarily disabled SELinux.

sudo setenforce Permissive

Container image

From here things are pretty straightforward. I’ll pull the docker image, which has a full Av1an setup ready to go.

podman pull docker.io/masterofzen/av1an:master

One little note is that you should use the master tag. A confusing thing about this image is that the latest tag is the old python version, and we want the current Rust version.

Executing Av1an

Now, navigate to whatever directory your source video is in. In my case, I losslessly encoded the DVDs with Handbrake into h264 and passed through the audio/chapter markers, etc. This gave me a good source to work with, even though it was a little bloated in file size. I don’t think Av1an accepts MPEG-2, which is why I did that.

First I’ll explain what the Podman command is doing for those who aren’t familiar with Docker/Podman, and then I’ll give a full working example.

podman run -v "$(pwd)":/videos:z --userns=keep-id -it --rm docker.io/masterofzen/av1an:master -i sourcevideo.mp4 -s scenes.csv --pix-format yuv420p10le -o output.webm -v "--VIDEO_OPTIONS" --keep -a "--AUDIO_OPTIONS"

  • podman run - Execute a container
  • -v "$(pwd)":/videos:z - Mount the present working directory as /videos in the container, and the :z is an SELinux labeling thing that can be dropped for non-SELinux users.
  • --userns=keep-id - This flag helps keep the user id and group ids consistent between the host and container so that they don’t get mangled. Your output file will belong to your user.
  • -it - Execute the command in a visible shell session
  • --rm - Remove the container (not the image, the container) when the command is done executing.

Final example

The rest of the flags are for Av1an itself, or for the encoders. So here’s a full working example of how I used it, to encode with aomenc and Opus for the audio. Av1an uses aomenc by default.

podman run -v "$(pwd)":/videos:z --userns=keep-id -it --rm docker.io/masterofzen/av1an:master -i sourcevideo.mp4 -s scenes.csv --pix-format yuv420p10le -o output.webm -v " --cpu-used=3 --enable-qm=1 --threads=4 -b 10 --end-usage=q --cq-level=28 --lag-in-frames=48 --auto-alt-ref=1 --enable-fwd-kf=1" --keep -a "-c:a libopus -b:a 128k"

I think for an explanation for what individual flags do, and perhaps some guidance on how to use them effectively, I can only refer one to the guide written by Reddit user BlueSwordM https://www.reddit.com/r/AV1/comments/t59j32/encoder_tuning_part_4_a_2nd_generation_guide_to/

  • Gianni R@lemmy.mlM
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 year ago

    Thanks for such a thorough guide! It is worth noting though that Blue himself now says these guides he wrote previously are not up to date. The current rationale is:

    • use the aomenc fork called aom-av1-lavish
    • use the following settings for lavish via av1an: --lag-in-frames=48 --tune-content=psy --tune=ssim --sb-size=dynamic --enable-qm=1 --qm-min=0 --qm-max=8 --row-mt=1 --disable-kf --kf-max-dist=9999 --kf-min-dist=1 --disable-trellis-quant=0 --arnr-maxframes=15 arnr-strength=4
    • GnuLinuxDude@lemmy.mlOP
      link
      fedilink
      English
      arrow-up
      1
      ·
      1 year ago

      I haven’t tried any forks just simply because they’re not included into Av1an, as far as I know. Are you saying that they’re actually included?

      But even since writing this mini guide three weeks ago I have slowly come around to the idea that it might just be easier to stick with SVT-AV1 due to its speed unless I am targeting the absolute minimum sizes on slow encode speeds, which I usually am not. I am usually trying to beat x264 with a reduction in size, but not necessarily pushed to the absolute limits of encoding possibilities.

      • Gianni R@lemmy.mlM
        link
        fedilink
        English
        arrow-up
        1
        ·
        1 year ago

        I don’t know if anything is “included” with Av1an as it is standalone & doesn’t have any encoding capabilities on its own. If you want competitive speed to SVT-AV1, you just need to set your worker count to the number of physical cores you have (given you have multithreading) as aomenc (lavish or regular) will use 2 threads per worker by default which is more efficient than allowing the encoder to parallelize on its own.

        If you want to try lavish, it is a good degree more efficient than SVT-AV1 at speed 4 & lower. You need to build it from source & copy the binary into your favorite bin directory. If you want to go faster than speed 4, SVT-AV1 is probably your best bet, although make sure to set av1an to use only 1 worker

        • GnuLinuxDude@lemmy.mlOP
          link
          fedilink
          English
          arrow-up
          2
          ·
          edit-2
          1 year ago

          I don’t know if anything is “included” with Av1an

          Oh right, I meant the docker image for Av1an. I’ll look into your suggestions and try them out and if I have interesting findings I’ll make a new post and report on it.

  • Luna
    link
    fedilink
    English
    arrow-up
    1
    ·
    5 months ago

    You can check out this guide on how to encode AV1 using Av1an and Podman:

    1. Install Podman on your system: Podman is a container engine that allows you to run containers without the need for a separate daemon. You can install Podman on Linux systems by following the installation instructions on the official Podman website.
    2. Install Av1an in a Podman container: Av1an is a command-line tool for encoding and transcoding videos using AV1. You can create a Podman container with Av1an installed by running the following command: podman run -it --name av1an-container ghcr.io/darealshinji/av1an This command will download the Av1an container image and run it in interactive mode.
    3. Encode your video using Av1an: Once the Av1an container is running, you can use the Av1an command-line tool to encode your video in AV1 format. You can use the following command to encode a video file named input.mp4: av1an -i input.mp4 -o output.av1 This command will start the encoding process and output the encoded video to a file named output.av1. And if you’re new to Av1an and Podman, try DVDFab DVD All In One. It’s user-friendly and can convert videos to AV1 easily.