Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I get one image file from video by per seconds? #118

Open
hanluner opened this issue Sep 1, 2019 · 5 comments
Open

How can I get one image file from video by per seconds? #118

hanluner opened this issue Sep 1, 2019 · 5 comments

Comments

@hanluner
Copy link

hanluner commented Sep 1, 2019

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.

@hanluner hanluner changed the title How can I get image file from video by per seconds? How can I get one image file from video by per seconds? Sep 1, 2019
@hanluner
Copy link
Author

hanluner commented Sep 1, 2019

@3d0c Can you help me?

@3d0c
Copy link
Owner

3d0c commented Sep 1, 2019

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.

@hanluner
Copy link
Author

hanluner commented Sep 2, 2019

@3d0c Thanks, I'll try.

@hanluner
Copy link
Author

hanluner commented Sep 3, 2019

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?

@3d0c
Copy link
Owner

3d0c commented Sep 3, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants