First frame of video

I am building a one page app with Go lang on the backend (and obviously javascript on the frontend). I would like to find a way to get the first frame of a video using Go lang.

First, I upload the .mp4 video file to the server. It is saved on the server.

Is there a way to get the first frame of this video using Go lang? This should be possible with Javascript on the interface, but I don’t feel that this is the right way to solve this problem.

I have no idea how to implement it with Go lang, and I have not found useful librarians, even built-in functions, that could help me solve this problem.

Each advice or any recommendations will be greatly expanded.

+4
source share
1 answer

As suggested in the comments, using ffmpeg would be the easiest approach. Below is an example from this answer :

package main

import (
    "bytes"
    "fmt"
    "os/exec"
)
func main() {
    filename := "test.mp4"
    width := 640
    height := 360
    cmd := exec.Command("ffmpeg", "-i", filename, "-vframes", "1", "-s", fmt.Sprintf("%dx%d", width, height), "-f", "singlejpeg", "-")
    var buffer bytes.Buffer
    cmd.Stdout = &buffer
    if cmd.Run() != nil {
        panic("could not generate frame")
    }
    // Do something with buffer, which contains a JPEG image
}
+4
source

Source: https://habr.com/ru/post/1628849/


All Articles