From ef5bc2f5975ec710b24f77fdf4ad1d5f6691292f Mon Sep 17 00:00:00 2001 From: lukas Date: Wed, 12 May 2021 23:29:47 +0200 Subject: [PATCH] extract thubnail picture size from raw bytes in backend --- apiGo/videoparser/Helpers.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/apiGo/videoparser/Helpers.go b/apiGo/videoparser/Helpers.go index 3c82b45..5de6b96 100644 --- a/apiGo/videoparser/Helpers.go +++ b/apiGo/videoparser/Helpers.go @@ -1,9 +1,12 @@ package videoparser import ( + "bytes" "encoding/base64" "encoding/json" "fmt" + "image/jpeg" + "log" "os/exec" "strconv" ) @@ -76,6 +79,16 @@ func parseFFmpegPic(path string) (*string, error) { if strEncPic == "" { return nil, nil } + + // extract dimensions of picture + reader := bytes.NewReader(stdout) + im, err := jpeg.DecodeConfig(reader) + if err != nil { + log.Fatal(err) + } + fmt.Printf("%d %d\n", im.Width, im.Height) + // todo use this information somewhere... + backpic64 := fmt.Sprintf("data:image/jpeg;base64,%s", strEncPic) return &backpic64, nil @@ -106,6 +119,11 @@ func getVideoAttributes(path string) *VideoAttributes { return nil } + // nil slice check of track array + if len(t.Media.Track) == 0 { + return nil + } + duration, err := strconv.ParseFloat(t.Media.Track[0].Duration, 32) filesize, err := strconv.Atoi(t.Media.Track[0].FileSize) width, err := strconv.Atoi(t.Media.Track[1].Width)