![]() |
ImFusion SDK 4.3
|
Public Types | |
| enum class | Codec { HEVC_NVENC = 0 , HEVC_QSV , H264_NVENC , H264_QSV , AV1_NVENC , AV1_AOM , MPEG4 } |
| List of algorithms used for video compression (Codec), IMPORTANT: the availability of these is dependent on the ffmpeg build unfortunately, unlike decoding, encoding using the generic CPU based codec for HEVC (and H264) cannot be added here due to licensing problems we should investigate hevc_v4l2m2m and libkvazaar for CPU based Encoder. More... | |
| enum class | Preset { LowLatency = 0 , Balanced = 1 , HighQuality = 2 } |
| using | FrameCallback = std::function<void(std::unique_ptr<ByteBuffer>, bool)> |
Public Member Functions | |
| VideoEncoder (FrameCallback frameCallback) | |
| Constructs the class with the given frame callback The frame callback is executed whenever a passed frame has been encoded by the background thread The callback is executed from the background thread, so proper synchronization must be ensured by the caller The parameters of the callback are a ByteBuffer containing the image data, and other used metadata. | |
| bool | start (Codec encoderId, int fps, Preset preset=Preset::LowLatency) |
| Starts the encoding thread with the given encoder parameters 'fps' is the expected frame rate of the video stream. | |
| bool | stop () |
| Stops the encoder thread, if running. | |
| void | restartEncoder () |
| Re-initializes the encoder state This can be used to reset the video stream, such that a client starting halfway through the stream can still decode it. | |
| void | feedFrame (std::unique_ptr< ImFusion::MemImage > image) |
| Pass a new image to the encoder thread, to be encoded into the video stream. | |
| bool | lastImageProcessed () const |
| return true if the algorithm had enough time to encode the previously stored image before the new one arrived | |
Static Public Member Functions | |
| static std::vector< Codec > | availableCodecs () |
| Returns the available encoder provided by the ffmpeg library IMPORTANT: Not all codecs returned by this function are guaranteed work. | |
| static std::string | codecName (Codec codec) |
|
strong |
List of algorithms used for video compression (Codec), IMPORTANT: the availability of these is dependent on the ffmpeg build unfortunately, unlike decoding, encoding using the generic CPU based codec for HEVC (and H264) cannot be added here due to licensing problems we should investigate hevc_v4l2m2m and libkvazaar for CPU based Encoder.
| VideoEncoder | ( | FrameCallback | frameCallback | ) |
Constructs the class with the given frame callback The frame callback is executed whenever a passed frame has been encoded by the background thread The callback is executed from the background thread, so proper synchronization must be ensured by the caller The parameters of the callback are a ByteBuffer containing the image data, and other used metadata.
Decoding applications typically expect to receive the first frame first, as it contains some information relevant to decoding.
| bool start | ( | Codec | encoderId, |
| int | fps, | ||
| Preset | preset = Preset::LowLatency ) |
Starts the encoding thread with the given encoder parameters 'fps' is the expected frame rate of the video stream.
This is only used for encoding in the metadata of the output video
| bool stop | ( | ) |
Stops the encoder thread, if running.
Blocks until the thread is joined.
| void feedFrame | ( | std::unique_ptr< ImFusion::MemImage > | image | ) |
Pass a new image to the encoder thread, to be encoded into the video stream.
The function returns immediately, and the FrameCallback (passed in the constructor) will be called at a later point in time with the encoded data. Note that if a frame had not yet been processed by the background thread (either because they're supplied too fast or because the encoding is too slow), unhandled frames will be replaced by the new one
|
static |
Returns the available encoder provided by the ffmpeg library IMPORTANT: Not all codecs returned by this function are guaranteed work.
For example, 'H264_NVENC' will only work if the GPU on the device supports it.