2017-10-09 22:11:01 +08:00
|
|
|
|
/*
|
2023-12-09 16:23:51 +08:00
|
|
|
|
* Copyright (c) 2016-present The ZLMediaKit project authors. All Rights Reserved.
|
2017-09-27 16:20:30 +08:00
|
|
|
|
*
|
2023-12-09 16:23:51 +08:00
|
|
|
|
* This file is part of ZLMediaKit(https://github.com/ZLMediaKit/ZLMediaKit).
|
2017-09-27 16:20:30 +08:00
|
|
|
|
*
|
2023-12-09 16:23:51 +08:00
|
|
|
|
* Use of this source code is governed by MIT-like license that can be found in the
|
2020-04-04 20:30:09 +08:00
|
|
|
|
* LICENSE file in the root of the source tree. All contributing project authors
|
|
|
|
|
|
* may be found in the AUTHORS file in the root of the source tree.
|
2017-04-01 16:35:56 +08:00
|
|
|
|
*/
|
|
|
|
|
|
#ifndef CODEC_H264ENCODER_H_
|
|
|
|
|
|
#define CODEC_H264ENCODER_H_
|
2017-04-25 11:35:41 +08:00
|
|
|
|
|
2017-04-01 16:35:56 +08:00
|
|
|
|
#include <cstdint>
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
|
extern "C" {
|
|
|
|
|
|
#endif //__cplusplus
|
|
|
|
|
|
#include <x264.h>
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
|
}
|
|
|
|
|
|
#endif //__cplusplus
|
|
|
|
|
|
|
2018-10-24 17:17:55 +08:00
|
|
|
|
namespace mediakit {
|
2017-04-01 16:35:56 +08:00
|
|
|
|
|
|
|
|
|
|
class H264Encoder {
|
|
|
|
|
|
public:
|
2020-03-20 11:51:24 +08:00
|
|
|
|
typedef struct {
|
|
|
|
|
|
int iType;
|
|
|
|
|
|
int iLength;
|
|
|
|
|
|
uint8_t *pucData;
|
2024-06-02 13:34:51 +08:00
|
|
|
|
|
|
|
|
|
|
int64_t dts;
|
|
|
|
|
|
int64_t pts;
|
2020-03-20 11:51:24 +08:00
|
|
|
|
} H264Frame;
|
2017-04-01 16:35:56 +08:00
|
|
|
|
|
2022-05-25 15:11:26 +08:00
|
|
|
|
H264Encoder();
|
|
|
|
|
|
~H264Encoder();
|
|
|
|
|
|
|
|
|
|
|
|
bool init(int iWidth, int iHeight, int iFps, int iBitRate);
|
|
|
|
|
|
int inputData(char *yuv[3], int linesize[3], int64_t cts, H264Frame **out_frame);
|
|
|
|
|
|
|
2017-04-01 16:35:56 +08:00
|
|
|
|
private:
|
2022-05-25 15:11:26 +08:00
|
|
|
|
x264_t *_pX264Handle = nullptr;
|
|
|
|
|
|
x264_picture_t *_pPicIn = nullptr;
|
|
|
|
|
|
x264_picture_t *_pPicOut = nullptr;
|
2020-03-20 11:51:24 +08:00
|
|
|
|
H264Frame _aFrames[10];
|
2017-04-01 16:35:56 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
2018-10-24 17:17:55 +08:00
|
|
|
|
} /* namespace mediakit */
|
2017-04-01 16:35:56 +08:00
|
|
|
|
|
|
|
|
|
|
#endif /* CODEC_H264ENCODER_H_ */
|