Encoder functions. More...
#include <shcodecs/shcodecs_common.h>
#include <shcodecs/encode_general.h>
#include <shcodecs/encode_properties.h>
#include <shcodecs/encode_h264.h>
#include <shcodecs/encode_mpeg4.h>
Go to the source code of this file.
Typedefs | |
typedef struct SHCodecs_Encoder | SHCodecs_Encoder |
typedef int(* | SHCodecs_Encoder_Input )(SHCodecs_Encoder *encoder, void *user_data) |
Signature of a callback for libshcodecs to call when it requires YUV 4:2:0 data. | |
typedef int(* | SHCodecs_Encoder_Input_Release )(SHCodecs_Encoder *encoder, unsigned char *y_input, unsigned char *c_input, void *user_data) |
Signature of a callback for libshcodecs to call when it no longer requires access to a previously input YUV buffer. | |
typedef int(* | SHCodecs_Encoder_Output )(SHCodecs_Encoder *encoder, unsigned char *data, int length, void *user_data) |
Signature of a callback for libshcodecs to call when it has encoded data. | |
Functions | |
SHCodecs_Encoder * | shcodecs_encoder_init (int width, int height, SHCodecs_Format format) |
Initialize the VPU4 for encoding a given video format. | |
void | shcodecs_encoder_close (SHCodecs_Encoder *encoder) |
Deallocate resources used to initialize the VPU4 for encoding, and reset it for future use. | |
int | shcodecs_encoder_set_output_callback (SHCodecs_Encoder *encoder, SHCodecs_Encoder_Output output_cb, void *user_data) |
Set the callback for libshcodecs to call when encoded data is available. | |
int | shcodecs_encoder_set_input_callback (SHCodecs_Encoder *encoder, SHCodecs_Encoder_Input input_cb, void *user_data) |
Set the callback for libshcodecs to call when raw YUV data is required. | |
int | shcodecs_encoder_set_input_release_callback (SHCodecs_Encoder *encoder, SHCodecs_Encoder_Input_Release release_cb, void *user_data) |
Set the callback for libshcodecs to call when it no longer requires access to a previously input YUV buffer. | |
void * | shcodecs_encoder_get_input_user_data (SHCodecs_Encoder *encoder) |
int | shcodecs_encoder_input_provide (SHCodecs_Encoder *encoder, void *y_input, void *c_input) |
Provide input data to the encoder. | |
int | shcodecs_encoder_run (SHCodecs_Encoder *encoder) |
Run the encoder. | |
int | shcodecs_encoder_encode_1frame (SHCodecs_Encoder *encoder, void *y_input, void *c_input, void *user_data) |
Encode one frame. | |
int | shcodecs_encoder_finish (SHCodecs_Encoder *encoder) |
Finish encoding. | |
int | shcodecs_encoder_get_width (SHCodecs_Encoder *encoder) |
Get the width in pixels of the encoded image. | |
int | shcodecs_encoder_get_height (SHCodecs_Encoder *encoder) |
Get the height in pixels of the encoded image. | |
int | shcodecs_encoder_get_frame_num_delta (SHCodecs_Encoder *encoder) |
Get the number of input frames elapsed since the last output callback. | |
int | shcodecs_encoder_get_min_input_frames (SHCodecs_Encoder *encoder) |
Get the minimum number of input frames required. |
Encoder functions.
typedef int(* SHCodecs_Encoder_Input)(SHCodecs_Encoder *encoder, void *user_data) |
Signature of a callback for libshcodecs to call when it requires YUV 4:2:0 data.
To pause encoding, return 1 from this callback.
encoder | The SHCodecs_Encoder* handle | |
user_data | Arbitrary data supplied by user |
0 | Continue encoding | |
1 | Pause encoding, return from shcodecs_encode() |
typedef int(* SHCodecs_Encoder_Input_Release)(SHCodecs_Encoder *encoder, unsigned char *y_input, unsigned char *c_input, void *user_data) |
Signature of a callback for libshcodecs to call when it no longer requires access to a previously input YUV buffer.
To pause encoding, return 1 from this callback.
encoder | The SHCodecs_Encoder* handle | |
user_data | Arbitrary data supplied by user |
0 | Continue encoding | |
1 | Pause encoding, return from shcodecs_encode() |
typedef int(* SHCodecs_Encoder_Output)(SHCodecs_Encoder *encoder, unsigned char *data, int length, void *user_data) |
Signature of a callback for libshcodecs to call when it has encoded data.
To pause encoding, return 1 from this callback.
encoder | The SHCodecs_Encoder* handle | |
data | The encoded data | |
length | Length of encoded data in bytes | |
user_data | Arbitrary data supplied by user |
0 | Continue encoding | |
1 | Pause encoding, return from shcodecs_encode() |
void shcodecs_encoder_close | ( | SHCodecs_Encoder * | encoder | ) |
Deallocate resources used to initialize the VPU4 for encoding, and reset it for future use.
encoder | The SHCodecs_Encoder* handle |
int shcodecs_encoder_encode_1frame | ( | SHCodecs_Encoder * | encoder, | |
void * | y_input, | |||
void * | c_input, | |||
void * | user_data | |||
) |
Encode one frame.
The encoder will then perform 1 or more callbacks to output encoded data. It also makes callbacks to release the input frames once they can be used for new data. If you use this function, you cannot use shcodecs_encoder_run
encoder | The SHCodecs_Encoder* handle | |
y_input | Pointer to the Y plane of input data | |
c_input | Pointer to the CbCr plane of input data | |
user_data | User data that is available during the input release callback |
0 | Success |
int shcodecs_encoder_finish | ( | SHCodecs_Encoder * | encoder | ) |
Finish encoding.
encoder | The SHCodecs_Encoder* handle |
0 | Success |
int shcodecs_encoder_get_frame_num_delta | ( | SHCodecs_Encoder * | encoder | ) |
Get the number of input frames elapsed since the last output callback.
This is typically called by the client in the encoder output callback.
encoder | The SHCodecs_Encoder* handle |
-1 | encoder invalid |
int shcodecs_encoder_get_height | ( | SHCodecs_Encoder * | encoder | ) |
Get the height in pixels of the encoded image.
encoder | The SHCodecs_Encoder* handle |
-1 | encoder invalid |
int shcodecs_encoder_get_min_input_frames | ( | SHCodecs_Encoder * | encoder | ) |
Get the minimum number of input frames required.
Since the encoder may encoder frames out of order due to BVOPs, it may not release an input buffer immediately. Therefore, you may need to use several input frames.
encoder | The SHCodecs_Encoder* handle |
The | minimum number of input frames required | |
-1 | encoder invalid |
int shcodecs_encoder_get_width | ( | SHCodecs_Encoder * | encoder | ) |
Get the width in pixels of the encoded image.
encoder | The SHCodecs_Encoder* handle |
-1 | encoder invalid |
SHCodecs_Encoder* shcodecs_encoder_init | ( | int | width, | |
int | height, | |||
SHCodecs_Format | format | |||
) |
Initialize the VPU4 for encoding a given video format.
width | The video image width | |
height | The video image height | |
format | SHCodecs_Format_MPEG4 or SHCODECS_Format_H264 |
int shcodecs_encoder_input_provide | ( | SHCodecs_Encoder * | encoder, | |
void * | y_input, | |||
void * | c_input | |||
) |
Provide input data to the encoder.
This function MUST be called from within an SHCodecs_Encoder_Input callback, otherwise the encode hardware will not see any data. The byte sizes of these planes do not vary unless the image dimensions vary, and can be retrieved with shcodecs_encoder_get_y_bytes() and shcodecs_encoder_get_c_bytes().
encoder | The SHCodecs_Encoder* handle | |
y_input | Pointer to the Y plane of input data | |
c_input | Pointer to the CbCr plane of input data |
0 | Success |
int shcodecs_encoder_run | ( | SHCodecs_Encoder * | encoder | ) |
Run the encoder.
The encoder will then perform callbacks to get input frames (where the user specifies the next frame details) and then 1 or more callbacks to output encoded data. It also makes callbacks to release the input frames once they can be used for new data. If you use this function, you cannot use shcodecs_encoder_encode_1frame
encoder | The SHCodecs_Encoder* handle |
0 | Success |
int shcodecs_encoder_set_input_callback | ( | SHCodecs_Encoder * | encoder, | |
SHCodecs_Encoder_Input | input_cb, | |||
void * | user_data | |||
) |
Set the callback for libshcodecs to call when raw YUV data is required.
encoder | The SHCodecs_Encoder* handle | |
input_cb | The callback function | |
user_data | Additional data to pass to the callback function |
int shcodecs_encoder_set_input_release_callback | ( | SHCodecs_Encoder * | encoder, | |
SHCodecs_Encoder_Input_Release | release_cb, | |||
void * | user_data | |||
) |
Set the callback for libshcodecs to call when it no longer requires access to a previously input YUV buffer.
encoder | The SHCodecs_Encoder* handle | |
release_cb | The callback function | |
user_data | Additional data to pass to the callback function |
int shcodecs_encoder_set_output_callback | ( | SHCodecs_Encoder * | encoder, | |
SHCodecs_Encoder_Output | output_cb, | |||
void * | user_data | |||
) |
Set the callback for libshcodecs to call when encoded data is available.
encoder | The SHCodecs_Encoder* handle | |
output_cb | The callback function | |
user_data | Additional data to pass to the callback function |