video_storybook

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2024 License: MIT Imports: 7 Imported by: 0

README

Video Storybook

Video storybook (thumbnail sprite) generator library using ffmpeg.

Requirements

  • ffmpeg

Example

fileName := "./sample.mp4"
videoMetadata, err := vtsg.GetMetadata(fileName)

if err != nil {
    log.Fatalln("Error while reading video metadata: " + err.Error())
}

duration := videoMetadata.Duration
tileCount := int(math.Ceil(duration / float64(interval)))
tileWidth, tileHeight, err := vtsg.CalculateTileDimensions(videoMetadata.Width, videoMetadata.Height, maxTileWidth, maxTileHeight)

if err != nil {
    log.Fatalln("Error calculating tile dimensions: " + err.Error())
}

columns := min(tileCount, maxColumns)
rows := int(math.Ceil(float64(tileCount) / float64(maxColumns)))
storyboardBuffer, err := vtsg.GenerateStoryboardImage(fileName, interval, columns, rows, tileWidth, tileHeight)

if err != nil {
    log.Fatalln("Error creating storyboard: " + err.Error())
}

err = os.WriteFile(outputFileName, storyboardBuffer.Bytes(), 0777)

The sprite was generated from some Blender sample video.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculateTileDimensions

func CalculateTileDimensions(width int, height int, maxWidth int, maxHeight int) (int, int, error)

func GenerateStoryboardImage

func GenerateStoryboardImage(fileName string, interval int, columns int, rows int, tileWidth int, tileHeight int) (*bytes.Buffer, error)

Types

type StoryboardMetadata

type StoryboardMetadata struct {
	Url        string                   `json:"url"`
	TileWidth  int                      `json:"tile_width"`
	TileHeight int                      `json:"tile_height"`
	Duration   float64                  `json:"duration"`
	Tiles      []StoryboardMetadataTile `json:"tiles"`
}

func GenerateStoryboardMetadata

func GenerateStoryboardMetadata(url string, interval int, columns int, tileWidth int, tileHeight int, duration float64) StoryboardMetadata

type StoryboardMetadataTile

type StoryboardMetadataTile struct {
	Start float64 `json:"start"`
	X     int     `json:"x"`
	Y     int     `json:"y"`
}

type VideoMetadata

type VideoMetadata struct {
	Width    int
	Height   int
	Duration float64
}

func GetMetadata

func GetMetadata(fileName string) (VideoMetadata, error)

Jump to

Keyboard shortcuts

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