Opus codec

Post your ideas and suggestions how to improve the game.
nastyslave
Inserter
Inserter
Posts: 43
Joined: Sat Aug 06, 2016 11:48 am
Contact:

Opus codec

Post by nastyslave »

FactorioBot wrote: Thu Jul 28, 2022 2:03 pm [*]Added PulseAudio driver for the SDL audio backend.
So can you add support for an OGG Opus codec? Because there is only support of OGG Vorbis in mods...
nastyslave
Inserter
Inserter
Posts: 43
Joined: Sat Aug 06, 2016 11:48 am
Contact:

Re: Version 1.1.63

Post by nastyslave »

https://opus-codec.org/comparison/

So any chance to add OGG OPUS handle in future versions?
Donion
Factorio Staff
Factorio Staff
Posts: 302
Joined: Sun Aug 22, 2021 9:18 am
Contact:

Re: Version 1.1.63

Post by Donion »

nastyslave wrote: Fri Jan 13, 2023 2:51 pm https://opus-codec.org/comparison/

So any chance to add OGG OPUS handle in future versions?
There are no plans to add support for Opus at the moment, but never say never. Do you have some specific issue with Vorbis or does it come down to quality/bitrate?
nastyslave
Inserter
Inserter
Posts: 43
Joined: Sat Aug 06, 2016 11:48 am
Contact:

Re: Version 1.1.63

Post by nastyslave »

Donion wrote: Fri Jan 13, 2023 3:05 pm Do you have some specific issue with Vorbis or does it come down to quality/bitrate?
When I'm trying to add some sounds/music to mods - game absolutely didn's understand half them, because half of .ogg's are OPUS, but this .ogg files are playing normaly with any audio player... Also, the quality of OPUS codec is always higher than Vorbis anyway.
So isn't all of that the reason to handle ALL .ogg files and add OPUS to codecs for Factorio instead of getting half of .ogg-files uncompatible at all...
quyxkh
Smart Inserter
Smart Inserter
Posts: 1031
Joined: Sun May 08, 2016 9:01 am
Contact:

Re: Version 1.1.63

Post by quyxkh »

A google turned up
Opus replaces both Vorbis and Speex for new applications, and several blind listening tests have ranked it higher-quality than any other standard audio format at any given bitrate until transparency is reached, including MP3, AAC, and HE-AAC.
which seems like a pretty damn stellar recommendation.
Donion
Factorio Staff
Factorio Staff
Posts: 302
Joined: Sun Aug 22, 2021 9:18 am
Contact:

Re: Version 1.1.63

Post by Donion »

nastyslave wrote: Fri Jan 13, 2023 2:51 pm https://opus-codec.org/comparison/

So any chance to add OGG OPUS handle in future versions?
I've been playing around with the Opus codec today. It's working, but it's funny how those comparisons don't mention that decoding is 3-5 times slower than vorbis.
xykite
Inserter
Inserter
Posts: 25
Joined: Thu Jul 30, 2020 9:39 pm
Contact:

Re: Version 1.1.63

Post by xykite »

Donion wrote: Thu Nov 07, 2024 8:29 pm I've been playing around with the Opus codec today. It's working, but it's funny how those comparisons don't mention that decoding is 3-5 times slower than vorbis.
3-5x slower doesn't sound right to me... are you using special implementations? With off-the-shelf tools I find opus is usually a bit faster than ogg at decoding if you count the wall-clock time, and between 50-100% slower if you count the cpu time.

On a Windows machine with WSL/Ubuntu, after running "apt install opus-tools vorbis-tools" and transcoding gleba-1-hero.ogg to opus at bitrate 64 (which sounds transparent to me), the best-of-three times are:

Code: Select all

$ time oggdec -o /dev/null gleba-1-hero.ogg
oggdec from vorbis-tools 1.4.2
Decoding "gleba-1-hero.ogg" to "/dev/null"
        [100.0%]

real    0m1.834s
user    0m0.969s
sys     0m0.422s

Code: Select all

$ time opusdec gleba-1-hero.opus /dev/null
Decoding to 44100 Hz (2 channels)
Encoded with libopus 1.4-711-g178672ed
ENCODER=opusenc from opus-tools 0.1.10
ENCODER_OPTIONS=--bitrate 64
Decoding complete.

real    0m1.617s
user    0m1.531s
sys     0m0.047s
Donion
Factorio Staff
Factorio Staff
Posts: 302
Joined: Sun Aug 22, 2021 9:18 am
Contact:

Re: Version 1.1.63

