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

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

FFmpeg I-P frame command in golang

问题

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

func ReadFrameAsJpeg(inFileName string, frameNum int) []byte {
	// 返回指定帧的 []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)
	}
}

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

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

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

$ 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.

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 -

答案1

得分: 1

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

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

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

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

Filter("select", ffmpeg.Args{fmt.Sprintf("gte(n,%d)", frameNum)}).
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:

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"})

</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:

确定