QT下使用ffmpeg+SDL实现音视频播放器,支持录像截图功能,提供源码分享与下载

前言:

    SDL是音视频播放和渲染的一个开源库,主要利用它进行视频渲染和音频播放。
SDL库下载路径:https://github.com/libsdl-org/SDL/releases/tag/release-2.26.3,我使用的是2.26.3版本,大家可以自行选择该版本或其他版本的库。

在这里插入图片描述

一、SDL库介绍:

    SDL2.lib、SDL2main.lib和SDL2test.lib是SDL库的不同部分和功能。

    SDL2.lib:这是SDL库的主要部分,包含了所有常用的SDL功能和函数。它提供了与窗口、渲染、音频、事件处理等相关的功能。

    SDL2main.lib:这是用于Windows平台上的SDL2的可执行文件的入口点的库文件。它包含了与Windows系统相关的代码,用于初始化SDL2和设置应用程序的入口点。

    SDL2test.lib:这是SDL测试库,包含了一些用于测试和验证SDL功能的测试代码和工具。

    通常情况下,您只需要链接SDL2.lib和SDL2main.lib就可以使用SDL库的大部分功能。SDL2test.lib主要是用于SDL开发的测试和验证,一般情况下不需要链接到您的应用程序中。

    请注意,如果你在Qt项目中使用了Qt的消息循环(例如使用QApplication::exec()),则应该使用SDL2main.lib而不是SDL2.lib。这是因为SDL2main.lib包含了一个定义了WinMain函数的模块,可以与Qt的消息循环兼容。如果你不使用Qt的消息循环,可以使用SDL2.lib。

音频方面:
SDL提供两种使音频设备取得音频数据方法:
a. push,SDL以特定的频率调用回调函数,在回调函数中取得音频数据(本文采用);
b. pull,用户程序以特定的频率调用SDL_QueueAudio(),向音频设备提供数据。

二、SDL常用函数介绍:

2.1. SDL初始化,初始化音频和视频模块以及时间模块

if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER)) {
TestNotNull(NULL, SDL_GetError());
}

2.2. 创建一个显示窗口给SDL winid是qt窗口的id,这样SDL窗口就会嵌入到Qt窗口里面

window = SDL_CreateWindowFrom((void *)winId());

SDL_Window* SDL_CreateWindow(const char* A,int B,int C,int D,int E,Uint32 F)
函数说明:创建窗口,成功返回指向SDL_Window的指针,失败返回NULL

2.3.为指定窗口创建渲染器上下文

SDL_Renderer* SDL_CreateRenderer(SDL_Window* window, int index, Uint32 flags)

2.4.将制定区域(srcrect)的纹理数据,拷贝到渲染目标尺寸为(dstrect)的渲染器上下文(renderer)中,为下一步的渲染做准备

int SDL_RenderCopy(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Rect* srcrect, const SDL_Rect* dstrect)

参数的含义如下。
renderer:渲染目标。
texture:输入纹理。
srcrect:选择输入纹理的一块矩形区域作为输入。设置为NULL的时候整个纹理作为输入。
dstrect:选择渲染目标的一块矩形区域作为输出。设置为NULL的时候整个渲染目标作为输出。

2.5.将渲染器上下文中的数据,渲染到关联窗体上去

void SDL_RenderPresent(SDL_Renderer* renderer)

2.6.此函数可为渲染器上下文创建纹理

SDL_Texture* SDL_CreateTexture(SDL_Renderer* renderer,
Uint32 format,
int access,
int w,
int h)

2.7.使用新的像素数据更新给定的纹理矩形。也就是说,可以固定刷新纹理的某一分部区域

图像数据写入显存中
int SDL_UpdateTexture(SDL_Texture* texture,
const SDL_Rect* rect,
const void* pixels,
int pitch)

2.8.清理屏幕

int SDLCALL SDL_RenderClear(SDL_Renderer * renderer);

2.9.线程、锁、条件变量

SDL线程创建:SDL_CreateThread
SDL线程等待:SDL_WaitThead
SDL互斥锁:SDL_CreateMutex/SDL_DestroyMutex
SDL锁定互斥:SDL_LockMutex/SDL_UnlockMutex
SDL条件变量(信号量):SDL_CreateCond/SDL_DestoryCond
SDL条件变量(信号量)等待/通知:SDL_CondWait/SDL_CondSingal