Post by Donion »

No special implementations, just grabbing opus from their github. I didn't use the latest version (but vorbis version used was quite old as well). And it was just a quick and dirty test, I didn't investigate how it behaves with different encoding settings.
But searching around the interwebs I've consistently found Opus being considerably slower than Vorbis.
For example here: https://www.audiokinetic.com/en/blog/a- ... ght-codec/

That being said, I will most likely still go ahead with adding Opus support (so mods can use it, and then any performance impact is on them) and encoding Space Age music with Opus (my goal is to cut the disk size in half, as there is a lot of music data in the expansion).
User avatar
BraveCaperCat
Fast Inserter
Fast Inserter
Posts: 242
Joined: Mon Jan 15, 2024 10:10 pm
Contact:

Re: Version 1.1.63

Post by BraveCaperCat »

You do know that you could have discussed audio formats in another topic... Right? At least I think you were talking about audio formats...
Creator of multiple mods, including Quality Assurance - My most popular one. Expect multiple modding-related questions, answers and other posts.
nastyslave
Inserter
Inserter
Posts: 43
Joined: Sat Aug 06, 2016 11:48 am
Contact:

Re: Version 1.1.63

Post by nastyslave »

So can we get .ogg opus support in new factorio versions?
Music files will reduced in size greatly if opus will be used.
Donion
Factorio Staff
Factorio Staff
Posts: 302
Joined: Sun Aug 22, 2021 9:18 am
Contact:

Re: Version 1.1.63

Post by Donion »

nastyslave wrote: Fri Nov 15, 2024 7:28 am So can we get .ogg opus support in new factorio versions?
Music files will reduced in size greatly if opus will be used.
Most likely yes, soon. We're doing testing and comparisons now, finalizing encoding settings.

Right now it's looking like a ~23% disk size reduction when matching the quality of what we're using now with Vorbis. I was aiming (and hoping) for larger reduction but that would mean a reduction in quality, which I'm not willing to do.
vadcx
Long Handed Inserter
Long Handed Inserter
Posts: 51
Joined: Fri Apr 19, 2024 4:12 pm
Contact:

Re: Version 1.1.63

Post by vadcx »

I'd love to read about what you've tried so far! In case you can't tell by the text below :lol:

I've written the bash script below to estimate if the "size on disk" overhead is too much (inspired by your wording). Currently, assuming 4KiB sector size it only amounts to ~8 MiB overhead for all Space Age sounds. That's not enough to justify the effort to pack all sounds in some container format (to have 1 file with all sounds as opposed to 2000 small files).

How about increased frame size in Opus?
https://wiki.xiph.org/Opus_Recommended_ ... e_Tweaking
https://man.archlinux.org/man/opusenc.1
--framesize N
Set maximum frame size in milliseconds (2.5, 5, 10, 20, 40, 60, default: 20)
Smaller framesizes achieve lower latency but less quality at a given bitrate.
Sizes greater than 20ms are only interesting at fairly low bitrates.
Finally I've looked at environmental sounds like 'low-density-inventory-pickup', 'turret-inventory-move' - in the current Vorbis their frequencies end at either ~10kHz or have a very quiet curve and cap around 12kHz. I am not sure how encoders/codecs handle this, would it make sense to encode those at 24 kHz (Nyquist theorem) and at a lower bitrate than game music? In the end... it's just factory noise (with lots of love behind it, right? :D )

Code: Select all

#!/usr/bin/env bash

# Description: counts file sizes in the given folder to estimate the wasted space
# due to sector alignment overhead ("disk size" in Windows' terms).
#
# Example: with a sector size of 4096, but actual file data of 2000 bytes, 2096 allocated bytes on disk remain unused.
# In extreme cases, it would help to pack all files in a container format (say, .ZIP without compression or .tar)
# to avoid per-file overhead.

# USAGE:
# ./script.sh <target folder>


# EXAMPLE: 
# ./script "$HOME/.steam/steam/steamapps/common/Factorio/data/space-age/sound/"

# OPTIONS:
# Edit sector_size and max_size_deviation_percent if you want.

set -e
shopt -s nocasematch

target_dir="$1"

# Default is 4096 for Windows/NTFS, Linux filesystems
sector_size=4096
# If less than % of a sector is occupied, count this file for overhead calculation.
max_size_deviation_percent=50

size_bitmask=$(( $sector_size - 1 ))
divisor=$(( (100 / $max_size_deviation_percent ) ))

limit=$(( $sector_size / $divisor ))

