39 lines
873 B
C
39 lines
873 B
C
|
|
#pragma once
|
||
|
|
|
||
|
|
#include <d3d11.h>
|
||
|
|
#include <wrl/client.h>
|
||
|
|
#include <vector>
|
||
|
|
#include <cstdint>
|
||
|
|
|
||
|
|
extern "C" {
|
||
|
|
#include <libavcodec/avcodec.h>
|
||
|
|
#include <libavutil/imgutils.h>
|
||
|
|
#include <libavutil/opt.h>
|
||
|
|
#include <libswscale/swscale.h>
|
||
|
|
}
|
||
|
|
|
||
|
|
using Microsoft::WRL::ComPtr;
|
||
|
|
|
||
|
|
class VideoEncoder {
|
||
|
|
public:
|
||
|
|
VideoEncoder();
|
||
|
|
~VideoEncoder();
|
||
|
|
|
||
|
|
bool Initialize(ID3D11Device* device, int width, int height, int fps, int bitrate);
|
||
|
|
bool EncodeFrame(ID3D11Texture2D* texture, std::vector<uint8_t>& outputData, bool& isKeyFrame);
|
||
|
|
|
||
|
|
private:
|
||
|
|
ID3D11Device* device_ = nullptr;
|
||
|
|
ID3D11DeviceContext* context_ = nullptr;
|
||
|
|
ComPtr<ID3D11Texture2D> stagingTexture_;
|
||
|
|
|
||
|
|
AVCodecContext* codecContext_ = nullptr;
|
||
|
|
AVFrame* frame_ = nullptr;
|
||
|
|
AVPacket* packet_ = nullptr;
|
||
|
|
SwsContext* swsContext_ = nullptr;
|
||
|
|
|
||
|
|
int width_ = 0;
|
||
|
|
int height_ = 0;
|
||
|
|
int pts_ = 0;
|
||
|
|
};
|