Streampunk / beamcoder

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

Beamcoder and nvidia hwaccel, h264_cuvid & h264_nvenc #42

Closed jpietek closed 4 years ago

jpietek commented 4 years ago

Is there any way to achieve gpu accelerated (de/en)coding with beamcoder, similar to: ffmpeg -c:v h264_cuvid -i x.ts -c:v h264_nvenc y.ts

I've compiled the ffmpeg according to Nvidia's instructions and did npm install with a proper ffmpeg compilaton.

beamcoder.decoders() & encoders() lists appropriate codecs, but the performance of the whole flow is around 4 times slower then expected (aws g4 instance). The GPU utilization is around few percent, instead of ~45% with ffmpeg.

Seems like BC is copying the frames back and forth from gpu to ram and to gpu again, which is a huge bottleneck?

thanks in advance for any hints!

jpietek commented 4 years ago

OK, most of the problems were due to multiple decoder (re)initialization + encoder flushing. Reencoding in a single dec/enc instance makes BC peformance comparable to ffmpeg, but still about 1/3 slower. FFmpeg utilizes about ~45% GPU, BC ~36%.