printf "Disk sector size for calculations (must be a power of 2): %d\n" "${sector_size}"
printf "Count, if file size within '%d' bytes of sector size\n" "$limit"

total_files_matched=0
total_size_deviation_matched=0

test $divisor -eq 0 && exit 2;
test -d "$target_dir"
while read -d $'\0' line
do
    file_name="$(echo "$line" | cut -f2)"

    if [[ "$file_name" =~ \.(ogg|flac|opus|mp3)$ ]]; then
        byte_size="$(echo "$line" | cut -f1)"

        remainder=$(( $byte_size & $size_bitmask / $divisor ))

        echo "$remainder <= $limit; $byte_size bytes - $file_name"

        if [[ $remainder -le $limit ]] && [[ ! $remainder -eq 0 ]]; then

            total_files_matched=$(( total_files_matched + 1 ))
            total_size_deviation_matched=$(( total_size_deviation_matched + remainder ))

            #echo "counting... $total_files_matched ; $total_size_deviation_matched"
        fi
    else
        echo "File is not music: $file_name"
    fi

done < <(du --all --bytes -0 "$target_dir")

# need to count the sector space, once per file, that was not occupied by any data (the remaining free space in a sector)
total_overhead=$(( total_files_matched * sector_size - total_size_deviation_matched ))
printf "Total files matched: %d\n" "$total_files_matched"
printf "Their sector misaligned overhead amounts to: %d bytes.\n" "$total_overhead"
User avatar
BraveCaperCat
Fast Inserter
Fast Inserter
Posts: 242
Joined: Mon Jan 15, 2024 10:10 pm
Contact:

Re: Version 1.1.63

Post by BraveCaperCat »

As I say, again - this discussion should be moved to another thread.
Creator of multiple mods, including Quality Assurance - My most popular one. Expect multiple modding-related questions, answers and other posts.
Donion
Factorio Staff
Factorio Staff
Posts: 302
Joined: Sun Aug 22, 2021 9:18 am
Contact:

Re: Version 1.1.63

Post by Donion »

BraveCaperCat wrote: Fri Nov 15, 2024 9:16 pm As I say, again - this discussion should be moved to another thread.
I have moved the posts to a this new topic.
nastyslave
Inserter
Inserter
Posts: 43
Joined: Sat Aug 06, 2016 11:48 am
Contact:

Re: Version 1.1.63

Post by nastyslave »

Donion wrote: Fri Nov 15, 2024 12:02 pm
nastyslave wrote: Fri Nov 15, 2024 7:28 am So can we get .ogg opus support in new factorio versions?
Music files will reduced in size greatly if opus will be used.
Most likely yes, soon. We're doing testing and comparisons now, finalizing encoding settings.

Right now it's looking like a ~23% disk size reduction when matching the quality of what we're using now with Vorbis. I was aiming (and hoping) for larger reduction but that would mean a reduction in quality, which I'm not willing to do.
Great news, guys! Factorio will be more potimized optimized soon!
Waiting for any news!
Last edited by nastyslave on Wed Nov 20, 2024 9:44 pm, edited 1 time in total.
User avatar
BraveCaperCat
Fast Inserter
Fast Inserter
Posts: 242
Joined: Mon Jan 15, 2024 10:10 pm
Contact:

Re: Version 1.1.63

Post by BraveCaperCat »

Donion wrote: Mon Nov 18, 2024 6:48 pm
BraveCaperCat wrote: Fri Nov 15, 2024 9:16 pm As I say, again - this discussion should be moved to another thread.
I have moved the posts to a this new topic.
Thank you!
nastyslave wrote: Wed Nov 20, 2024 5:23 pm
Donion wrote: Fri Nov 15, 2024 12:02 pm
nastyslave wrote: Fri Nov 15, 2024 7:28 am So can we get .ogg opus support in new factorio versions?
Music files will reduced in size greatly if opus will be used.
Most likely yes, soon. We're doing testing and comparisons now, finalizing encoding settings.

Right now it's looking like a ~23% disk size reduction when matching the quality of what we're using now with Vorbis. I was aiming (and hoping) for larger reduction but that would mean a reduction in quality, which I'm not willing to do.
Great news, guys! Factorio will be more potimized soon!
Waiting for any news!
*optimized, not potimized. (would be really funny if they accidently added pots to factorio instead of optimizing it...)
Creator of multiple mods, including Quality Assurance - My most popular one. Expect multiple modding-related questions, answers and other posts.
Post Reply

Return to “Ideas and Suggestions”