问题
Media Foundation h264 encoder poor performance
I'm writing an application which records PC's screen in realtime and encodes it with Media Foundation h264 codec. Encoding consumes a lot of CPU resources. And after I stop recording video (or pause it by simply stopping feeding an encoder with video and audio frames), CPU load stays very high for a long period of time (5-10 seconds and more). During this time application waits until IMFSinkWriter::Finalize method completes.
My PC configuration:
- Intel i5-2410M 2.3 GHz with 4 cores
- 8 GB RAM
Codec configuration:
- 25 fps
- 1364 x 768 resolution
- baseline profile
- 1.2 MBit bitrate
Is this a limitation of MF h264 codec performance or is it due to bugs/misconfiguration in my code?
回答1:
It is expected behavior for the pipeline having a long internal queue to keep encoding video until the queue is empty. Since - as it seems - software encoder is being used and it's pretty slow, your screen capture source generates enough data to fill the queues so tight that it takes additional seconds to sort that out.
Your solution would be to either control/reduce data rate, or use faster, esp. hardware-assisted, encoder. Media Foundation could however take advantage of hardware encoders automatically so I suppose it's not the option for you. You can check availability of hardware encoders using MediaFoundationVideoEncoderTransforms tool.
来源:https://stackoverflow.com/questions/39611512/media-foundation-h264-encoder-poor-performance