10.读取事件

SDL_PollEvent
从事件队列中,读取事件的常用函数
如果时间队列中有待处理事件,返回1;如果没有可处理事件,则返回0

11.发送事件

int SDL_PushEvent(SDL_Event * event);

12.等待事件

SDL_WaitEvent

13.音频相关

SDL_PauseAudio(0) //恢复音频播放
SDL_PauseAudio(1) //暂停音频播放
SDL_CloseAudio() //关闭音频

三、ffmpeg+SDL实现音视频播放器:

3.1 支持实时流、支持视频文件的音视频播放

在这里插入图片描述
在这里插入图片描述

3.2 支持录像、支持截图功能

录像:
在这里插入图片描述

截图:
在这里插入图片描述

3.3 核心代码

cvideoplayer.h

#ifndef CVIDEOPLAYER_H
#define CVIDEOPLAYER_H

#include <QObject>
#include <QWidget>

#include <QtWidgets>
#include <SDL.h>
#include "commondef.h"
#include <QQueue>
#include "mp4recorder.h"

#define MAX_AUDIO_OUT_SIZE 8*1152

typedef struct audio_data
{
    char data[MAX_AUDIO_OUT_SIZE];
    int size;
}audio_data_t;


class cVideoPlayer : public QWidget
{
    Q_OBJECT
public:
    cVideoPlayer(QWidget *parent = nullptr, int nWidth = 704, int nHeight = 576);
    ~cVideoPlayer();

public:
    bool loadVideo(const QString &sUrl);
    void playVideo();
    void OpenAudio(bool bOpen);
    void Snapshot();
    void startRecord(bool bStart);

protected:
    void paintEvent(QPaintEvent *event) override;

public:
    QQueue<audio_data_t*> m_adq;

private:
    bool m_bRun = false;
    int m_nPlayWay = MEDIA_PLAY_STREAM;
    SDL_Window *m_pWindow = nullptr;
    SDL_Renderer *m_pRenderer = nullptr;
    SDL_Texture *m_pTexture = nullptr;
    AVFormatContext *m_pFormatCtx = nullptr;
    AVCodecContext* m_pVideoCodecCxt = nullptr;          //视频解码器上下文
    AVCodecContext* m_pAudioCodecCxt = nullptr;          //音频解码器上下文
    SwrContext *m_pAudioSwrContext = nullptr;            //音频重采样上下文
    AVFrame *m_pFrame = nullptr;
    AVFrame *m_pYuvFrame = nullptr;
    AVFrame *m_pPcmFrame = nullptr;
    struct SwsContext *m_pSwsCtx = nullptr;
    int m_nBufferSize = 0;
    uint8_t *m_pDstBuffer = nullptr;
    int m_nVideoIndex = -1;
    int m_nAudioIndex = -1;
    int64_t m_nStartTime;
    AVPacket m_packet;
    enum AVCodecID m_CodecId;
    enum AVCodecID m_AudioCodecId;
    int m_nSDLWidth;
    int m_nSDLHeight;

    //音频
    SDL_AudioSpec m_audioSpec;
    bool m_bSupportAudio = false;
    bool m_bPauseAudio = false;
    int m_nAudioSampleRate = 8000;                       //音频采样率
    int m_nAudioPlaySampleRate = 44100;                  //音频播放采样率
    int m_nAudioPlayChannelNum = 1;                      //音频播放通道数

    //mp4录像
    mp4Recorder m_mp4Recorder;
    bool m_bRecord = false;

    //截图
    bool m_bSnapshot = false;
    SDL_Surface *m_pSurface = nullptr;
};

#endif // CVIDEOPLAYER_H

cvideoplayer.cpp

#include "cvideoplayer.h"

QMutex g_lock;

// 音频处理回调函数。读队列获取音频包,解码,播放
void sdl_audio_callback(void *userdata, uint8_t *stream, int len)
{
    cVideoPlayer *pPlayer = (cVideoPlayer*)userdata;

    SDL_memset(stream, 0, len);

    if(pPlayer && pPlayer->m_adq.size() > 0)
    {
        QMutexLocker guard(&g_lock);
        audio_data_t* pAudioData = pPlayer->m_adq.dequeue();
        if(pAudioData->size == 0)
            return;

        len = (len>pAudioData->size?pAudioData->size:len);
        SDL_MixAudio(stream, (uint8_t *)pAudioData->data, len, SDL_MIX_MAXVOLUME);
        delete pAudioData;
    }
}

