当前位置: 首页 > news >正文

网站开发数据库连接失败株洲seo快速排名

网站开发数据库连接失败,株洲seo快速排名,kuler 网站,adobe 网站制作软件有哪些介绍 工作开发中需要处理的文件很多并无音频,针对这一场景,这里分享工作中自己封装使用的类库。精简的代码实现了播放、暂停、停止、快进、快退、进度跳转、倍速播放功能。直接放代码,方便后期复制使用。 代码 头文件 /*** file videopla…

介绍

工作开发中需要处理的文件很多并无音频,针对这一场景,这里分享工作中自己封装使用的类库。精简的代码实现了播放、暂停、停止、快进、快退、进度跳转、倍速播放功能。直接放代码,方便后期复制使用。

代码

头文件

/*** @file videoplayer.h* @brief ffmpeg实现视频解码* @author ZXT* @date 2023.12.23*/#ifndef VIDEOPLAYER_H
#define VIDEOPLAYER_H#include <QThread>
#include <QDebug>
#include <QImage>extern "C"
{
#include "libavformat/avformat.h"
#include "libavcodec/avcodec.h"
#include "libswscale/swscale.h"
#include "libavutil/imgutils.h"
#include "libavutil/time.h"
}class VideoDecoder : public QThread
{Q_OBJECT
public:explicit VideoDecoder(QObject *parent = nullptr);~VideoDecoder();/*** @brief 开始播放* @param path入参 路径*/void startPlay(const QString &path);/*** @brief 停止播放*/void stopPlay();/*** @brief 暂停或继续播放* @param pause入参 ture暂停 false继续*/void pausePlay(bool pause);/*** @brief 进度跳转播放* @param sec入参 跳转的秒数*/void seekPlay(int sec);/*** @brief 倍速播放* @param speed入参 播放速度*/void speedPlay(float speed = 1.0);signals:/*** @brief 播放时长* @param sec入参 时长秒数*/void sigDuration(int sec);/*** @brief 播放位置* @param sec入参 当前秒数*/void sigPlayPosition(int sec);/*** @brief 播放结束* @param ret出参 状态码*/void sigPlayFinished(int ret);/*** @brief 发送解码后的显示图像* @param image出参 视频图像*/void sigSendImage(const QImage &image);protected:void run();private://运行标志volatile bool m_isRun = false;//暂停状态volatile bool m_pause = false;//进度跳转状态volatile bool m_seek = false;//优化跳转速度volatile bool m_seekFilter = false;//文件路径QString m_filePath;//开始时间 ms单位int64_t m_startTime = 0;//暂停时间 ms单位int64_t m_pauseTime = 0;//跳转时间 ms单位int64_t m_seekTime = 0;//时长信息 秒int m_videoDuration = 0;//播放速率float m_speedValue = 1.0;//上一次的播放速率float m_lastSpeedValue = 1.0;
};#endif // VIDEOPLAYER_H

实现文件

