Browse Source

feat: add checking ffmpeg when submit video

pull/136/head
Aldino Kemal 2 years ago
parent
commit
bd0369e45d
  1. 3
      src/cmd/root.go
  2. 11
      src/services/send.go

3
src/cmd/root.go

@ -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{

11
src/services/send.go

@ -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)
@ -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()

Loading…
Cancel
Save