I have come across a strange problem when remuxing Opus audio stream from WebM to another container like ogg or opus.
Running the output files through a spectrum analyzer clearly shows that there is loss/change in the data. I'm not sure if the results are 100% accurate, though multiple programs confirm it. I've tried multiple methods using both FFmpeg and MKVExtract, but in both cases, the extracted files have noticeable differences (also in size).
After thorough research, I found out about this bug in FFmpeg which could explain the misalignment and thus the change in file size. But there seems to be more going on here. I converted the source and all extracted files to 32-bit WAVs using Audacity, then analyzed them again. The offset is even more pronounced in this case, along with the difference in the actual data.
Are there any more robust testing methods and reliable tools for more convenient batch processing if necessary?
This is the spectrum output from Audacity and Spek with some additional info:
Source file: audio.webm
Size: 2.94 MB
Spek: https://i.imgur.com/5NtmwG7.png
Audacity: https://i.imgur.com/hEs8Ajo.png
Extracted file using FFmpeg: audio_extracted_ffmpeg.opus
Size: 2.90 MB
Spek: https://i.imgur.com/5UBV3FV.png
Audacity: https://i.imgur.com/lsZl0Bt.png
Extracted file using MKVExtract: audio_extracted_mkvextract.opus
Size: 2.91 MB
Spek: https://i.imgur.com/waa1TOJ.png
Audacity: https://i.imgur.com/TAqyIst.png
Comparison between the source WebM and the FFmpeg Opus in Audacity:
Source file: https://i.imgur.com/xYciUfH.png
Extracted via FFmpeg: https://i.imgur.com/T8T02fx.png
This is the output of the FFmpeg extraction:
ffmpeg version 4.2 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 9.1.1 (GCC) 20190807
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt
libavutil 56. 31.100 / 56. 31.100
libavcodec 58. 54.100 / 58. 54.100
libavformat 58. 29.100 / 58. 29.100
libavdevice 58. 8.100 / 58. 8.100
libavfilter 7. 57.100 / 7. 57.100
libswscale 5. 5.100 / 5. 5.100
libswresample 3. 5.100 / 3. 5.100
libpostproc 55. 5.100 / 55. 5.100
Input #0, matroska,webm, from 'files/audio.webm':
Metadata:
encoder : google/video-file
Duration: 00:03:08.30, start: -0.007000, bitrate: 131 kb/s
Stream #0:0(eng): Audio: opus, 48000 Hz, stereo, fltp (default)
Output #0, opus, to 'files/ffmpeg/audio_extracted_ffmpeg.opus':
Metadata:
encoder : Lavf58.29.100
Stream #0:0(eng): Audio: opus, 48000 Hz, stereo, fltp (default)
Metadata:
encoder : Lavf58.29.100
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
size= 2975kB time=00:03:08.28 bitrate= 129.5kbits/s speed=6.57e+03x
video:0kB audio:2952kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.803061%
And MKVToolNix:
Extracting track 0 with the CodecID 'A_OPUS' to the file 'files/mkvextract/audio_extracted_mkvextract.opus'. Container format: Ogg (Opus in Ogg)
Progress: 100%
CLI params:
ffmpeg -i "source.webm" -vn -acodec copy "output.opus"
mkvextract "source.webm" tracks 0:"output.opus"
ffmpeg -i source.webm -c:a copy -vn output.opus && ffmpeg -i output.opus decoded_extracted.wav
andffmpeg -i source.webm decoded.wav
?