#include "videoplayer.h"VideoDecoder::VideoDecoder(QObject *parent) : QThread(parent)
{}VideoDecoder::~VideoDecoder()
{quit();wait();
}//开始播放
void VideoDecoder::startPlay(const QString &path)
{m_filePath = path;m_isRun = true;m_pause = false;m_seek = false;m_speedValue = 1.0;m_lastSpeedValue = 1.0;this->start();
}//停止播放
void VideoDecoder::stopPlay()
{m_pause = false;m_seek = false;m_isRun = false;
}//暂停或继续播放
void VideoDecoder::pausePlay(bool pause)
{m_pause = pause;if(pause){m_pauseTime = av_gettime_relative() / 1000;}else{int offset = av_gettime_relative() / 1000 - m_pauseTime;m_startTime += offset;}
}//进度跳转播放
void VideoDecoder::seekPlay(int sec)
{if(!m_isRun)return;if(m_videoDuration == sec)sec -= 2;m_seekTime = sec * 1000;m_seekFilter = true;m_seek = true;
}//倍速播放
void VideoDecoder::speedPlay(float speed)
{int64_t elapsed = av_gettime_relative() / 1000 - m_startTime;int offset = elapsed - (elapsed * this->m_lastSpeedValue / speed);m_startTime += offset;m_speedValue = speed;m_lastSpeedValue = speed;
}void VideoDecoder::run()
{qDebug() << "VideoDecoder start" << m_filePath;std::string temp = m_filePath.toStdString();AVFormatContext *inFmtCtx = avformat_alloc_context();int ret = avformat_open_input(&inFmtCtx, temp.c_str(), NULL, NULL);if (ret < 0){qDebug() << "open input error";emit sigPlayFinished(-1);return;}//获取流信息ret = avformat_find_stream_info(inFmtCtx, NULL);if (ret < 0){qDebug() << "find stream info error";emit sigPlayFinished(-1);return;}//获取视频流信息 目前只有视频流bool getVideo = false;int videoIndex = av_find_best_stream(inFmtCtx, AVMEDIA_TYPE_VIDEO, -1, -1, NULL, 0);AVStream *videoStream = NULL;AVCodec *videoDecoder = NULL;AVCodecContext *videoDeCodecCtx = NULL;if (videoIndex >= 0){videoStream = inFmtCtx->streams[videoIndex];//初始化解码器videoDecoder = avcodec_find_decoder(videoStream->codecpar->codec_id);videoDeCodecCtx = avcodec_alloc_context3(videoDecoder);if(videoDeCodecCtx != NULL){avcodec_parameters_to_context(videoDeCodecCtx, videoStream->codecpar);ret = avcodec_open2(videoDeCodecCtx, videoDecoder, NULL);if(ret < 0)avcodec_free_context(&videoDeCodecCtx);elsegetVideo = true;}}if(!getVideo){avformat_close_input(&inFmtCtx);emit sigPlayFinished(-1);return;}AVFrame *swsFrame = av_frame_alloc();SwsContext *swsCtx = nullptr;uint8_t *videoData = nullptr;//输出视频参数信息if(getVideo){int srcW = videoStream->codecpar->width;int srcH = videoStream->codecpar->height;AVPixelFormat format = videoDeCodecCtx->pix_fmt;m_videoDuration = inFmtCtx->duration / AV_TIME_BASE;emit sigDuration(m_videoDuration);int byte = av_image_get_buffer_size(AV_PIX_FMT_RGB32, srcW, srcH, 1);videoData = (uint8_t *)av_malloc(byte * sizeof(uint8_t));av_image_fill_arrays(swsFrame->data, swsFrame->linesize, videoData, (AVPixelFormat)AV_PIX_FMT_RGB32, srcW, srcH, 1);swsCtx = sws_getContext(srcW, srcH, (AVPixelFormat)format, srcW, srcH, (AVPixelFormat)AV_PIX_FMT_RGB32, SWS_FAST_BILINEAR, NULL, NULL, NULL);}//开始时刻m_startTime = av_gettime_relative() / 1000;int64_t ptsTime = 0;int64_t ptsBackup = 0;int curPlayPos = 0;AVPacket *packet = av_packet_alloc();AVFrame *videoFrame = av_frame_alloc();while(m_isRun){//暂停if(m_pause){QThread::msleep(200);continue;}//进度切换if(m_seek){//跳转的播放时刻 单位微秒int64_t timeStamp = m_seekTime * 1000;if (inFmtCtx->start_time != AV_NOPTS_VALUE){timeStamp += inFmtCtx->start_time;}//注:seek若关键帧间隔大需避免延时timeStamp = av_rescale_q(timeStamp, AVRational{1, AV_TIME_BASE}, videoStream->time_base);ret = av_seek_frame(inFmtCtx, videoIndex, timeStamp, AVSEEK_FLAG_BACKWARD);if(ret < 0){qDebug() << "av_seek_frame fail" << m_seekTime;}else{//清空内部帧队列if(videoDeCodecCtx)avcodec_flush_buffers(videoDeCodecCtx);//调整时钟int64_t offset = m_seekTime - ptsTime;m_startTime -= offset;}m_seek = false;}//不断读取packetret = av_read_frame(inFmtCtx, packet);if (ret == AVERROR_EOF){m_isRun = false;break;}if(packet->stream_index == videoIndex){//编码数据进行解码ret = avcodec_send_packet(videoDeCodecCtx, packet);if (ret < 0){av_packet_unref(packet);continue;}ret = avcodec_receive_frame(videoDeCodecCtx, videoFrame);if (ret < 0){av_packet_unref(packet);continue;}//计算当前帧实际时间 msptsTime = videoFrame->pts * av_q2d(videoStream->time_base) * 1000;if(m_seekFilter){//跳转播放时间不符合的帧直接丢弃 默认阈值200msint offset = m_seekTime - ptsTime;if(0 > offset || offset < 200){m_seekFilter = false;}else{av_frame_unref(videoFrame);av_packet_unref(packet);continue;}}//倍速将改变原pts值 太高倍速会导致解码消耗过高、渲染过频繁可考虑抽帧ptsBackup = ptsTime;ptsTime *= (1 / m_speedValue);//控制速度 ms单位qint64 elapsed = av_gettime_relative() / 1000 - m_startTime;int64_t sleepMs = ptsTime - elapsed;if(sleepMs > 3){QThread::msleep(sleepMs);}//发送播放位置信息int sec = ptsBackup / 1000;if(sec != curPlayPos){curPlayPos = sec;emit sigPlayPosition(curPlayPos);}//将解码后的frame数据转换为Imagesws_scale(swsCtx, (const uint8_t *const *)videoFrame->data, videoFrame->linesize, 0, videoFrame->height, swsFrame->data, swsFrame->linesize);QImage image((uchar *)videoData, videoFrame->width, videoFrame->height, QImage::Format_RGB32);QImage copy = image.copy();emit sigSendImage(copy);av_frame_unref(videoFrame);}av_packet_unref(packet);}//释放资源sws_freeContext(swsCtx);av_frame_free(&swsFrame);av_free(videoData);av_packet_free(&packet);av_frame_free(&videoFrame);avcodec_free_context(&videoDeCodecCtx);avformat_close_input(&inFmtCtx);emit sigPlayFinished(0);qDebug() << "VideoDecoder end" << m_filePath;return;
}

