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

Multi-threaded decoding #125

Open
SpaceInvader61 opened this issue Apr 3, 2020 · 13 comments
Open

Multi-threaded decoding #125

SpaceInvader61 opened this issue Apr 3, 2020 · 13 comments

Comments

@SpaceInvader61
Copy link

SpaceInvader61 commented Apr 3, 2020

Hi!
Is it possible to do a multi-threaded decoding?
I see you had a commit related to that ~10 month ago, does it mean it is not implemented yet?
It yes, are there plans to implement this feature?

@3d0c
Copy link
Owner

3d0c commented Apr 3, 2020

Hi, @SpaceInvader61
As far as i understand - there are two options:

  • you can set threads count for codec context by SetThreadCount - it affects libav codec directly
  • or if you need to proceed multiple files at once - use go routines - there is an examlpes

@SpaceInvader61
Copy link
Author

Hi, @3d0c !

Thank you for the fast response
Yeah, basically, what I'm trying to do is the first option

For simplicity, I tried to use your examples of video-to-goImage(I removed the save image part) and added SetThreadCount to all possible places there
But it is still using only one core, while when I run "ffmpeg -i data/video.mp4 -f null -" it is using all cores

So, what am I missing?

@3d0c
Copy link
Owner

3d0c commented Apr 3, 2020

@SpaceInvader61
Yes, you're right — i can reproduce this problem. Will check it out.
Thanks.

@SpaceInvader61
Copy link
Author

@3d0c Thank you!

@3d0c
Copy link
Owner

3d0c commented Apr 3, 2020

@SpaceInvader61

Well, you can try to define count of thread vi Options
After codec has been opened, initialize codec context like with options:

    codec, err := gmf.FindEncoder(extention)
    if err != nil {
        log.Fatalf("%s\n", err)
    }

    options := []*gmf.Option{
        {"threads", 8},
    }
    cc := gmf.NewCodecCtx(codec, options)

@SpaceInvader61
Copy link
Author

@3d0c

I tried to do what you suggested in the video-to-goImage example, but it is still only using one thread

@3d0c
Copy link
Owner

3d0c commented Apr 3, 2020 via email

@SpaceInvader61
Copy link
Author

Oh, actually, I got confused with a different context in the example
After I added the options directly to stream.go creation of NewCodecCtx - it worked!

So, probably I just didn't get it right - where is the place I should pass this option? Because it seems like I need to pass it to the inner videoStream Codec?

Thank you!

@3d0c
Copy link
Owner

3d0c commented Apr 3, 2020

Ok. you've got 4 (a least) contexts:

  • input codec
  • input codecContext - here is where you can apply options
  • output codec
  • output codecContext

I've provided a complete snippet, which you can just replace lines 57-66 and it should work.
Anyway - just check what methods can receive options optionally - and you can pass it

@SpaceInvader61
Copy link
Author

You mean 57-66 in stream.go , right?

@3d0c
Copy link
Owner

3d0c commented Apr 3, 2020

Oops, sorry, looks like i've got another codebase
I meant this one https://github.com/3d0c/gmf/blob/master/examples/video-to-image.go#L57-L62
let codec init as is, just add options into NewCodecCtx(codec, opotions)
that's it.

@SpaceInvader61
Copy link
Author

Yeah, that's what I mean - this one is used for Encoding, isn't it?

And to do the same for Decoding I'll have to change the context inside the "ist" object
https://github.com/3d0c/gmf/blob/master/examples/video-to-image.go#L124

@3d0c
Copy link
Owner

3d0c commented Apr 3, 2020

Actually, no. You did (libav did) multy-hreadnig for decoding, not for encoding (you can see it by debugging ffmpeg) - it doesn't. So, setup threads for decoding and forget about encoding.
P.S. I could be wrong about all that things - but this is what i figured out while i debugging ffmpeg.

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