6

I understand (maybe incorrectly) that webm audio files downloaded from youtube are basically vorbis streams inside an opus file structure. Is there a way to extract that stream and save it as an ogg file without transcoding? So far, all of my experiments have either produced just opus files with an ogg extension (using -c:a copy for example), or transcoded files that have a drastic loss of quality.

1 Answers1

12

.webm files indeed can contain vorbis audio, but it can also contain opus audio. Also an ogg file can contain both audio formats. One can transfer the audio without conversion to an .ogg file:

ffmpeg -i "$INPUTFILE" -vn -c:a copy "$(basename "$INPUTFILE" .webm)".ogg

If you need vorbis audio in an ogg container, but your .webm contains opus audio, then you need to transcode obviously.

In oggenc, a -q 6 setting will result in a file with variable bitrate at about 192 kbps. This is a setting where quality loss mostly will not be perceived anymore ("transparent"), and is a setting optimal to achieve excellent quality at a minimum file size. In ffmpeg, the corresponding option is -qscale:a 6:

ffmpeg -i "$INPUTFILE" -vn -c:a libvorbis -qscale:a 6 "$(basename "$INPUTFILE" .webm)".ogg

The range is -1 to 10, where 10 is very high quality.The default is -qscale:a 3, which corresponds to an average bitrate of about 112. (See full details)

vanadium
  • 88,010
  • Thanks. That's what I was afraid of. The webm files from youtube have opus audio in them, and my media player won't play them, even if embedded in an ogg file. I haven't found a way to transcode them without losing quality, or else hugely increasing file size. – doctordruidphd Jul 14 '20 at 12:28
  • Transcoding to vorbis should not lead to a huge increase in file size. Of course, there is (perceived or not) quality loss. Please consider accepting the question if it answers your concern (even not entirely to what you may have wished). – vanadium Jul 14 '20 at 12:33
  • This is great! And I am able to play Ogg Opus files without issue on my Android 11 phone. So there's no need to transcode in this case. – Serrano Pereira Jun 07 '21 at 18:41