extract thubnail picture size from raw bytes in backend

This commit is contained in:
lukas 2021-05-12 23:29:47 +02:00
parent da07dc04bd
commit ef5bc2f597

View File

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