How can I get one image file from video by per seconds?
hanluner opened this issue · 5 comments
hi,
May I ask a question, How can I get image file from video by per seconds? Is there have any example code? Thank u very much. My English is very poor.
Hi, @hanluner
To get a current intput stream duration in seconds (to get a current second) you can use (*Packet).Time()
method, e.g.:
currSec = pkt.Time(ist.TimeBase())
read this code snippet whithin the video-to-goImage.go
example context.
So, you've got a packet — you can count a current duration in seconds, then just skip extra packets you don't need to decode and dump.
But, remember that not always packet == frame
, so if you need better precision, you can decode a packet, count a frames and skip/get them according TimeBase
.
Hi, @3d0c
I'm still confused of several details related to packet.
What is the time unit of each packet? I.e. We transfer the video stream into packets by the unit of second or micro-second?
It returns seconds, calculated according timebase and current packet pts
.
func (p *Packet) Time(timebase AVRational) int {
return int(float64(timebase.AVR().Num) / float64(timebase.AVR().Den) * float64(p.Pts()))
}