libobs: Add gs_save_png_file - #777
Merged
Merged
Conversation
Lets callers without Qt (obs-studio-node's screenshot IPC) save a PNG using libobs' existing FFmpeg encoder instead of vendoring an image writer. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Integer overflow and narrowing can bypass input validation and pass invalid dimensions or strides to FFmpeg.
Review effort: Balanced
Findings: 1
What changed in this PR
Adds PNG encoding to libobs using FFmpeg, enabling consumers to save texture data without bundling another encoder.
Changes:
- Exports
gs_save_png_file. - Supports RGBA, BGRA, BGRX, padded row pitches, and UTF-8 paths.
| File | Description |
|---|---|
libobs/graphics/graphics.h |
Declares the PNG-saving API. |
libobs/graphics/graphics-ffmpeg.c |
Implements validation, conversion, encoding, writing, and cleanup. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
cx * 4 could wrap in uint32_t and bypass the pitch check, and values above INT_MAX were narrowed into invalid FFmpeg arguments. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
A failure after opening the destination unlinked it even when it already existed. Writing to <file>.tmp and replacing on success leaves an existing file untouched on failure. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
A direct write is enough for screenshots: "wb" already truncates an existing destination, so removing the partial file on failure loses nothing. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Problem: obs-studio-node needs to write a screenshot PNG (streamlabs/obs-studio-node#1786). libobs can decode images but not write them, so that PR vendors stb_image_write.
Change: export
gs_save_png_file(file, data, format, cx, cy, linesize)next togs_create_texture_file_data, encoding with the FFmpeg PNG encoder libobs already links. Accepts RGBA/BGRA/BGRX (BGRX -> opaque), honours row pitch, writes viaos_fopenfor UTF-8 paths, and removes a partial file only if it created it.Effect: no behaviour change for existing code; osn can drop stb once this ships.
Testing:
cmake --build build_x64 --config RelWithDebInfo --target libobs(Windows x64): 0 warnings/errorsgs_create_texture_file_datawith padded pitch, 6 invalid-arg rejections, non-ASCII filename, existing file preserved on rejected call -- 11/11 pass🤖 Generated with Claude Code