cVideoPlayer::cVideoPlayer(QWidget *parent, int nWidth, int nHeight) : QWidget(parent),
    m_nSDLWidth(nWidth), m_nSDLHeight(nHeight)
{
    this->resize(nWidth, nHeight);
}

cVideoPlayer::~cVideoPlayer()
{
    m_bRun = false;

    MY_DEBUG << "~cVideoPlayer 000";

    if(nullptr != m_pSurface)
    {
        SDL_FreeSurface(m_pSurface);
        m_pSurface = nullptr;
    }

    if(nullptr != m_pTexture)
    {
        SDL_DestroyTexture(m_pTexture);
        m_pTexture = nullptr;
    }

    MY_DEBUG << "~cVideoPlayer 111";

    if(nullptr != m_pRenderer)
    {
        SDL_DestroyRenderer(m_pRenderer);
        m_pRenderer = nullptr;
    }

    MY_DEBUG << "~cVideoPlayer 222";

    if(nullptr != m_pWindow)
    {
        SDL_DestroyWindow(m_pWindow);
        m_pWindow = nullptr;
    }

    MY_DEBUG << "~cVideoPlayer 333";

    SDL_CloseAudio();
    SDL_Quit();

    MY_DEBUG << "~cVideoPlayer 444";

    if(nullptr != m_pFrame)
    {
        av_frame_free(&m_pFrame);
        m_pFrame = nullptr;
    }

    if(nullptr != m_pYuvFrame)
    {
        av_frame_free(&m_pYuvFrame);
        m_pYuvFrame = nullptr;
    }

    MY_DEBUG << "~cVideoPlayer 555";

    if(nullptr != m_pVideoCodecCxt)
    {
        avcodec_close(m_pVideoCodecCxt);
        //m_pVideoCodecCxt = nullptr; //设置为nullptr会导致崩溃
    }

    MY_DEBUG << "~cVideoPlayer 666";

    if(m_pFormatCtx)
    {
        avformat_close_input(&m_pFormatCtx);
        avformat_free_context(m_pFormatCtx);
        m_pFormatCtx = nullptr;
    }

    MY_DEBUG << "~cVideoPlayer 777";

    if(nullptr != m_pSwsCtx)
    {
        sws_freeContext(m_pSwsCtx);
        m_pSwsCtx = nullptr;
    }

    MY_DEBUG << "~cVideoPlayer 888";

    if(nullptr != m_pDstBuffer)
    {
        av_free(m_pDstBuffer);
    }

    MY_DEBUG << "~cVideoPlayer end";
}