文章转载自:
http://phytogenesis.rbzd.cn
http://megrim.rbzd.cn
http://exceptive.rbzd.cn
http://belat.rbzd.cn
http://osteosarcoma.rbzd.cn
http://syncerebrum.rbzd.cn
http://adsuki.rbzd.cn
http://ferret.rbzd.cn
http://allodiality.rbzd.cn
http://prole.rbzd.cn
http://gaikwar.rbzd.cn
http://dulcimer.rbzd.cn
http://grant.rbzd.cn
http://geophilous.rbzd.cn
http://charles.rbzd.cn
http://faciobrachial.rbzd.cn
http://transshape.rbzd.cn
http://mayhap.rbzd.cn
http://haemophilia.rbzd.cn
http://intrench.rbzd.cn
http://dyak.rbzd.cn
http://trickiness.rbzd.cn
http://gozitan.rbzd.cn
http://plasmasphere.rbzd.cn
http://romaika.rbzd.cn
http://veridically.rbzd.cn
http://socket.rbzd.cn
http://siddhi.rbzd.cn
http://subimago.rbzd.cn
http://slick.rbzd.cn
http://ureterolithotomy.rbzd.cn
http://ageratum.rbzd.cn
http://puffin.rbzd.cn
http://braky.rbzd.cn
http://rillet.rbzd.cn
http://crankle.rbzd.cn
http://leander.rbzd.cn
http://lovestruck.rbzd.cn
http://trifolium.rbzd.cn
http://gravicembalo.rbzd.cn
http://pratas.rbzd.cn
http://similarity.rbzd.cn
http://monacan.rbzd.cn
http://leakiness.rbzd.cn
http://incandesce.rbzd.cn
http://fatherlike.rbzd.cn
http://undutiful.rbzd.cn
http://gravelly.rbzd.cn
http://baffling.rbzd.cn
http://serpiginous.rbzd.cn
http://demothball.rbzd.cn
http://minnesotan.rbzd.cn
http://concoct.rbzd.cn
http://prattler.rbzd.cn
http://gradually.rbzd.cn
http://understock.rbzd.cn
http://hordein.rbzd.cn
http://dismount.rbzd.cn
http://puerilism.rbzd.cn
http://mahabharata.rbzd.cn
http://anhydride.rbzd.cn
http://fieldstone.rbzd.cn
http://spiniferous.rbzd.cn
http://fortis.rbzd.cn
http://yuletide.rbzd.cn
http://consecutively.rbzd.cn
http://vitellogenic.rbzd.cn
http://sialolithiasis.rbzd.cn
http://kilogramme.rbzd.cn
http://nacho.rbzd.cn
http://iconograph.rbzd.cn
http://oxim.rbzd.cn
http://runover.rbzd.cn
http://competitory.rbzd.cn
http://duckling.rbzd.cn
http://antidiabetic.rbzd.cn
http://embarkation.rbzd.cn
http://septuagenary.rbzd.cn
http://mutably.rbzd.cn
http://sanidine.rbzd.cn
http://fooper.rbzd.cn
http://insulin.rbzd.cn
http://gemsbok.rbzd.cn
http://calais.rbzd.cn
http://watchfully.rbzd.cn
http://houselights.rbzd.cn
http://ping.rbzd.cn
http://chronoscope.rbzd.cn
http://isthmectomy.rbzd.cn
http://entoptoscope.rbzd.cn
http://icecap.rbzd.cn
http://quietive.rbzd.cn
http://realisable.rbzd.cn
http://smarmy.rbzd.cn
http://revamp.rbzd.cn
http://craniognomy.rbzd.cn
http://hypotactic.rbzd.cn
http://melbourne.rbzd.cn
http://nomenclature.rbzd.cn
http://malarious.rbzd.cn
http://www.15wanjia.com/news/90643.html

