Skip to content

Commit

Permalink
feat: add checking ffmpeg when submit video
Browse files Browse the repository at this point in the history
  • Loading branch information
Aldino Kemal authored and Aldino Kemal committed Apr 19, 2024
1 parent 25ab6b5 commit bd0369e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ func runRest(_ *cobra.Command, _ []string) {
return token != nil
})
app := fiber.New(fiber.Config{
Views: engine,
Views: engine,
BodyLimit: int(config.WhatsappSettingMaxVideoSize),
})
app.Static("/statics", "./statics")
app.Use("/components", filesystem.New(filesystem.Config{
Expand Down
11 changes: 6 additions & 5 deletions src/services/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,12 @@ func (service serviceSend) SendVideo(ctx context.Context, request domainSend.Vid
return response, pkgError.InternalServerError(fmt.Sprintf("failed to store video in server %v", err))
}

// Check if ffmpeg is installed
_, err = exec.LookPath("ffmpeg")
if err != nil {
return response, pkgError.InternalServerError("ffmpeg not installed")
}

// Get thumbnail video with ffmpeg
thumbnailVideoPath := fmt.Sprintf("%s/%s", config.PathSendItems, generateUUID+".png")
cmdThumbnail := exec.Command("ffmpeg", "-i", oriVideoPath, "-ss", "00:00:01.000", "-vframes", "1", thumbnailVideoPath)
Expand All @@ -276,11 +282,6 @@ func (service serviceSend) SendVideo(ctx context.Context, request domainSend.Vid

if request.Compress {
compresVideoPath := fmt.Sprintf("%s/%s", config.PathSendItems, generateUUID+".mp4")
// Compress video with ffmpeg, check if ffmpeg is installed
_, err = exec.LookPath("ffmpeg")
if err != nil {
return response, pkgError.InternalServerError("ffmpeg not installed")
}

cmdCompress := exec.Command("ffmpeg", "-i", oriVideoPath, "-strict", "-2", compresVideoPath)
err = cmdCompress.Run()
Expand Down

0 comments on commit bd0369e

Please sign in to comment.