bool cVideoPlayer::loadVideo(const QString &sUrl)
{
    avformat_network_init();

    if(sUrl.contains("rtsp://") || sUrl.contains("http://")) //实时流
        m_nPlayWay = MEDIA_PLAY_STREAM;
    else
        m_nPlayWay = MEDIA_PLAY_FILE;

    m_pFormatCtx = avformat_alloc_context();
    if (avformat_open_input(&m_pFormatCtx, sUrl.toStdString().c_str(), nullptr, nullptr) != 0)
    {
        MY_DEBUG << "Failed to open video file";
        return false;
    }

    if (avformat_find_stream_info(m_pFormatCtx, nullptr) < 0)
    {
        MY_DEBUG << "Failed to find stream information";
        return false;
    }

    m_nVideoIndex = av_find_best_stream(m_pFormatCtx, AVMEDIA_TYPE_VIDEO, -1, -1, NULL, 0);
    m_nAudioIndex = av_find_best_stream(m_pFormatCtx, AVMEDIA_TYPE_AUDIO, -1, -1, NULL, 0);

    if (m_nVideoIndex == -1)
    {
        MY_DEBUG << "Failed to find video stream";
        return false;
    }

    //查找并打开视频解码器
    m_pVideoCodecCxt = avcodec_alloc_context3(nullptr);
    if (avcodec_parameters_to_context(m_pVideoCodecCxt, m_pFormatCtx->streams[m_nVideoIndex]->codecpar) != 0)
    {
        MY_DEBUG << "Failed to copy codec parameters to codec context";
        return false;
    }

    const AVCodec *codec = avcodec_find_decoder(m_pVideoCodecCxt->codec_id);
    if (codec == nullptr)
    {
        MY_DEBUG << "Failed to find video decoder";
        return false;
    }

    if (avcodec_open2(m_pVideoCodecCxt, codec, nullptr) < 0)
    {
        MY_DEBUG << "Failed to open video decoder";
        return false;
    }

    m_CodecId = codec->id;

    //查找并打开音频解码器
    if(m_nAudioIndex > 0)
    {
        //查找音频解码器
        const AVCodec *pAVCodec = avcodec_find_decoder(m_pFormatCtx->streams[m_nAudioIndex]->codecpar->codec_id);
        if(!pAVCodec)
        {
            MY_DEBUG << "audio decoder not found";
            return false;
        }

        m_AudioCodecId = pAVCodec->id;

        //音频解码器参数配置
        if (!m_pAudioCodecCxt)
            m_pAudioCodecCxt = avcodec_alloc_context3(nullptr);
        if(nullptr == m_pAudioCodecCxt)
        {
            MY_DEBUG << "avcodec_alloc_context3 error m_pAudioCodecCxt=nullptr";
            return false;
        }
        avcodec_parameters_to_context(m_pAudioCodecCxt, m_pFormatCtx->streams[m_nAudioIndex]->codecpar);

        //打开音频解码器
        int nRet = avcodec_open2(m_pAudioCodecCxt, pAVCodec, nullptr);
        if(nRet < 0)
        {
            avcodec_close(m_pAudioCodecCxt);
            MY_DEBUG << "avcodec_open2 error m_pAudioCodecCxt";
            return false;
        }

        //音频重采样初始化
        if (nullptr == m_pAudioSwrContext)
        {
            if(m_pAudioCodecCxt->channel_layout <= 0 || m_pAudioCodecCxt->channel_layout > 3)
                m_pAudioCodecCxt->channel_layout = 1;

            MY_DEBUG << "m_audioCodecContext->channel_layout:" << m_pAudioCodecCxt->channel_layout;
            MY_DEBUG << "m_audioCodecContext->channels:" << m_pAudioCodecCxt->channels;

            m_pAudioSwrContext = swr_alloc_set_opts(0,
                                                   m_pAudioCodecCxt->channel_layout,
                                                   AV_SAMPLE_FMT_S16,
                                                   m_pAudioCodecCxt->sample_rate,
                                                   av_get_default_channel_layout(m_pAudioCodecCxt->channels),
                                                   m_pAudioCodecCxt->sample_fmt,
                                                   m_pAudioCodecCxt->sample_rate,
                                                   0,
                                                   0);
            auto nRet = swr_init(m_pAudioSwrContext);
            if(nRet < 0)
            {
                MY_DEBUG << "swr_init error";
                return false;
            }
        }

        m_nAudioSampleRate = m_pAudioCodecCxt->sample_rate;
        m_audioSpec.freq = m_nAudioSampleRate;                  // 采样率
        m_audioSpec.format = AUDIO_S16SYS;                      // S表带符号,16是采样深度,SYS表采用系统字节序
        m_audioSpec.channels = m_pAudioCodecCxt->channels;      // 声道数
        m_audioSpec.silence = 0;                                // 静音值
        m_audioSpec.samples = m_pAudioCodecCxt->frame_size;     // SDL声音缓冲区尺寸,单位是单声道采样点尺寸x通道数
        m_audioSpec.callback = sdl_audio_callback;              // 回调函数,若为NULL,则应使用SDL_QueueAudio()机制
        m_audioSpec.userdata = this;                            // 提供给回调函数的参数

        //打开音频设备并创建音频处理线程
        if(SDL_OpenAudio(&m_audioSpec, NULL) < 0)
        {
            MY_DEBUG << "SDL_OpenAudio failed.";
            return false;
        }
        if(nullptr == m_pPcmFrame)
            m_pPcmFrame = av_frame_alloc();

        m_bSupportAudio = true;
    }

    av_dump_format(m_pFormatCtx, 0, NULL, 0);

    m_pFrame = av_frame_alloc();
    m_pSwsCtx = sws_getContext(m_pVideoCodecCxt->width, m_pVideoCodecCxt->height, m_pVideoCodecCxt->pix_fmt,
                            m_pVideoCodecCxt->width, m_pVideoCodecCxt->height, AV_PIX_FMT_YUV420P,
                            SWS_BICUBIC, nullptr, nullptr, nullptr);

    m_nBufferSize = av_image_get_buffer_size(AV_PIX_FMT_YUV420P, m_pVideoCodecCxt->width, m_pVideoCodecCxt->height, 1);

    m_pDstBuffer = (unsigned char*)av_malloc(m_nBufferSize);
    if (!m_pDstBuffer)
    {
        MY_DEBUG << "av_malloc error";
        return false;
    }

    m_pYuvFrame = av_frame_alloc();
    int ret = av_image_fill_arrays(m_pYuvFrame->data, m_pYuvFrame->linesize, m_pDstBuffer, AV_PIX_FMT_YUV420P, m_pVideoCodecCxt->width, m_pVideoCodecCxt->height, 1);
    if(ret <= 0)
    {
        return false;
    }

    //SDL
    if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER))
    {
        MY_DEBUG << "SDL_Init failed.";
        return false;
    }

    m_pWindow = SDL_CreateWindowFrom((void *)winId());
    if(!m_pWindow)
    {
        MY_DEBUG << "SDL_CreateWindowFrom failed.";
        return false;
    }

    SDL_ShowWindow(m_pWindow);

    m_pRenderer = SDL_CreateRenderer(m_pWindow, -1, 0);
    if(!m_pRenderer)
    {
        MY_DEBUG << "SDL_CreateRenderer failed.";
        return false;
    }

    m_pTexture = SDL_CreateTexture(m_pRenderer, SDL_PIXELFORMAT_IYUV, SDL_TEXTUREACCESS_STREAMING, m_pVideoCodecCxt->width, m_pVideoCodecCxt->height);
    if(!m_pTexture)
    {
        MY_DEBUG << "SDL_CreateTexture failed.";
        return false;
    }
    m_pSurface = SDL_CreateRGBSurface(0, m_nSDLWidth, m_nSDLHeight, 24, 0x000000FF, 0x0000FF00, 0x00FF0000, 0);
    
    m_bRun = true;
    m_nStartTime = av_gettime();

    return true;
}

