Skip to content

Commit 50b76d1

Browse files
Refactor video processing to extract variant generation logic into a separate function
1 parent dfa15e9 commit 50b76d1

2 files changed

Lines changed: 43 additions & 27 deletions

File tree

internal/handlers/variants.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package handlers
2+
3+
import (
4+
"context"
5+
"log"
6+
"path/filepath"
7+
8+
"github.com/Prateet-Github/worker-go/internal/ffmpeg"
9+
)
10+
11+
func (h *VideoHandler) generateVariants(
12+
ctx context.Context,
13+
inputPath string,
14+
outputDir string,
15+
) error {
16+
17+
for _, rendition := range ffmpeg.Renditions {
18+
19+
renditionDir := filepath.Join(
20+
outputDir,
21+
rendition.Name,
22+
)
23+
24+
log.Printf("Generating %s...", rendition.Name)
25+
26+
if err := h.ffmpeg.GenerateVariant(
27+
ctx,
28+
inputPath,
29+
renditionDir,
30+
rendition,
31+
); err != nil {
32+
return err
33+
}
34+
}
35+
36+
return nil
37+
}

internal/handlers/video.go

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -82,33 +82,12 @@ func (h *VideoHandler) ProcessVideo(
8282

8383
log.Println("Generating HLS...")
8484

85-
// if err := h.ffmpeg.GenerateVariant(
86-
// ctx,
87-
// inputPath,
88-
// outputDir,
89-
// ffmpeg.Renditions[1],
90-
// ); err != nil {
91-
// log.Printf("GenerateHLS failed: %v", err)
92-
// return err
93-
// }
94-
95-
for _, rendition := range ffmpeg.Renditions {
96-
97-
renditionDir := filepath.Join(
98-
outputDir,
99-
rendition.Name,
100-
)
101-
102-
log.Printf("Generating %s...", rendition.Name)
103-
104-
if err := h.ffmpeg.GenerateVariant(
105-
ctx,
106-
inputPath,
107-
renditionDir,
108-
rendition,
109-
); err != nil {
110-
return err
111-
}
85+
if err := h.generateVariants(
86+
ctx,
87+
inputPath,
88+
outputDir,
89+
); err != nil {
90+
return err
11291
}
11392

11493
log.Println("HLS generated")

0 commit comments

Comments
 (0)