更新代码
This commit is contained in:
@@ -231,6 +231,7 @@ bool FFmpegThread::init()
|
|||||||
|
|
||||||
void FFmpegThread::run()
|
void FFmpegThread::run()
|
||||||
{
|
{
|
||||||
|
qint64 startTime = av_gettime();
|
||||||
while (!stopped) {
|
while (!stopped) {
|
||||||
//根据标志位执行初始化操作
|
//根据标志位执行初始化操作
|
||||||
if (isPlay) {
|
if (isPlay) {
|
||||||
@@ -270,16 +271,25 @@ void FFmpegThread::run()
|
|||||||
emit receiveImage(image);
|
emit receiveImage(image);
|
||||||
}
|
}
|
||||||
|
|
||||||
msleep(1);
|
usleep(1);
|
||||||
}
|
}
|
||||||
|
#if 1
|
||||||
|
//延时(不然文件会立即全部播放完)
|
||||||
|
AVRational timeBase = {1, AV_TIME_BASE};
|
||||||
|
int64_t ptsTime = av_rescale_q(avPacket->dts, avFormatContext->streams[videoStreamIndex]->time_base, timeBase);
|
||||||
|
int64_t nowTime = av_gettime() - startTime;
|
||||||
|
if (ptsTime > nowTime) {
|
||||||
|
av_usleep(ptsTime - nowTime);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
} else if (index == audioStreamIndex) {
|
} else if (index == audioStreamIndex) {
|
||||||
//解码音频流,这里暂不处理,以后交给sdl播放
|
//解码音频流,自行处理
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
av_packet_unref(avPacket);
|
av_packet_unref(avPacket);
|
||||||
av_freep(avPacket);
|
av_freep(avPacket);
|
||||||
msleep(1);
|
usleep(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
//线程结束后释放资源
|
//线程结束后释放资源
|
||||||
|
|||||||
@@ -6,10 +6,10 @@ Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget)
|
|||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
//本示例支持的是rtsp视频流(其他的一概不支持/没有做音视频同步)
|
||||||
QStringList urls;
|
QStringList urls;
|
||||||
urls << "f:/1.mp4";
|
urls << "http://vfx.mtime.cn/Video/2021/11/16/mp4/211116131456748178.mp4";
|
||||||
urls << "rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov";
|
urls << "http://vd3.bdstatic.com/mda-jennyc5ci1ugrxzi/mda-jennyc5ci1ugrxzi.mp4";
|
||||||
urls << "http://vfx.mtime.cn/Video/2019/02/04/mp4/190204084208765161.mp4";
|
|
||||||
urls << "rtsp://admin:Admin123456@192.168.0.15:554/media/video1";
|
urls << "rtsp://admin:Admin123456@192.168.0.15:554/media/video1";
|
||||||
ui->cboxUrl->addItems(urls);
|
ui->cboxUrl->addItems(urls);
|
||||||
ui->cboxUrl->setCurrentIndex(0);
|
ui->cboxUrl->setCurrentIndex(0);
|
||||||
|
|||||||
Reference in New Issue
Block a user