void cVideoPlayer::playVideo()
{
    SDL_Event event;
    //启用音频子线程回调处理
    if(m_bSupportAudio)
        SDL_PauseAudio(0);

    while(m_bRun)
    {
        if(av_read_frame(m_pFormatCtx, &m_packet) >= 0)
        {
            if(m_bRecord)
            {
                //MY_DEBUG << "record...";
                AVPacket* pPkt = av_packet_clone(&m_packet);
                m_mp4Recorder.saveOneFrame(*pPkt, m_CodecId, m_AudioCodecId);
                av_packet_free(&pPkt);
            }

            if (m_packet.stream_index == m_nVideoIndex)
            {
                if(m_nPlayWay == MEDIA_PLAY_FILE)//本地文件播放延时处理
                {
                    AVRational time_base = m_pFormatCtx->streams[m_nVideoIndex]->time_base;
                    AVRational time_base_q = {1, AV_TIME_BASE}; // AV_TIME_BASE_Q;
                    int64_t pts_time = av_rescale_q(m_packet.dts, time_base, time_base_q);
                    //MY_DEBUG << "pts_time:" << pts_time;
                    int64_t now_time = av_gettime() - m_nStartTime;
                    if (pts_time > now_time)
                        av_usleep((pts_time - now_time));
                }

                avcodec_send_packet(m_pVideoCodecCxt, &m_packet);
                while (avcodec_receive_frame(m_pVideoCodecCxt, m_pFrame) == 0)
                {
                    sws_scale(m_pSwsCtx, m_pFrame->data, m_pFrame->linesize, 0, m_pVideoCodecCxt->height,
                              m_pYuvFrame->data, m_pYuvFrame->linesize);

                    SDL_UpdateTexture(m_pTexture, nullptr, m_pYuvFrame->data[0], m_pYuvFrame->linesize[0]);
                    SDL_RenderClear(m_pRenderer);
                    SDL_RenderCopy(m_pRenderer, m_pTexture, nullptr, nullptr);
                    SDL_RenderPresent(m_pRenderer);

                    if(m_bSnapshot)
                    {
                        SDL_RenderReadPixels(m_pRenderer, NULL, SDL_PIXELFORMAT_RGB24, m_pSurface->pixels, m_pSurface->pitch);

                        QString sImgePath = QString("%1screenshot.bmp").arg(SNAPSHOT_DEFAULT_PATH);

                        SDL_SaveBMP(m_pSurface, sImgePath.toUtf8().data());
                        m_bSnapshot = false;
                    }

                    SDL_PollEvent(&event);
                    if (event.type == SDL_QUIT)
                    {
                        MY_DEBUG << "event.type == SDL_QUIT";
                        m_bRun = false;
                        break;
                    }

                }
            }
            else if(m_packet.stream_index == m_nAudioIndex)
            {
                int nRet = avcodec_send_packet(m_pAudioCodecCxt, &m_packet);
                if(nRet != 0)
                {
                    av_packet_unref(&m_packet);
                    continue;
                }

                nRet = 0;
                while(!nRet)
                {
                    nRet = avcodec_receive_frame(m_pAudioCodecCxt, m_pPcmFrame);
                    if(nRet == 0)
                    {
                        audio_data_t* pAudioData = new audio_data_t;

                        uint8_t  *pData[1];
                        pData[0] = (uint8_t *)pAudioData->data;

                        //获取目标样本数
                        auto nDstNbSamples = av_rescale_rnd(m_pPcmFrame->nb_samples,
                                                                m_nAudioPlaySampleRate,
                                                                m_nAudioSampleRate,
                                                                AV_ROUND_ZERO);

                        //重采样
                        int nLen = swr_convert(m_pAudioSwrContext, pData, nDstNbSamples,
                                              (const uint8_t **)m_pPcmFrame->data,
                                              m_pPcmFrame->nb_samples);

                        if(nLen <= 0)
                        {
                            MY_DEBUG << "swr_convert error";
                            delete pAudioData;
                            continue;
                        }

                        //获取样本保存的缓存大小
                        int nOutsize = av_samples_get_buffer_size(nullptr, m_pAudioCodecCxt->channels,
                                                                 m_pPcmFrame->nb_samples,
                                                                 AV_SAMPLE_FMT_S16,
                                                                 0);
                        pAudioData->size = nOutsize;
                        QMutexLocker guard(&g_lock);
                        if(!m_bPauseAudio)
                            m_adq.enqueue(pAudioData);
                    }
                }
            }
            av_packet_unref(&m_packet);
        }
    }
}

