video aspect ratios categorized

This commit is contained in:
2025-03-16 10:24:09 +02:00
parent 1d0c56f493
commit 3c13056111
2 changed files with 57 additions and 1 deletions

36
main.go
View File

@@ -1,12 +1,16 @@
package main
import (
"bytes"
"context"
"encoding/json"
"fmt"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/s3"
"log"
"net/http"
"os"
"os/exec"
"github.com/bootdotdev/learn-file-storage-s3-golang-starter/internal/database"
@@ -32,6 +36,38 @@ type thumbnail struct {
mediaType string
}
func getVideoAspectRatio(filePath string) (string, error) {
cmd := exec.Command("ffprobe", "-v", "error", "-print_format", "json", "-show_streams", filePath)
var buffer bytes.Buffer
cmd.Stdout = &buffer
err := cmd.Run()
if err != nil {
return "", err
}
type Stream struct {
Index int `json:"index"`
Width int `json:"width"`
Height int `json:"height"`
DisplayAspectRatio string `json:"display_aspect_ratio"`
}
type VideoInfo struct {
Streams []Stream `json:"streams"`
}
var videoInfo VideoInfo
err = json.Unmarshal(buffer.Bytes(), &videoInfo)
if err != nil {
fmt.Println(err)
return "", err
}
return videoInfo.Streams[0].DisplayAspectRatio, nil
}
func main() {
godotenv.Load(".env")