在golang中使用FFmpeg的I-P帧命令。

huangapple go评论112阅读模式
英文:

FFmpeg I-P frame command in golang

问题

我一直在使用下面的命令从视频中获取特定帧并将其放入缓冲区中。

  1. func ReadFrameAsJpeg(inFileName string, frameNum int) []byte {
  2. // 返回指定帧的 []byte
  3. buf := bytes.NewBuffer(nil)
  4. err := ffmpeg.Input(inFileName).
  5. Filter("select", ffmpeg.Args{fmt.Sprintf("gte(n,%d)", frameNum)}).
  6. Output("pipe:", ffmpeg.KwArgs{"vframes": 1, "format": "image2", "vcodec": "mjpeg"}).
  7. WithOutput(buf, os.Stdout).Run()
  8. if err != nil {
  9. fmt.Println(err)
  10. panic(err)
  11. }
  12. }

在根据帧编号获取特定帧时,我还想检查它是哪种类型的帧。比如使用 "pict_type" 来获取该信息。我尝试使用下面的过滤器来获取帧类型,但是显示出了 "error parsing the argument"。它应该输出 "pict_type = P" 或者 "pict_type = I"。

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

我正在尝试实现以下命令:

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

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

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

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"

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

I am trying to implement the following command

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

答案1

得分: 1

你正在将showinfo作为select过滤器选项的一部分进行指定,而不是定义两个不同的过滤器。假设你正在使用这个库,你需要像这样操作:

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

我对Go语言不太熟悉,所以可能会有语法问题需要解决。

编辑:
是的,你是对的,应该使用不同的过滤器。
对于Go语言,可以这样使用:

  1. Filter("select", ffmpeg.Args{fmt.Sprintf("gte(n,%d)", frameNum)}).
  2. Filter("showinfo", ffmpeg.Args{"TRUE"})
英文:

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:

  1. ffmpeg.Input(inFileName)
  2. .Filter("select", ffmpeg.Args{fmt.Sprintf("eq(n,%d)", frameNum)})
  3. .Filter("showinfo")
  4. .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,

  1. Filter("select", ffmpeg.Args{fmt.Sprintf("gte(n,%d)", frameNum)}).
  2. Filter("showinfo", ffmpeg.Args{"TRUE"})
  3. </details>

huangapple
  • 本文由 发表于 2022年4月11日 05:17:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/71820648.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定