3d0c / gmf

Go Media Framework
MIT License
885 stars 170 forks source link

Multi-threaded decoding #125

Open SpaceInvader61 opened 4 years ago

SpaceInvader61 commented 4 years ago

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 commented 4 years ago

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

SpaceInvader61 commented 4 years ago

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 commented 4 years ago

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

SpaceInvader61 commented 4 years ago

@3d0c Thank you!

3d0c commented 4 years ago

@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 commented 4 years ago

@3d0c

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

3d0c commented 4 years ago

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:

@3d0c

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.

SpaceInvader61 commented 4 years ago

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 commented 4 years ago

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

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 commented 4 years ago

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

3d0c commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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.