Home > Enterprise >  FFmpeg I-P frame command in golang
FFmpeg I-P frame command in golang

Time:04-12

I have been using the command below to get a specific frame from the video and get it into a buffer.

func ReadFrameAsJpeg(inFileName string, frameNum int) []byte {
    // Returns specified frame as []byte
    buf := bytes.NewBuffer(nil)
    err := ffmpeg.Input(inFileName).
        Filter("select", ffmpeg.Args{fmt.Sprintf("gte(n,%d)", frameNum)}).
        Output("pipe:", ffmpeg.KwArgs{"vframes": 1, "format": "image2", "vcodec": "mjpeg"}).
        WithOutput(buf, os.Stdout).Run()
    if err != nil {
        fmt.Println(err)
        panic(err)
    }

While getting a specific frame according to a FrameNum, I want to also check which type of frame it is. Like using "pict_type" to get that information. I tried using a filter to get the frame type below, but it showed "error parsing the argument". It should give the output with the "pict_type = P" or "pict_type = I"

Filter("select", ffmpeg.Args{fmt.Sprintf("eq(n,%d),showinfo", frameNum)}).

I am trying to implement the following command

$ ffmpeg -hide_banner -i INPUT.mp4 -filter:v "select=eq('n,3344'),showinfo" -frames:v 1 -map 0:v:0 -f null -

CodePudding user response:

You are specifying showinfo as a part of select filter options, instead of defining 2 different filters. Assuming that you are using this library, you need to do something like this:

ffmpeg.Input(inFileName)
  .Filter("select", ffmpeg.Args{fmt.Sprintf("eq(n,%d)", frameNum)})
  .Filter("showinfo")
  .Output(...)...

I'm not familiar with go language so there maybe a syntax issue that you may need to sort out.

Edit: Yes it is right it should be a different filter. For golang it works using,

Filter("select", ffmpeg.Args{fmt.Sprintf("gte(n,%d)", frameNum)}).
Filter("showinfo", ffmpeg.Args{"TRUE"})
  • Related