main
1// Package ffmpeg provides FFmpeg integration for timelapse generation.
2package ffmpeg
3
4import (
5 "fmt"
6 "os"
7 "path/filepath"
8 "strings"
9)
10
11// GenerateConcatFile creates an FFmpeg concat demuxer file.
12// Each path in the list is written as "file '<path>'" on its own line.
13// Paths are converted to absolute paths since ffmpeg's concat demuxer
14// resolves relative paths relative to the concat file's directory.
15func GenerateConcatFile(outputPath string, clipPaths []string) error {
16 var b strings.Builder
17
18 for _, path := range clipPaths {
19 // Convert to absolute path for ffmpeg concat demuxer
20 absPath, err := filepath.Abs(path)
21 if err != nil {
22 return fmt.Errorf("getting absolute path for %s: %w", path, err)
23 }
24 // Escape single quotes in path by replacing ' with '\''
25 escaped := strings.ReplaceAll(absPath, "'", "'\\''")
26 fmt.Fprintf(&b, "file '%s'\n", escaped)
27 }
28
29 err := os.WriteFile(outputPath, []byte(b.String()), 0644)
30 if err != nil {
31 return fmt.Errorf("writing concat file: %w", err)
32 }
33
34 return nil
35}