英文:
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>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论