Video Encoders translate from streams of raw video images to compressed bitstreams. In video streaming applications, video encoders are usually found on the sending side of a stream. They receive input from video sources such as video capture devices or frame compositors, and the output is sent across the network to the receiving end. There are many different video codecs, and possibly many implementations of each. However, different implementations tend to have a similar API so it is possible generalize them. This generalization makes it easier to develop software that uses video encoders, and makes advanced features such as hardware video encoding more easily accessible.
The API for a typical video encoder would include a method to allocate the encoder’s memory resources (create()), and a method to configure the encoder (configure()). Typical configuration parameters are the target bit-rate, NAL sizes and the bit-stream format. After this, raw video frames can be passed to the encoder, usually one at a time (encode()). The encode method will process the given video frame and generate bit-stream data for it. This method may take a long time to run, so a-synchronous function calls or multi-threading may be needed. For real-time video streaming, it can be useful to have a method that generates an I-Frame on demand (request_iframe()). When the encoder is no longer needed, such as when the media session ends, there should be a function to free any resources the encoder has allocated (destroy()).