void cVideoPlayer::OpenAudio(bool bOpen)
{
    if(bOpen)
    {
        m_bPauseAudio = false;
        SDL_PauseAudio(0);
    }
    else
    {
        m_bPauseAudio = true;
        SDL_PauseAudio(1);
    }
}

void cVideoPlayer::Snapshot()
{
    m_bSnapshot = true;
}

void cVideoPlayer::startRecord(bool bStart)
{
    if(bStart)
    {
        QString sPath = RECORD_DEFAULT_PATH;
        QDate date = QDate::currentDate();
        QTime time = QTime::currentTime();
        QString sRecordPath = QString("%1%2-%3-%4-%5%6%7.mp4").arg(sPath).arg(date.year()). \
                arg(date.month()).arg(date.day()).arg(time.hour()).arg(time.minute()). \
                arg(time.second());

        MY_DEBUG << "sRecordPath:" << sRecordPath;

        if(nullptr != m_pFormatCtx && m_bRun)
        {
            m_bRecord = m_mp4Recorder.Init(m_pFormatCtx, m_CodecId, m_AudioCodecId, sRecordPath);
        }

    }
    else
    {
        if(m_bRecord)
        {
            MY_DEBUG << "stopRecord...";
            m_mp4Recorder.DeInit();
            m_bRecord = false;
        }
    }
}

void cVideoPlayer::paintEvent(QPaintEvent *event)
{
    Q_UNUSED(event);
    QPainter painter(this);
    painter.fillRect(rect(), Qt::black);
}

