.opus file extension changes to .ogg in Opus file attachments

Aivaras

Well-known member
Affected version
v2.2.17, including the current version of xenforo.com
When I attach a file with the .opus extension to a post, the extension gets changed to .ogg during the process. If I then download the .ogg file, it still plays back as Opus. So it seems that XF automatically encapsulates Opus files in the OGG container. Why does this happen, and can it be avoided? We use Opus files as digital products, and changing their extensions is very misleading.

A possible cause of the problem may be 'opus' => 'audio/ogg' instead of 'opus' => 'audio/opus' in the snippet below:

 
So it seems that XF automatically encapsulates Opus files in the OGG container.
I dont think so, XenForo doesn't modify the file - it just changes the extension.

Why does this happen, and can it be avoided?

Opus packets are not self-delimiting, but are designed to be used inside a container of some sort which supplies the decoder with each packet's length. Opus was originally specified for encapsulation in Ogg containers, specified as audio/ogg; codecs=opus, and for Ogg Opus files the .opus filename extension is recommended.
So most likely your .opus files are Ogg containers that contain opus audio.
When XenForo detects an Ogg container, it automatically changes the fie extension to .ogg.
This isn't wrong technically as it is an Ogg container after all, but I understand why this may be confusing.

To avoid this you can add a little patch to XF/Http/Upload.php

Add
PHP:
// check if it is opus which has recommended file extension .opus and set this instead of .ogg
$first64 = substr($preamble, 0, 128);
if (strpos($first64, '4F70757348656164') !== false)
{
    $audioType = 'opus';
}
after
PHP:
$audioType = 'ogg';
and .opus files that are Ogg containers with opus audio should stay .opus (but .ogg files with opus audio will be changed to .opus).

A possible cause of the problem may be 'opus' => 'audio/ogg' instead of 'opus' => 'audio/opus' in the snippet below:
audio/ogg is the correct MIME type for an ogg container with opus audio.
 
Last edited:
Hi Kirby,

Thank you very much for your insights, suggestions, and explanations—they’re highly appreciated!

So most likely your .opus files are Ogg containers that contain opus audio.
Yes, FFprobe (FFmpeg) reports that the files are contained in OGG, as expected. That’s not the issue. The issue lies with the file extension.

When XenForo detects an Ogg container, it automatically changes the fie extension to .ogg.
This isn't wrong technically as it is an Ogg container after all, but I understand why this may be confusing.
I’m not sure I can agree here (the “isn’t wrong” bit).

1) See the Official Opus file format specification, RFC 7845 > Section 9: Content Type:


which clearly states:
The RECOMMENDED filename extension for Ogg Opus files is '.opus'.

2) In the audio world—including professional audio production and authoring software—the .ogg extension is reserved for Ogg Vorbis, a completely different codec. While still widely used, Vorbis is deprecated, and Opus is its successor.

audio/ogg is the correct MIME type for an ogg container with opus audio.
Yes, this is in line with RFC 7845.
 
Last edited:
In the audio world—including professional audio production and authoring software—the .ogg extension is reserved for Ogg Vorbis
I don't see anything in the linked RFC that backs your claim, it is only mentioned that .opus is recommended for ogg opus (and .ogg for ogg vorbis according to RFC5334).
So unless there is some statement in this (or another RFC) that kinda enforces .opus via MUST I'd say XF use is kinda acceptable, though not ideal.
 
Back
Top Bottom