相关文章:

  • 怎么用qq相册做网站重庆网站制作系统
  • 专做sm的网站销售找客户的方法
  • 哪个网站做民宿更好呢推广任务接单平台
  • 甘肃建设项目审批权限网站广东疫情最新情况
  • 旅游网站平台建设的方案招工 最新招聘信息
  • 装饰网站建设多少钱58网络推广
  • 网站建设策划方案模板网站关键词优化外包
  • 网站建设 空间5188关键词挖掘
  • 建站wordpress 基础seo优化排名易下拉效率
  • 国外设计参考网站宁德市人民医院
  • wordpress博客优点成都网站排名优化公司
  • 石家庄网站开发价格互联网网络推广公司
  • 网站开发怎么做单页网站怎么优化
  • 下城区做网站seo顾问收费
  • 房产网站怎么做seo监控
  • 网站建设有什么工作如何seo搜索引擎优化
  • wordpress淘宝客模板下载seo数据
  • java视频网站开发技术网站建设策划书案例
  • 学平面设计怎么样啊百度seo排名点击
  • 购买网站宁波seo服务推广
  • 建立个人网站主题为什么seo工资不高
  • 前程无忧怎么做网站针对本地的免费推广平台
  • 做网站开发的商标注册多少类seo搜索引擎优化介绍
  • 做贸易的网站有哪些长沙网站制作推广
  • 网站上的动图axure怎么做武汉刚刚发生的新闻
  • 男生和男生做污的视频网站福州百度分公司
  • 白银市建设管理处网站辽阳网站seo
  • 怎么和网站建设公司签合同新产品宣传推广策划方案
  • 南京网站设计培训百度推广竞价排名
  • 微信公众平台和微网站的区别在线seo推广软件