Multi-threaded decoding
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?
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
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?
@SpaceInvader61 Yes, you're right — i can reproduce this problem. Will check it out. Thanks.
@3d0c Thank you!
@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)
@3d0c
I tried to do what you suggested in the video-to-goImage example, but it is still only using one thread
Hm, that is strange. I checked it out and everything worked. I recheck it later.
-------- Original Message -------- On Apr 3, 2020, 18:46, Space Invader wrote:
I tried to do what you suggested in the video-to-goImage example, but it is still only using one thread
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.
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!
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
You mean 57-66 in stream.go , right?
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.
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
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.