Documentation
¶
Index ¶
- func AddImageType(types ...string)
- func AddVideoType(types ...string)
- func CalculateSimilarity(media1, media2 Media) float64
- func GroupMedia(media []Media, threshold float64) [][]Media
- func LoadAndGroupMedia(channel <-chan Result[Media], total int, threshold float64, ignoreErrors bool) <-chan LoadAndGroupResult
- func LoadMediaFromDirectory(directory string, options DirectoryOptions) (<-chan Result[Media], int)
- func LoadMediaFromFiles(filePaths []string, options FilesOptions) <-chan Result[Media]
- type DirectoryOptions
- type FilesOptions
- type FrameOptions
- type LoadAndGroupResult
- type Media
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddImageType ¶
func AddImageType(types ...string)
AddImageType adds one or more image type extensions to the list of valid image types.
func AddVideoType ¶
func AddVideoType(types ...string)
AddVideoType adds one or more video type extensions to the list of valid video types.
func CalculateSimilarity ¶
CalculateSimilarity computes a similarity score between two Media objects. Returns a value between 0 and 1, where higher values indicate greater similarity.
func GroupMedia ¶
GroupMedia organizes a list of media objects into groups based on a similarity threshold.
It uses a Disjoint Set Union (DSU) to cluster media items whose pairwise similarity score meets or exceeds the given threshold. Within each group (of at least two items), media are sorted by quality, prioritizing length, then resolution, then file size.
Parameters: ¶
- media: []Media Slice of Media objects to be grouped.
- threshold: float64 Similarity threshold (0.0–1.0) for merging two media items.
Returns: ¶
- [][]Media A two-dimensional slice where each inner slice represents a group of media items (minimum length of 2), sorted by quality descending.
func LoadAndGroupMedia ¶
func LoadAndGroupMedia( channel <-chan Result[Media], total int, threshold float64, ignoreErrors bool, ) <-chan LoadAndGroupResult
LoadAndGroupMedia performs media loading and similarity grouping in a single pass.
As each media item arrives from the input channel, it is immediately compared against all previously loaded items. Matches (similarity >= threshold) are unioned in a DSU. When the channel closes, groups are extracted.
Parameters: ¶
- channel: A channel of Result[Media] from LoadMediaFromFiles or LoadMediaFromDirectory.
- total: The expected total number of items (used for DSU pre-allocation).
- threshold: Similarity threshold (0.0–1.0) for merging two media items.
- ignoreErrors: If true, loading errors are skipped; if false, the first error terminates processing.
Returns: ¶
- A channel of LoadAndGroupResult messages reporting progress and the final result.
func LoadMediaFromDirectory ¶
func LoadMediaFromDirectory(directory string, options DirectoryOptions) (<-chan Result[Media], int)
LoadMediaFromDirectory loads Media objects from a specified directory based on the provided options.
Parameters: ¶
- directory: The path to the directory containing media files.
- options: A DirectoryOptions struct specifying the configuration for loading media.
Returns: ¶
- A channel that will receive Result[Media] objects for each valid file processed.
- An integer representing the total number of files that will be processed.
func LoadMediaFromFiles ¶
func LoadMediaFromFiles(filePaths []string, options FilesOptions) <-chan Result[Media]
LoadMediaFromFiles loads Media objects from an array of file paths.
Parameters: ¶
- filePaths: An array of strings containing the paths to the image or video files.
- options: The configuration options for loading multiple files.
Returns: ¶
- A channel that will receive Media objects for each valid file processed.
- An error if there is an issue opening or decoding any of the files.
Types ¶
type DirectoryOptions ¶
type DirectoryOptions struct {
IncludeImages bool
IncludeVideos bool
IsRecursive bool
Parallel int
FrameOptions
}
DirectoryOptions represents the configuration options for loading media from a directory.
Fields: ¶
- IncludeImages: A flag indicating whether to include image files.
- IncludeVideos: A flag indicating whether to include video files.
- IsRecursive: A flag indicating whether to search subdirectories recursively.
- Parallel: The number of files to process in parallel.
- FrameOptions: Frame transformation options (flip, rotate).
func (*DirectoryOptions) SetDefaults ¶
func (o *DirectoryOptions) SetDefaults()
type FilesOptions ¶
type FilesOptions struct {
Parallel int
FrameOptions
}
FilesOptions represents the configuration options for processing multiple files.
Fields: ¶
- Parallel: The number of files to process in parallel.
- FrameOptions: Frame transformation options (flip, rotate).
func (*FilesOptions) SetDefaults ¶
func (o *FilesOptions) SetDefaults()
type FrameOptions ¶
FrameOptions represents the configuration options for loading media frames.
Fields: ¶
- FrameFlip: A flag indicating whether the frame should be flipped.
- FrameRotate: A flag indicating whether the frame should be rotated.
type LoadAndGroupResult ¶
type LoadAndGroupResult struct {
// Media is the item just loaded (nil on error or final message).
Media *Media
// Loaded is the number of items successfully loaded so far.
Loaded int
// Err is non-nil if this item had a loading error.
Err error
// Done is true on the final message; Groups will be populated.
Done bool
// Groups contains the final grouped result, only populated when Done is true.
Groups [][]Media
}
LoadAndGroupResult represents a progress update from the single-pass load-and-group operation.
type Media ¶
type Media struct {
// Name of the media.
Name string `json:"name"`
// Type of the media (e.g., image, video).
Type string `json:"type"`
// Width represents the width of the media in pixels.
Width int `json:"width"`
// Height represents the height of the media in pixels.
Height int `json:"height"`
// Size represents the size of the media file in bytes.
Size int64 `json:"size"`
// Length represents the duration of the media in seconds (for images this is always 0)
Length int `json:"length"`
// contains filtered or unexported fields
}
Media represents a media object.
func LoadMediaFromFile ¶
func LoadMediaFromFile(filePath string, options FrameOptions) (*Media, error)
LoadMediaFromFile loads a Media object from the given file path.
Parameters: ¶
- filePath: The path to the image or video file.
- options: The configuration options for loading frames.
Returns: ¶
- A pointer to a Media object containing the name and the converted image.
- An error if there is an issue opening or decoding the file.
func LoadMediaFromImages ¶
func LoadMediaFromImages(name string, images []image.Image, options FrameOptions) Media
LoadMediaFromImages creates a Media object from the given image or video.
Parameters: ¶
- name: The name of the media.
- images: The images to be converted into a Media object.
- options: The configuration options for loading frames.
Returns: ¶
- A Media object containing the name, type and frames of the media.