3.4 开发过程问题处理

1)qtmain.lib 无法解析外部符号_main _winmain
这个错误通常是由于Qt和SDL使用了不同的入口函数引起的。Qt使用的是main函数作为入口,而SDL使用的是WinMain函数作为入口。当你在Qt项目中调用SDL函数时,链接器会找不到main或WinMain函数,从而导致链接错误。
解决方法:在main函数上增加#undef main,如下

#undef main
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    return a.exec();
}

2)视频没渲染问题
创建好窗口以后需要调用 SDL_ShowWindow(window);显示SDL窗口

3.5 播放器工程下载

https://download.csdn.net/download/linyibin_123/88262235

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/97474.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

ChatGPT⼊门到精通(5):ChatGPT 和Claude区别

⼀、Claude介绍 Claude是Anthropic开发的⼀款⼈⼯智能助⼿。 官⽅⽹站&#xff1a; ⼆、Claude能做什么 它可以通过⾃然语⾔与您进⾏交互,理解您的问题并作出回复。Claude的主要功能包括: 1、问答功能 Claude可以解答⼴泛的常识问题与知识问题。⽆论是历史上的某个事件,理科…

node.js 简单使用 开始

1.概要 问&#xff1a;体验一下node.js 看一下如何运行。 答&#xff1a;使用命令 node 文件名.js 2.举例 2.1 代码准备(main.js) console.log(第一行node.js代码); 2.2 运行效果

Spark项目Java和Scala混合打包编译

文章目录 项目结构Pom完整文件编译查看 实际开发用有时候引用自己写的一些java工具类&#xff0c;但是整个项目是scala开发的spark程序&#xff0c;在项目打包时需要考虑到java和scala混合在一起编译。 今天看到之前很久之前写的一些打包编译文章&#xff0c;发现很多地方不太对…

新方案unity配表工具

工具下载&#xff1a;网盘链接 工具结构&#xff1a;针对每张表格生成一个表格类&#xff0c;其中默认包含一个list和字典类型参数记录表格数据&#xff0c;初始化项目时将list中的数据转为按id索引的dictionary&#xff0c;用于访问数据。额外包含一个同名Temp后缀的类&#…

力扣:73. 矩阵置零(Python3)

题目&#xff1a; 给定一个 m x n 的矩阵&#xff0c;如果一个元素为 0 &#xff0c;则将其所在行和列的所有元素都设为 0 。请使用 原地 算法。 来源&#xff1a;力扣&#xff08;LeetCode&#xff09; 链接&#xff1a;力扣&#xff08;LeetCode&#xff09;官网 - 全球极客挚…

Llama模型结构解析(源码阅读)

目录 1. LlamaModel整体结构流程图2. LlamaRMSNorm3. LlamaMLP4. LlamaRotaryEmbedding 参考资料&#xff1a; https://zhuanlan.zhihu.com/p/636784644 https://spaces.ac.cn/archives/8265 ——《Transformer升级之路&#xff1a;2、博采众长的旋转式位置编码》 前言&#x…

无涯教程-分类算法 - 随机森林

随机森林是一种监督学习算法&#xff0c;可用于分类和回归&#xff0c;但是&#xff0c;它主要用于分类问题&#xff0c;众所周知&#xff0c;森林由树木组成&#xff0c;更多树木意味着更坚固的森林。同样&#xff0c;随机森林算法在数据样本上创建决策树&#xff0c;然后从每…

Linux文件管理知识:查找文件(第二篇)

上篇文章详细介绍了linux系统中查找文件的工具或者命令程序locate和find命令的基本操作。那么&#xff0c;今天这篇文章紧接着查找文件相关操作内容介绍。 Find命令所属操作列表中的条目&#xff0c;有助于我们想要的结果输出。上篇文章已讲到find 命令是基于搜索结果来执行操作…

LAMP介绍与配置

一.LAMP 1.1.LAMP架构的组成 CGI&#xff08;通用网关接口&#xff09;和FastCGI&#xff08;快速公共网关接口&#xff09;都是用于将Web服务器与后端应用程序&#xff08;如PHP、Python等&#xff09;进行交互的协议/接口。 特点 CGI FastCGI 运行方式 每个请求启动…

