NickeManarin/ScreenToGif · error · Exception
Error while encoding the gif with Gifski. Empty output file.
Error message
Error while encoding the gif with Gifski. Empty output file.
What it means
After the Gifski encoding try/catch (which only logs exx and continues), EncodingManager checks gifskiGifPreset.FullPath: if the file does not exist or is zero bytes, it throws this Exception wrapping a Win32Exception and attaching Marshal.GetLastWin32Error() as HelpLink. The exception is raised whether the inner block threw (silently logged) or gifski simply produced nothing.
Source
Thrown at ScreenToGif/Util/EncodingManager.cs:909
throw new Exception("Error while adding frames with Gifski. " + res, new Win32Exception(res.ToString())) { HelpLink = $"Result:\n\r{Marshal.GetLastWin32Error()}" };
}
Update(id, EncodingStatus.Processing, null, false);
gifski.EndAdding(handle);
#endregion
}
}
catch (Exception exx)
{
LogWriter.Log(exx, "gifski");
}
var fileInfo2 = new FileInfo(gifskiGifPreset.FullPath);
if (!fileInfo2.Exists || fileInfo2.Length == 0)
throw new Exception("Error while encoding the gif with Gifski. Empty output file.", new Win32Exception()) { HelpLink = $"Result:\n\r{Marshal.GetLastWin32Error()}" };
#endregion
break;
}
default:
throw new Exception("Undefined Gif encoder type");
}
Update(id, 1, watch.Elapsed);
watch.Restart();
break;
#endregion
}
View on GitHub (pinned to a4d0a67c21)
Solutions
- Inspect LogWriter's 'gifski' entries — the swallowed inner exception has the real cause.
- Upgrade gifski.dll to the latest x64 release and re-run the export.
- Verify the output folder is writable and excluded from AV scanning.
- Reduce frame count / resolution and retry; if it succeeds, the cause was memory or a specific frame.
Example fix
// before
catch (Exception exx)
{
LogWriter.Log(exx, "gifski");
}
var fileInfo2 = new FileInfo(gifskiGifPreset.FullPath);
if (!fileInfo2.Exists || fileInfo2.Length == 0)
throw new Exception("Error while encoding the gif with Gifski. Empty output file.", new Win32Exception()) { HelpLink = $"Result:\n\r{Marshal.GetLastWin32Error()}" };
// after
Exception innerCause = null;
try { /* gifski add frames + end adding */ }
catch (Exception exx) { LogWriter.Log(exx, "gifski"); innerCause = exx; }
var fileInfo2 = new FileInfo(gifskiGifPreset.FullPath);
if (!fileInfo2.Exists || fileInfo2.Length == 0)
throw new Exception("Error while encoding the gif with Gifski. Empty output file.", innerCause ?? new Win32Exception()) { HelpLink = $"Result:\n\r{Marshal.GetLastWin32Error()}" }; Defensive patterns
Strategy: try-catch
Validate before calling
// Validate output folder writability before encoding var dir = Path.GetDirectoryName(gifskiGifPreset.FullPath); if (!Directory.Exists(dir) || !HasWriteAccess(dir)) /* warn user */
Type guard
// n/a
Try / catch
try { /* gifski add frames + EndAdding */ }
catch (Exception exx) { LogWriter.Log(exx, "gifski"); lastGifskiError = exx; }
finally
{
var fi = new FileInfo(gifskiGifPreset.FullPath);
if (!fi.Exists || fi.Length == 0)
throw new Exception("Empty Gifski output.", lastGifskiError);
} Prevention
- Don't swallow the inner gifski exception silently — keep it as the inner exception of the rethrow.
- Verify the gifski.dll version matches the API the interop layer expects (IsOlderThan0Dot9).
- Validate every frame file exists and is readable before calling AddFrame.
When it happens
Trigger: The inner try completed (or threw and was caught+logged) but new FileInfo(gifskiGifPreset.FullPath).Exists is false or Length == 0. Causes: gifski.AddFrame returned non-Ok (and its own throw was swallowed by the catch), gifski native code crashed, the output path was unwritable, or no EndAdding was reached.
Common situations: Gifski version mismatch (e.g. < 0.9 API used against newer DLL); corrupted frame PNGs fed to gifski; out of memory / very large frame count; antivirus quarantining the partial output; output folder permissions; gifski.Start returned an invalid handle that produced no data.
Related errors
- Gifski not present.
- Error while encoding the {preset.Type} with FFmpeg.
- FFmpeg not present.
- Missing upload preset called {preset.UploadService}
- history.Message
AI-assisted analysis of NickeManarin/ScreenToGif@a4d0a67c21 (2026-08-13).
Data as JSON: /api/errors/b893c3bfebaeae2c.
Report an issue: GitHub.