Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize Video streaming and playing ffmpeg Kernel by Qt

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly shows you "Qt how to achieve video streaming ffmpeg kernel", the content is easy to understand, clear, hope to help you solve doubts, the following let the editor lead you to study and learn "how to achieve video streaming ffmpeg kernel Qt" this article.

I. Preface

I wrote this tool a long time ago. Later, due to the continuous upgrading of the Qt version and many iterations of ffmpeg, the ffmpeg downloaded from the official website with the original code may not compile correctly, because many api have changed, so this time I took the time to clean up and rewrite them all, only for the most concise and best use, compatible with both ffmpeg3 and ffmpeg4, and supported both 32-bit libraries and 64-bit libraries. In this way, any rookie can take it and compile it directly.

Second, code ideas

Step 1: introduce the header file of ffmpeg

/ / the following must be added, otherwise the compilation will not pass To be compatible with C and C99 standards # ifndef INT64_C#define INT64_C#define UINT64_C#endif// introduced the ffmpeg header file extern "C" {# include "libavutil/opt.h" # include "libavutil/time.h" # include "libavutil/frame.h" # include "libavutil/pixdesc.h" # include "libavutil/avassert.h" # include "libavutil/imgutils.h" # include "libavutil/ffversion.h" # include "libavcodec/avcodec.h" # include "libswscale/swscale.h "# include" libavformat/avformat.h "# include" libavfilter/avfilter.h "# ifdef ffmpegdevice#include" libavdevice/avdevice.h "# endif#ifndef gcc45#include" libavutil/hwcontext.h "# include" libavutil/hwcontext_qsv.h "# endif}

Step 2: register ffmpeg library here found that many people register for each class, so that each time the memory increases a lot, not impossible, but unnecessary, in fact, ffmpeg libraries and decoders, etc., only need to register once in a program, there is no need to register every video class once.

/ / only need to initialize once in a software void FFmpegThread::initlib () {static QMutex mutex; QMutexLocker locker (& mutex); static bool isInit = false; if (! isInit) {/ / register all available file formats and decoders av_register_all () in the library; / / register all devices, mainly for local camera playback support # ifdef ffmpegdevice avdevice_register_all () # endif / / initialize the network flow format. When using network flow, you must execute avformat_network_init (); isInit = true; qDebug () data, avFrame2- > linesize, 0, videoHeight, avFrame3- > data, avFrame3- > linesize); / / both of the following methods can / / QImage image (avFrame3- > data [0], videoWidth, videoHeight, QImage::Format_RGB32) QImage image ((uchar *) buffer, videoWidth, videoHeight, QImage::Format_RGB32); if (! image.isNull ()) {emit receiveImage (image);} msleep (1) }} else if (index = = audioStreamIndex) {/ / decode the audio stream, which will not be processed here and will be handed over to sdl to play}} av_packet_unref (avPacket); av_freep (avPacket); msleep (1);} / / release the resource free () after the thread ends; stopped = false IsPlay = false; qDebug ()

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report