Seaborn数据可视化(四)

目录 1.绘制箱线图 2.绘制小提琴图 3.绘制多面板图 4.绘制等高线图 5.绘制热力图 1.绘制箱线图 import seaborn as sns import matplotlib.pyplot as plt # 加载示例数据&#xff08;例如&#xff0c;使用seaborn自带的数据集&#xff09; tips sns.load_dataset("t…

中国智慧燃气行业市场需求

文章来源&#xff1a;中研普华产业研究院 关键词&#xff1a;智慧燃气、智慧燃气场站、智慧燃气平台、设备设施数字化、数字孪生、工业互联网 智慧燃气&#xff0c;是以城市输气管网为基础&#xff0c;各终端用户协调发展&#xff0c;以信息通信平台为支撑&#xff0c;具有信…

C++信息学奥赛1177:奇数单增序列

#include<bits/stdc.h> using namespace std; int main(){int n;cin>>n; // 输入整数 n&#xff0c;表示数组的大小int arr[n]; // 创建大小为 n 的整型数组for(int i0;i<n;i) cin>>arr[i]; // 输入数组元素for(int i0;i<n;i){ // 对数组进行冒泡排序f…

在腾讯云服务器OpenCLoudOS系统中安装svn(有图详解)

1. 安装svn yum -y install subversion 安装成功&#xff1a; 2. 创建数据根目录及仓库 mkdir -p /usr/local/svn/svnrepository 创建test仓库&#xff1a; svnadmin create /usr/local/svn/test test仓库创建成功&#xff1a; 3. 修改配置test仓库 cd /usr/local/svn/te…

39.RESTful案例

RESTful案例 准备环境 Employee.java public class Employee {private Integer id;private String lastName;private String email;//1 male, 0 femaleprivate Integer gender; } //省略get、set和构造方法EmployeeDao.java package com.atguigu.SpringMVC.dao;import com.…

C++信息学奥赛1178:成绩排序

#include<bits/stdc.h> using namespace std; int main(){int n;cin>>n; // 输入整数 n&#xff0c;表示数组的大小int arr[n]; // 创建大小为 n 的整型数组 arrstring brr[n]; // 创建大小为 n 的字符串数组 brrfor(int i0;i<n;i) cin>>brr[i]>>ar…

有线耳机插入电脑没声音

有线耳机插入电脑没声音 首先确保耳机和电脑都没问题&#xff0c;那就有可能是声音输出设备设置错误 右击任务栏的声音图标-打开声音设置-选择输出设备。

2 hadoop的目录

1. 目录结构&#xff1a; 其中比较的重要的路径有&#xff1a; hdfs,mapred,yarn &#xff08;1&#xff09;bin目录&#xff1a;存放对Hadoop相关服务&#xff08;hdfs&#xff0c;yarn&#xff0c;mapred&#xff09;进行操作的脚本 &#xff08;2&#xff09;etc目录&#x…

线上问诊:业务数据采集

系列文章目录 线上问诊&#xff1a;业务数据采集 线上问诊&#xff1a;数仓数据同步 文章目录 系列文章目录前言一、环境安装1.DataX 二、全量同步1.DataX配置文件生成2.启动hadoop测试一下。3.全量同步 三、增量同步1.配置Flume2.编写Flume拦截器3.通道测试4.修改Maxwell参数…

Pytorch学习:神经网络模块torch.nn.Module和torch.nn.Sequential

文章目录 1. torch.nn.Module1.1 add_module&#xff08;name&#xff0c;module&#xff09;1.2 apply(fn)1.3 cpu()1.4 cuda(deviceNone)1.5 train()1.6 eval()1.7 state_dict() 2. torch.nn.Sequential2.1 append 3. torch.nn.functional.conv2d 1. torch.nn.Module 官方文档…

环保数字化,让污染无处遁形

环保一直以来都是我国大力推崇的举措&#xff0c;“保护环境、人人有责”的标语深入人心&#xff0c;但是环保绝不是某一天某一年就能做好的事情&#xff0c;而在于一朝一夕坚持不懈&#xff0c;下文将针对环保的场景介绍一下数字孪生技术在环保领域的应用。 一、环保背景 新中…
最新文章