Streampunk / beamcoder

Node.js native bindings to FFmpeg.
GNU General Public License v3.0
397 stars 76 forks source link

pass hw_frames_ctx from frame to encoder #52

Closed jpietek closed 3 years ago

jpietek commented 3 years ago
  1. The idea behind this change is to allow encoder to use hardware accelerated frames. For ex. a frame can be hwuploaded to cuda and filtered with a scale_npp filter. If the hw_frames context is not passed to the encoder, it currently fails in such scenario.

  2. The avdevices are currently not initialized on beamcoder init. That's why it's impossible to use a v4l2 device as a demuxer input:

    let dm = await beamcoder.demuxer({ url: '/dev/video10', iformat: "video4linux2",

This will fail with "invalid input" error. Registering the avdevices on init fixes this issue.

scriptorian commented 3 years ago

Hi Jan, thanks for the pull request. I have just pushed some changes with a slightly different approach that should allow you to have the encoder use hw frames but in this version you will need to copy the hw_frames_ctx from frame to encoder in your JS code before the first frame is encoded. I hope this meets your needs.

scriptorian commented 3 years ago

Hi @jpietek , did my changes support what you needed? Can we close the pull request? Thanks.

jpietek commented 3 years ago

Yup, having those hw_contexts mapped to nodejs will do the trick. BTW do you have some plans to support -hwaccel flags via beamcoder and filters like cuda_overlay?

scriptorian commented 3 years ago

Great, I'll go ahead and close the pull request. I'd like to add more hw support when time allows - but I'm not sure when that will be!