
вот мой код
StreamCodec.h
Код: Выделить всё
class StreamCodec : public QObject
{
Q_OBJECT
public:
StreamCodec(int height, int width, int fps);
public slots:
void encodeFrame(std::shared_ptr pData);
void run();
signals:
void encodeFinish(AVPacket* packet);
private:
void initializeSWS();
void initializeCodec();
AVPacket* allocatepacket(AVFrame* frame);
AVFrame* allocateFrame(std::shared_ptr pData);
AVFrame* formatFrame(AVFrame* frame);
const AVCodec* codec;
AVCodecContext* context;
SwsContext *swsContext;
int bytesPerPixel;
int width;
int height;
int fps;
int pts = 0;
};
Код: Выделить всё
StreamCodec::StreamCodec(int height, int width, int fps)
{
this->height = height;
this->width = width;
this->fps = fps;
}
void StreamCodec::initializeCodec()
{
codec = avcodec_find_encoder(AV_CODEC_ID_H264);
if (!codec) {
qDebug() width = width;
context->time_base.num = 1;
context->time_base.den = fps;
context->framerate.num = fps;
context->framerate.den = 1;
context->pix_fmt = AV_PIX_FMT_YUV420P;
context->gop_size = 0;
av_opt_set(context->priv_data, "preset", "ultrafast", 0);
av_opt_set(context->priv_data, "crf", "35", 0);
av_opt_set(context->priv_data, "tune", "zerolatency", 0);
auto desc = av_pix_fmt_desc_get(AV_PIX_FMT_BGRA);
if (!desc){
qDebug()
Подробнее здесь: [url]https://stackoverflow.com/questions/78661905/avpacket-data-is-empty-0-0-but-has-size[/url]