Need help getting my custom FLAC ffmpeg extraArgs working

Discussion of advanced MakeMKV functionality, expert mode, conversion profiles
Post Reply
Message
Author
DoctorHorsey
Posts: 9
Joined: Thu Dec 20, 2018 11:28 am

Need help getting my custom FLAC ffmpeg extraArgs working

#1 Post by DoctorHorsey » Sun Mar 01, 2020 9:44 am

Hello :)

I've been trying to create a custom conversion profile for MakeMKV, to achieve downsampled 16-bit 48-kHz FLAC tracks.

I've fiddled around with Google and my local ffmpeg binary, and I'm currently trying to replicate

Code: Select all

-compression_level 12 -af aresample=48000:resampler=soxr:precision=32:dither_method=shibata -sample_fmt s16
ffmpeg arguments in my modified /Users/daniel/Library/MakeMKV/flac-16-48.mmcp.xml profile:

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<profile>
    <!-- profile name - Default -->
    <name lang="eng">FLAC-16/48</name>

    <!-- Common MKV flags -->
    <mkvSettings
        ignoreForcedSubtitlesFlag="true"
        useISO639Type2T="false"
        setFirstAudioTrackAsDefault="true"
        setFirstSubtitleTrackAsDefault="true"
        setFirstForcedSubtitleTrackAsDefault="true"
        insertFirstChapter00IfMissing="true"
    />

    <!-- Output formats currently supported by MakeMKV -->
    <outputSettings name="copy" outputFormat="directCopy">
        <description lang="eng">Copy track as-is</description>
    </outputSettings>

    <outputSettings name="lpcm" outputFormat="LPCM-raw">
        <description lang="eng">Save as raw LPCM</description>
    </outputSettings>

    <outputSettings name="wavex" outputFormat="LPCM-wavex">
        <description lang="eng">Save as LPCM in WAV container</description>
    </outputSettings>

    <outputSettings name="flac-1648" outputFormat="FLAC">
        <description lang="eng">Save as 16-bit 48-kHz FLAC (best compression)</description>
        <extraArgs>-compression_level 12 -af aresample=48000:resampler=soxr:precision=32:dither_method=shibata -sample_fmt s16</extraArgs>
    </outputSettings>

    <!-- Default rule - copy as is -->
    <trackSettings input="default">
        <output outputSettingsName="copy"
                defaultSelection="$app_DefaultSelectionString">
        </output>
    </trackSettings>

    <!-- Save LPCM mono or stereo as FLAC -->
    <trackSettings input="LPCM-stereo">
        <output outputSettingsName="flac-1648"
                defaultSelection="$app_DefaultSelectionString">
        </output>
    </trackSettings>

    <!-- Save multi-channel LPCM as FLAC -->
    <trackSettings input="LPCM-multi">
        <output outputSettingsName="flac-1648"
                defaultSelection="$app_DefaultSelectionString,+sel:true">
        </output>
    </trackSettings>

    <!-- Save TRUEHD as FLAC -->
    <trackSettings input="TRUEHD-stereo">
        <output outputSettingsName="flac-1648"
                defaultSelection="$app_DefaultSelectionString,+sel:true">
        </output>
    </trackSettings>
    <trackSettings input="TRUEHD-multi">
        <output outputSettingsName="flac-1648"
                defaultSelection="$app_DefaultSelectionString,+sel:true">
        </output>
    </trackSettings>
    <trackSettings input="MLP-stereo">
        <output outputSettingsName="flac-1648"
                defaultSelection="$app_DefaultSelectionString,+sel:true">
        </output>
    </trackSettings>
    <trackSettings input="MLP-multi">
        <output outputSettingsName="flac-1648"
                defaultSelection="$app_DefaultSelectionString,+sel:true">
        </output>
    </trackSettings>

    <!-- Save DTS-HD as FLAC -->
    <trackSettings input="DTSHDMA-stereo">
        <output outputSettingsName="flac-1648"
                defaultSelection="$app_DefaultSelectionString,+sel:true">
        </output>
    </trackSettings>
    <trackSettings input="DTSHDMA-multi">
        <output outputSettingsName="flac-1648"
                defaultSelection="$app_DefaultSelectionString,+sel:true">
        </output>
    </trackSettings>

    <!-- Save DTS-HD LBR (low quality) as FLAC (just to decode) -->
    <trackSettings input="DTSHDLBR-stereo">
        <output outputSettingsName="flac-1648"
                defaultSelection="$app_DefaultSelectionString">
        </output>
    </trackSettings>
    <trackSettings input="DTSHDLBR-multi">
        <output outputSettingsName="flac-1648"
                defaultSelection="$app_DefaultSelectionString">
        </output>
    </trackSettings>

</profile>
The odd thing is, I can use the profile in MakeMKV without any problems, but the downsampling arguments just seem to be ignored, while the `compression_level` argument is picked up. That is, changing any of the resampling options yields exactly the same 24-bit FLAC output, but changing the compression level yields FLAC tracks of slightly differing sizes. So, the `extraArguments` string is picked up, it's just partially "ignored."

I was thinking it might be that the embedded ffmpeg was built without SoX support, but no matter how non-specific and non-SoX I make the resampling arguments, I can't get anything to have an effect on the output.

It almost feels like there's some kind of layer that pre-parses the `extraArgs` string and selects predetermined values before building a final argument string to be used with ffmpeg. Is there, or am I just misunderstanding how to do this? (Hoping for the latter :D)

Thanks! :)

EDIT: Since waiting for this post to be approved, I've made a few changes and done some more research. First of all, I've looked at the AAC profile that's bundled with MakeMKV, and noticed that you can add multiple <extraArgs/> nodes in the XML, so I've tried using that as well, to split up each argument in its own node. This does not make a difference.

Secondly, I've noticed that I can put pretty much any garbage option in the extraArgs string, such as "-non_existent_argument hello -compression_level 12", and still have MakeMKV pick up the compression_level argument, while my garbage argument doesn't produce any errors. This, to me, seems to point to my hunch that there's some kind of preprocessing, or whitelisting, going in in MakeMKV before it produces its arguments for ffmpeg. I mean, considering that there's no ffmpeg binary bundled, but what appears to be an ffmpeg library (/Applications/MakeMKV.app/Contents/MacOS/libffm.dylib), it seems like my assumption that these values are arguments for ffmpeg is wrong, and that they're actually arguments for MakeMKV, just named similarly for convenience and transparency as to what they actually do.

If this is correct, does this mean that we cannot actually add custom arguments for ffmpeg via extraArgs? Does anyone know?

Also, if so, I've noticed the "outputBPS" attribute in the AAC profile's XML, which seems to do downsampling to 16 bits per sample, but there's no clue as to what method is used to achieved this, and if there are more attributes like these available, e.g. "outputSR" for resampling to 48 kHz. It'd be nice to have the source code to refer to in lieu of documentation :D

Post Reply