watermark

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 18, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PayloadVersion = 0x0001
	PayloadLength  = 16
)

Variables

View Source
var MimeToAssetType = map[string]string{
	"video/mp4":        "video",
	"video/quicktime":  "video",
	"video/x-matroska": "video",
	"image/jpeg":       "image",
	"image/png":        "image",
	"image/tiff":       "image",
	"image/webp":       "image",
}
View Source
var MimeToExt = map[string]string{
	"video/mp4":        ".mp4",
	"video/quicktime":  ".mov",
	"video/x-matroska": ".mkv",
	"image/jpeg":       ".jpg",
	"image/png":        ".png",
	"image/tiff":       ".tiff",
	"image/webp":       ".webp",
}

Functions

func BuildPayload

func BuildPayload(tokenID, campaignID string) []byte

BuildPayload constructs the 16-byte watermark payload per spec section 7.3:

Bytes 0–1:   Format version (0x0001)
Bytes 2–9:   Token ID (8 bytes, truncated SHA-256 of UUID string)
Bytes 10–13: Campaign ID (4 bytes, truncated SHA-256 of UUID string)
Bytes 14–15: CRC-16 checksum of bytes 0–13

func EscapeFFmpegText

func EscapeFFmpegText(s string) string

func ExtractImageThumbnail

func ExtractImageThumbnail(ctx context.Context, inputPath, outputPath string) error

func ExtractVideoThumbnail

func ExtractVideoThumbnail(ctx context.Context, inputPath, outputPath string, seekSecs float64) error

func FileSize

func FileSize(path string) (int64, error)

func GoInvisibleImageDetect added in v1.1.0

func GoInvisibleImageDetect(ctx context.Context, inputPath string, payloadLengthBytes int) (string, error)

GoInvisibleImageDetect extracts the DWT-DCT-SVD watermark from an image file. payloadLengthBytes is the number of payload bytes to extract (e.g., PayloadLength = 16). Returns the hex-encoded payload.

func GoInvisibleImageEmbed added in v1.1.0

func GoInvisibleImageEmbed(ctx context.Context, inputPath, outputPath, payloadHex string, jpegQuality int) error

GoInvisibleImageEmbed embeds a DWT-DCT-SVD invisible watermark into an image file, matching the Python imwatermark library's dwtDctSvd encoding.

inputPath must be JPEG, PNG, or WebP. outputPath extension determines the output format (JPEG recommended). payloadHex is the 32-character hex string (16 bytes = 128 bits). jpegQuality is the JPEG quality for the output file (e.g., 92).

func ImageWatermark

func ImageWatermark(ctx context.Context, p ImageParams) error

func InvisibleImageDetect

func InvisibleImageDetect(ctx context.Context, inputPath, pythonPath, scriptPath string, payloadLength int) (string, error)

InvisibleImageDetect extracts an invisible DWT-DCT watermark from an image. Returns the hex-encoded payload.

func InvisibleImageEmbed

func InvisibleImageEmbed(ctx context.Context, inputPath, outputPath, payloadHex, pythonPath, scriptPath string, jpegQuality int) error

InvisibleImageEmbed applies an invisible DWT-DCT watermark to an image using the Python invisible-watermark library.

func InvisibleVideoDetect

func InvisibleVideoDetect(ctx context.Context, videoPath, pythonPath, detectScript string, payloadLength int) ([]string, error)

InvisibleVideoDetect extracts key frames from a video and attempts to decode the invisible watermark from each. Returns all detected payload hex strings. The caller should perform majority voting to determine the most likely payload.

func InvisibleVideoEmbed

func InvisibleVideoEmbed(ctx context.Context, videoPath, payloadHex, pythonPath, embedScript string, framesDir string) error

InvisibleVideoEmbed embeds invisible watermarks into evenly-spaced key frames of a video file. Steps:

  1. Extract N evenly-spaced I-frames from the video
  2. Embed invisible watermark into each frame
  3. The watermarked frames are stored alongside the video for detection reference

Note: Full frame re-injection into the video stream is not performed in this version. The visible overlay from FFmpeg is the primary protection for video. Invisible watermarks on extracted frames provide a detection mechanism for clean digital copies.

func MajorityVote

func MajorityVote(payloads []string) string

MajorityVote returns the most frequently occurring string from a list.

func ParsePayload

func ParsePayload(data []byte) (tokenIDHex string, campaignIDHex string, valid bool)

ParsePayload validates and extracts fields from a 16-byte payload. Returns the hex-encoded token ID hash (8 bytes) and campaign ID hash (4 bytes), plus a boolean indicating whether the CRC validated.

func ParsePayloadFuzzy

func ParsePayloadFuzzy(data []byte) (tokenIDHex string, campaignIDHex string, plausible bool)

ParsePayloadFuzzy extracts token and campaign ID hashes from a 16-byte payload without requiring CRC validation. Used as a fallback when CRC fails due to minor bit errors from JPEG re-compression. Returns the hex-encoded hashes and whether the version field is close enough to be plausible.

func PayloadHex

func PayloadHex(tokenID, campaignID string) string

PayloadHex returns the hex-encoded payload string.

func SHA256File

func SHA256File(path string) (string, error)

func VideoWatermark

func VideoWatermark(ctx context.Context, p VideoParams) error

func WatermarkText

func WatermarkText(tokenID, recipientName string) string

Types

type ImageParams

type ImageParams struct {
	InputPath  string
	OutputPath string
	Text       string
	FontPath   string
}

type ProbeResult

type ProbeResult struct {
	DurationSecs float64
	Width        int
	Height       int
	VideoCodec   string
	AudioCodec   string
}

func Probe

func Probe(filePath string) (*ProbeResult, error)

type VideoParams

type VideoParams struct {
	InputPath  string
	OutputPath string
	Text       string
	FontPath   string
}

Directories

Path Synopsis
Package dct implements a 2D Type-II DCT and its inverse (Type-III).
Package dct implements a 2D Type-II DCT and its inverse (Type-III).
Package dwt implements a single-level 2D Haar Discrete Wavelet Transform.
Package dwt implements a single-level 2D Haar Discrete Wavelet Transform.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL