NickeManarin/ScreenToGif · error · Exception
Error while encoding the {preset.Type} with FFmpeg.
Error message
Error while encoding the {preset.Type} with FFmpeg. What it means
EncodeWithFfmpeg completes the ffmpeg process run (optionally a second pass) and then inspects new FileInfo(preset.FullPath). If the output file does not exist or has Length == 0, it throws Exception with a HelpLink carrying the firstPass+secondPass commands and the captured ffmpeg log. The exception means ffmpeg ran but produced no usable output.
Source
Thrown at ScreenToGif/Util/EncodingManager.cs:1862
}
var fileInfo = new FileInfo(preset.FullPath);
//Execute the second pass, cleaning up the logs.
if (!string.IsNullOrWhiteSpace(secondPass))
{
//I could try using as a single command.
//ffmpeg -y -hwaccel auto {I} -c:v h264_nvenc -pix_fmt yuv420p -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" -pass 1 -f avi NUL
//&&
//ffmpeg -y -hwaccel auto {I} -c:v h264_nvenc -pix_fmt yuv420p -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" -pass 2 -f avi {O}
log += Environment.NewLine + SecondPassFfmpeg(secondPass, id, tokenSource, LocalizationHelper.Get("S.Encoder.Processing.Second"));
EraseSecondPassLogs(preset.FullPath);
}
if (!fileInfo.Exists || fileInfo.Length == 0)
throw new Exception($"Error while encoding the {preset.Type} with FFmpeg.") { HelpLink = $"Command:\n\r{firstPass + Environment.NewLine + secondPass}\n\rResult:\n\r{log}" };
}
private static string SecondPassFfmpeg(string command, int id, CancellationTokenSource tokenSource, string processing)
{
var log = "";
var process = new ProcessStartInfo(UserSettings.All.FfmpegLocation)
{
Arguments = command,
CreateNoWindow = true,
ErrorDialog = false,
UseShellExecute = false,
RedirectStandardError = true
};
using (var pro = Process.Start(process))
{
var indeterminate = true;View on GitHub (pinned to a4d0a67c21)
Solutions
- Read the HelpLink — it contains the exact ffmpeg commands and the full log identifying the failure line.
- Update ffmpeg to a recent static build that includes the needed encoders (libx264, libvpx-vp9, etc.).
- If using hardware acceleration (nvenc/qsv), verify the GPU supports it or fall back to software encoders.
- Verify preset.FullPath's folder is writable and excluded from AV scanning.
Example fix
// before
if (!fileInfo.Exists || fileInfo.Length == 0)
throw new Exception($"Error while encoding the {preset.Type} with FFmpeg.") { HelpLink = $"Command:\n\r{firstPass + Environment.NewLine + secondPass}\n\rResult:\n\r{log}" };
// after
if (!fileInfo.Exists || fileInfo.Length == 0)
throw new Exception($"Error while encoding the {preset.Type} with FFmpeg. Output missing or empty. See HelpLink for command and log.") { HelpLink = $"Command:\n\r{firstPass + Environment.NewLine + secondPass}\n\rResult:\n\r{log}" }; Defensive patterns
Strategy: try-catch
Validate before calling
// Pre-flight: confirm the encoder exists in this ffmpeg build var encoders = await PathHelper.GetFfmpegEncoders(); // -encoders output parsed if (!encoders.Contains(requiredEncoder)) /* warn user */
Type guard
// n/a
Try / catch
try { await EncodeWithFfmpeg(...); }
catch (Exception ex)
{
var log = ex.HelpLink; // contains command + ffmpeg log
LogWriter.Log(ex, $"ffmpeg encode failed.\n{log}");
throw;
} Prevention
- Always read the HelpLink — it carries the exact command and ffmpeg's error log.
- Keep ffmpeg up to date; older builds lack modern encoders (nvenc, libvpx-vp9, av1).
- Validate the output folder is writable and AV-excluded before starting a long encode.
When it happens
Trigger: ffmpeg exited but preset.FullPath is missing or zero bytes. Typical causes: ffmpeg returned non-zero (bad codec, missing encoder build, invalid filter), the two-pass first pass failed silently, an invalid scale/pix_fmt argument, frames missing on disk, or the output path was unwritable.
Common situations: ffmpeg build without the required encoder (e.g. no libx264 / libvpx / h264_nvenc); older ffmpeg version (HasOlderFfmpegVersion) using deprecated flags; corrupted/empty source frames; AV quarantining output; unsupported hardware acceleration flag on a GPU that lacks it.
Related errors
- Error while encoding the gif with Gifski. Empty output file.
- FFmpeg not present.
- Gifski not present.
- Error while capturing frames with FFmpeg.
- Missing upload preset called {preset.UploadService}
AI-assisted analysis of NickeManarin/ScreenToGif@a4d0a67c21 (2026-08-13).
Data as JSON: /api/errors/cbc31121fd1086ff.
Report an issue: GitHub.