Tichau/FileConverter · error · Exception

The conversion preset must be valid.

Error message

The conversion preset must be valid.

What it means

ConversionJob_FFMPEG.Convert() throws Exception when this.ConversionPreset is null before iterating the ffmpeg pass list (ffmpegArgumentStringByPass) and launching the ffmpeg process. As the generic fallback created by ConversionJobFactory.Create for any output type not handled by a specialized job, it relies on the preset to build its argument passes during Initialize(). The base ctor already null-guards the preset, so reaching this line means the parameterless design-mode constructor or a reflection/direct-call path bypassed the real constructor.

Source

Thrown at Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.cs:432

            if (this.ffmpegArgumentStringByPass.Count == 0)
            {
                throw new Exception("No ffmpeg arguments generated.");
            }

            for (int index = 0; index < this.ffmpegArgumentStringByPass.Count; index++)
            {
                if (string.IsNullOrEmpty(this.ffmpegArgumentStringByPass[index].Arguments))
                {
                    throw new Exception("Invalid ffmpeg process arguments.");
                }
            }
        }
        
        protected override void Convert()
        {
            if (this.ConversionPreset == null)
            {
                throw new Exception("The conversion preset must be valid.");
            }

            for (int index = 0; index < this.ffmpegArgumentStringByPass.Count; index++)
            {
                FFMpegPass currentPass = this.ffmpegArgumentStringByPass[index];

                this.UserState = currentPass.Name;
                this.ffmpegProcessStartInfo.Arguments = currentPass.Arguments;

                Diagnostics.Debug.Log($"Execute command: {this.ffmpegProcessStartInfo.FileName} {this.ffmpegProcessStartInfo.Arguments}.");
                Diagnostics.Debug.Log(string.Empty);

                try
                {
                    using (Process exeProcess = Process.Start(this.ffmpegProcessStartInfo))
                    {
                        using (StreamReader reader = exeProcess.StandardError)
                        {

View on GitHub (pinned to 6c157a411f)

Solutions

  1. Always create the job with new ConversionJob_FFMPEG(conversionPreset, inputFilePath) (or via ConversionJobFactory.Create, which requires a non-null preset).
  2. Call PrepareConversion() then StartConversion(); do not invoke Convert() directly.
  3. For design-time, guard with if (ConversionPreset == null) return; at the top of Convert().
  4. Ensure the preset is loaded and non-null before ConversionJobFactory.Create is called.

Example fix

// before
var job = new ConversionJob_FFMPEG();
job.Convert(); // throws: preset null

// after
var job = ConversionJobFactory.Create(conversionPreset, inputFilePath);
job.PrepareConversion(outputFilePath);
job.StartConversion();
Defensive patterns

Strategy: validation

Validate before calling

if (job == null || job.ConversionPreset == null)
{
    throw new InvalidOperationException(
        "ConversionJob_FFMPEG requires a non-null ConversionPreset; create it via ConversionJobFactory.Create.");
}
job.StartConversion();

Type guard

private static bool HasValidPreset(ConversionJob job) => job != null && job.ConversionPreset != null;

Try / catch

try
{
    job.StartConversion();
}
catch (Exception ex) when (ex.Message.Contains("conversion preset must be valid"))
{
    logger.Error(ex, "FFMPEG job created without a preset; rebuilding.");
    job = ConversionJobFactory.Create(LoadPreset(), inputPath);
}

Prevention

When it happens

Trigger: ConversionJob_FFMPEG instantiated via its parameterless ctor then Convert() invoked; or Convert() called through reflection on an instance whose Initialize() never ran with a preset. Initialize() also separately throws 'Invalid ffmpeg process arguments.' when a pass has empty Arguments, but the preset guard precedes that loop.

Common situations: Design-time preview of an FFMPEG job; a test calling Convert() directly; a code path that constructed the generic fallback job before the preset was deserialized; misuse where the factory returned a job but the caller reset state.

Related errors


AI-assisted analysis of Tichau/FileConverter@6c157a411f (2026-08-13). Data as JSON: /api/errors/3a66e57a8046bd99. Report an issue: GitHub.