Reclaimer icon indicating copy to clipboard operation
Reclaimer copied to clipboard

Incorrect conversion of (Halo 2) XBOX 4-bit IMA ADPCM due to ffmpeg

Open meowsandstuff opened this issue 1 year ago • 1 comments

When using ffmpeg to convert audio files encoded in the XBOX 4-bit IMA ADPCM format, the resulting output contains noticeable audible noise. This occurs when re-encoding to any format - even WAV. The quality degradation is significant, and the issue persists across multiple versions of ffmpeg. This problem appears to be specific to how ffmpeg handles this codec, and is not necessarily an issue with Reclaimer itself or it handles the re-encoding process, as I am unable to find any workarounds with ffmpeg that alleviate this issue.

The output should be a clean file without any added noise, preserving the original audio quality. However, the resulting file contains audible noise,

As an example, I'm providing a screenshot showing conversion of an Xbox IMA file from another game to FLAC using vgmstream (Flyaround_06), and then the same file in ffmpeg. You will be able to observe that the frequencies in the ffmpeg output have much more audible noise present. This same issue occurs in Halo 2.

image

Given this issue, I recommend switching from ffmpeg as a re-encoder to vgmstream for converting these files - specifically, vgmstream-cli. vgmstream handles these conversions with 100% clean output, preserving the original audio quality without the noise observed in ffmpeg. It should also support most (if not all) of the extracted sound tags from each Halo game, should sound extraction be added for these games down the line.

meowsandstuff avatar Sep 26 '24 05:09 meowsandstuff

This looks promising, albeit less flexible than ffmpeg. My main concern is that it doesn't appear to support receiving the file input via stdin. With ffmpeg, Reclaimer streams the sound data directly into the ffmpeg process, but with vgmstream it looks like it requires the input to be a file path. In a large batch extract this would create significant overhead since Reclaimer would have to write the data to disk for every permutation of every sound tag, then make sure it removes the temporary file(s) after conversion is done.

Gravemind2401 avatar Oct 11 '24 09:10 Gravemind2401

Apologies for the lack of response here 'til now.

Could you use named pipes in lieu of stdin? Might be a bit hacky, and the only reason I know of it is because of Linux, but I know you can do the same thing in Windows: https://en.wikipedia.org/wiki/Named_pipe

meowsandstuff avatar Nov 17 '24 03:11 meowsandstuff

Unfortunately named pipes don't work in this case. From what I can tell, it looks like vmgstream loops through all the formats it knows, testing the file against each one until it finds a match. This means it has to start from the beginning of the file again each time, which is not possible with named pipes since the data can only be read once.

Gravemind2401 avatar Nov 17 '24 07:11 Gravemind2401

@RevOcelotMGS can you post a sample ADPCM IMA XBOX file for testing. I will look into fixing ffmpeg.

rouseabout avatar Dec 10 '24 05:12 rouseabout

@RevOcelotMGS can you post a sample ADPCM IMA XBOX file for testing. I will look into fixing ffmpeg.

@rouseabout

I'm attaching three separate 4-bit Xbox IMA files for you to use as reference. Best of luck!

Some contextual information: battle_rifle_reload and fire_burst both come from Halo 2. Flyaround_06 is the sample file shown in my OP. This comes from a separate game (Crimson Skies: High Road to Revenge) and in its' current state when converted with ffmpeg has the most noticeable audio quality loss (out of various files tested).

I'm attaching a separate .flac of Flyaround_06 in the .zip which is converted using vgmstream-cli. If you need any more sample files, let me know.

imapcm.zip

meowsandstuff avatar Dec 11 '24 09:12 meowsandstuff

Thanks for providing samples.

ADPCM IMA Xbox .wav files now play back correctly in FFmpeg master: https://github.com/FFmpeg/FFmpeg/commit/b2cba76d4fe55c944bb4277c1c1def8597c1106b

rouseabout avatar Dec 22 '24 05:12 rouseabout

Tested, and verified the related issues are resolved. Thank you!

meowsandstuff avatar Dec 30 '24 20:12 meowsandstuff